Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ func (a *App) Failed() <-chan error {
return a.failed
}

// Ready is Readiness().Ready. Together with Live it lets an App be passed as a
// single health source, for example to dioad/net's Server.AddHealthSource,
// which then serves /health/live from Live and /health/ready from Ready.
func (a *App) Ready(ctx context.Context) (any, error) {
return a.readiness.Ready(ctx)
}

// Live returns nil while every started service that implements Liveness
// reports live, and otherwise the errors of those that do not, each naming its
// service.
Expand Down
20 changes: 20 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,26 @@ func TestApp_Live_NamesTheServicesThatAreNotLive(t *testing.T) {
assert.NotContains(t, err.Error(), "good")
}

func TestApp_IsAHealthSourceOnItsOwn(t *testing.T) {
t.Parallel()
var _ interface {
Live(context.Context) error
Ready(context.Context) (any, error)
} = (*App)(nil)

app := New()
svc := newFailingService("store", &eventLog{})
svc.ready = errors.New("replica behind")
require.NoError(t, app.Add("store", svc))
require.NoError(t, app.Start(t.Context()))
t.Cleanup(func() { _ = app.Stop(context.Background()) })

_, err := app.Ready(t.Context())

require.ErrorContains(t, err, "replica behind")
require.NoError(t, app.Live(t.Context()))
}

func TestApp_ServiceReadinessIsACheckOfThatName(t *testing.T) {
t.Parallel()
app := New()
Expand Down
Loading