Skip to content

Commit

Permalink
call TestApp.ResetBootstrap as finalizer of the test OnTerminate hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Mar 20, 2024
1 parent 03cec9a commit 309c4fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion core/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ func (app *BaseApp) initLogger() error {
for {
select {
case <-done:
handler.WriteAll(ctx)
return
case <-ticker.C:
handler.WriteAll(ctx)
}
Expand All @@ -1289,8 +1289,13 @@ func (app *BaseApp) initLogger() error {
app.logger = slog.New(handler)

app.OnTerminate().PreAdd(func(e *TerminateEvent) error {
// write all remaining logs before ticker.Stop to avoid races with ResetBootstrap user calls
handler.WriteAll(context.Background())

ticker.Stop()

done <- true

return nil
})

Expand Down
11 changes: 7 additions & 4 deletions tests/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ type TestApp struct {
//
// After this call, the app instance shouldn't be used anymore.
func (t *TestApp) Cleanup() {
t.ResetEventCalls()
t.ResetBootstrapState()
t.TestMailer.Reset()
t.OnTerminate().Trigger(&core.TerminateEvent{App: t})
t.OnTerminate().Trigger(&core.TerminateEvent{App: t}, func(e *core.TerminateEvent) error {
t.TestMailer.Reset()
t.ResetEventCalls()
t.ResetBootstrapState()

return nil
})

if t.DataDir() != "" {
os.RemoveAll(t.DataDir())
Expand Down

0 comments on commit 309c4fe

Please sign in to comment.