Skip to content
Draft
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
5 changes: 5 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,11 @@ func withTimeout(ctx context.Context, param *withTimeoutParams) error {
caller,
err,
r)
} else if caller == "" {
return fmt.Errorf("%v hook failed: %w",
param.hook,
err)

}
return fmt.Errorf("%v hook added by %v failed: %w",
param.hook,
Expand Down
22 changes: 22 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,28 @@ func TestAppRunTimeout(t *testing.T) {
}
}

func TestVeryShortTimeout(t *testing.T) {
type A struct{}
spy := new(fxlog.Spy)
app := New(
WithLogger(func() fxevent.Logger { return spy }),
Provide(func() *A {
// this will timeout
time.Sleep(time.Millisecond)
return &A{}
}),
Invoke(func(*A) {}),
)

ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
err := app.Start(ctx)
require.Error(t, err)
// The error message should never be in the format "added by" followed by an empty string.
assert.NotContains(t, err.Error(), "OnStart hook added by failed")
assert.Contains(t, err.Error(), "context deadline exceeded")
cancel()
}

func TestAppStart(t *testing.T) {
t.Parallel()

Expand Down