From 309c4fe6fe6857538462e12111f11804c3406003 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Wed, 20 Mar 2024 23:47:19 +0200 Subject: [PATCH] call TestApp.ResetBootstrap as finalizer of the test OnTerminate hook --- core/base.go | 7 ++++++- tests/app.go | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/core/base.go b/core/base.go index d7dc9fb35..b911e87fb 100644 --- a/core/base.go +++ b/core/base.go @@ -1279,7 +1279,7 @@ func (app *BaseApp) initLogger() error { for { select { case <-done: - handler.WriteAll(ctx) + return case <-ticker.C: handler.WriteAll(ctx) } @@ -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 }) diff --git a/tests/app.go b/tests/app.go index 9dbb2b9fc..e638f2521 100644 --- a/tests/app.go +++ b/tests/app.go @@ -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())