From a59c9525c1e667e6b95cb2727255527c2f7fc979 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Tue, 23 Jul 2024 08:22:00 -0400 Subject: [PATCH] notifications: Fix flaky SMTP tests (#90801) Signed-off-by: Dave Henderson --- pkg/services/notifications/smtp_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/services/notifications/smtp_test.go b/pkg/services/notifications/smtp_test.go index bf1c5def758..7b7fb04165d 100644 --- a/pkg/services/notifications/smtp_test.go +++ b/pkg/services/notifications/smtp_test.go @@ -10,6 +10,7 @@ import ( "net/textproto" "strings" "testing" + "time" smtpmock "github.com/mocktools/go-smtp-mock/v2" "github.com/stretchr/testify/assert" @@ -150,10 +151,9 @@ func TestSmtpDialer(t *testing.T) { } func TestSmtpSend(t *testing.T) { - // Test is currently very flaky. Skipping it for now. - t.Skip() srv := smtpmock.New(smtpmock.ConfigurationAttr{ MultipleRcptto: true, + HostAddress: "127.0.0.1", }) require.NoError(t, srv.Start()) defer func() { _ = srv.Stop() }() @@ -183,6 +183,8 @@ func TestSmtpSend(t *testing.T) { require.NoError(t, err) require.Equal(t, 1, count) + // workaround for https://github.com/mocktools/go-smtp-mock/issues/181 + time.Sleep(1 * time.Millisecond) messages := srv.MessagesAndPurge() require.Len(t, messages, 1) sentMsg := messages[0] @@ -233,6 +235,8 @@ func TestSmtpSend(t *testing.T) { require.NoError(t, err) require.Equal(t, 1, count) + // workaround for https://github.com/mocktools/go-smtp-mock/issues/181 + time.Sleep(1 * time.Millisecond) messages := srv.MessagesAndPurge() require.Len(t, messages, 1) sentMsg := messages[0] @@ -292,6 +296,8 @@ func TestSmtpSend(t *testing.T) { require.NoError(t, err) require.Equal(t, 3, count) + // workaround for https://github.com/mocktools/go-smtp-mock/issues/181 + time.Sleep(1 * time.Millisecond) messages := srv.MessagesAndPurge() require.Len(t, messages, 3)