From 78f7cd0d6ce353b97e85d129ff2d83be5658efdf Mon Sep 17 00:00:00 2001 From: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Date: Tue, 15 Mar 2022 09:52:41 -0300 Subject: [PATCH] fix(adminmonitor): fix a data race in a unit test EE-2714 (#6627) --- api/adminmonitor/admin_monitor_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/adminmonitor/admin_monitor_test.go b/api/adminmonitor/admin_monitor_test.go index 1df983276..2b32eb921 100644 --- a/api/adminmonitor/admin_monitor_test.go +++ b/api/adminmonitor/admin_monitor_test.go @@ -35,9 +35,15 @@ func Test_start_shouldFatalAfterTimeout_ifNotInitialized(t *testing.T) { datastore := i.NewDatastore(i.WithUsers([]portainer.User{})) + ch := make(chan struct{}) var fataled bool origLogFatalf := logFatalf - logFatalf = func(s string, v ...interface{}) { fataled = true } + + logFatalf = func(s string, v ...interface{}) { + fataled = true + close(ch) + } + defer func() { logFatalf = origLogFatalf }() @@ -45,6 +51,7 @@ func Test_start_shouldFatalAfterTimeout_ifNotInitialized(t *testing.T) { monitor := New(timeout, datastore, context.Background()) monitor.Start() <-time.After(2 * timeout) + <-ch assert.True(t, fataled, "monitor should been timeout and fatal") }