From 59ec2de8bd99763b515b1df25678dfac37185820 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Wed, 30 Mar 2022 14:37:42 -0400 Subject: [PATCH] Fix race in test --- server/server_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/server_test.go b/server/server_test.go index 062821d8..67aff540 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -714,6 +714,12 @@ func (t *testMailer) Send(from, to string, m *message) error { return nil } +func (t *testMailer) Count() int { + t.mu.Lock() + defer t.mu.Unlock() + return t.count +} + func TestServer_PublishTooRequests_Defaults(t *testing.T) { s := newTestServer(t, newTestConfig(t)) for i := 0; i < 60; i++ { @@ -902,7 +908,7 @@ func TestServer_PublishAsJSON_WithEmail(t *testing.T) { m := toMessage(t, response.Body.String()) require.Equal(t, "mytopic", m.Topic) require.Equal(t, "A message", m.Message) - require.Equal(t, 1, mailer.count) + require.Equal(t, 1, mailer.Count()) } func TestServer_PublishAsJSON_Invalid(t *testing.T) {