Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeout report generation race #816

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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