This commit is contained in:
@@ -15,6 +15,10 @@ type SettlementMonitor interface {
|
||||
Stats(context.Context) (ledger.SettlementStats, error)
|
||||
}
|
||||
|
||||
type SettlementAuthority interface {
|
||||
SettlementAllowed(context.Context) (bool, error)
|
||||
}
|
||||
|
||||
type Status struct {
|
||||
Serving bool
|
||||
DatabaseReady bool
|
||||
@@ -50,6 +54,10 @@ func (s *Service) Check(ctx context.Context) Status {
|
||||
if err == nil {
|
||||
status.SettlementStats = stats
|
||||
status.SettlementReady = true
|
||||
if authority, ok := s.settlement.(SettlementAuthority); ok {
|
||||
allowed, authorityErr := authority.SettlementAllowed(ctx)
|
||||
status.SettlementReady = authorityErr == nil && allowed
|
||||
}
|
||||
}
|
||||
}
|
||||
return status
|
||||
|
||||
@@ -61,3 +61,15 @@ func TestCheckReportsSettlementQueryFailure(t *testing.T) {
|
||||
t.Fatalf("unexpected status: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
type pausedSettlementStub struct{ settlementStub }
|
||||
|
||||
func (pausedSettlementStub) SettlementAllowed(context.Context) (bool, error) { return false, nil }
|
||||
|
||||
func TestGLOnlyKeepsLedgerServingWhileNormalSettlementClientsFailClosed(t *testing.T) {
|
||||
monitor := pausedSettlementStub{settlementStub{stats: ledger.SettlementStats{Pending: 3}}}
|
||||
got := NewService(databaseStub{}, monitor).Check(context.Background())
|
||||
if !got.Serving || !got.DatabaseReady || !got.SettlementEnabled || got.SettlementReady || got.SettlementStats.Pending != 3 {
|
||||
t.Fatalf("unexpected GL-only readiness: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user