git » chasquid » commit 99c4ad5

smtpsrv: Disable reloads during tests

author Alberto Bertogli
2019-12-01 18:48:08 UTC
committer Alberto Bertogli
2019-12-01 19:09:58 UTC
parent e8a6bf61881b3aa0709abc3fab6ea112154add39

smtpsrv: Disable reloads during tests

Reloading during tests will cause the testing aliases to be removed,
which makes test runs that extend beyond 30s to be flaky.

This patch fixes the bug by disabling reloads during these tests.

internal/smtpsrv/server.go +3 -0
internal/smtpsrv/server_test.go +3 -0

diff --git a/internal/smtpsrv/server.go b/internal/smtpsrv/server.go
index 4e3105a..9b5fe28 100644
--- a/internal/smtpsrv/server.go
+++ b/internal/smtpsrv/server.go
@@ -163,6 +163,9 @@ func (s *Server) InitQueue(path string, localC, remoteC courier.Courier) {
 // periodicallyReload some of the server's information, such as aliases and
 // the user databases.
 func (s *Server) periodicallyReload() {
+	if reloadEvery == nil {
+		return
+	}
 	for range time.Tick(*reloadEvery) {
 		err := s.aliasesR.Reload()
 		if err != nil {
diff --git a/internal/smtpsrv/server_test.go b/internal/smtpsrv/server_test.go
index 6da06a8..3e46726 100644
--- a/internal/smtpsrv/server_test.go
+++ b/internal/smtpsrv/server_test.go
@@ -584,6 +584,9 @@ func realMain(m *testing.M) int {
 		// Disable SPF lookups, to avoid leaking DNS queries.
 		disableSPFForTesting = true
 
+		// Disable reloading.
+		reloadEvery = nil
+
 		go s.ListenAndServe()
 	}