From b244db94e24ce5497b97f4ec60fb9f02044edcc6 Mon Sep 17 00:00:00 2001 From: wiggin77 Date: Sun, 25 May 2025 00:06:14 -0400 Subject: [PATCH] fix race --- Makefile | 6 ++++++ mock_smtp_server.go | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c472632..391c5bf 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,11 @@ build: test: go test ./... +# Run tests with race condition detection +.PHONY: test-race +test-race: + go test -race ./... + # Build for all supported architectures .PHONY: buildall buildall: clean @@ -78,6 +83,7 @@ help: @echo " build - Build for current architecture" @echo " buildall - Build for all supported architectures" @echo " test - Run tests" + @echo " test-race - Run tests with race condition detection" @echo " check-style - Install golangci-lint and run code style checks" @echo " clean - Remove build artifacts" @echo " run - Build and run the application" diff --git a/mock_smtp_server.go b/mock_smtp_server.go index 588f1b8..a1b4a9e 100644 --- a/mock_smtp_server.go +++ b/mock_smtp_server.go @@ -165,10 +165,10 @@ func (s *MockSMTPServer) Reset() { } func (s *MockSMTPServer) acceptConnections() { - for s.running { + for s.isRunning() { conn, err := s.listener.Accept() if err != nil { - if s.running { + if s.isRunning() { fmt.Printf("Accept error: %v\n", err) } continue @@ -178,6 +178,12 @@ func (s *MockSMTPServer) acceptConnections() { } } +func (s *MockSMTPServer) isRunning() bool { + s.mu.Lock() + defer s.mu.Unlock() + return s.running +} + func (s *MockSMTPServer) handleConnection(conn net.Conn) { defer conn.Close()