From 88886206c2c758bf619362aaa484dd3e254b8ed1 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 30 Jun 2025 10:08:52 +0300 Subject: fix: improve test server cleanup to prevent intermittent TestDMap2 failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added explicit cleanup with a 100ms delay when test servers are started to ensure the server process terminates and releases its port before the next test runs. This prevents intermittent failures in TestDMap2 when it runs after other tests that use servers. The issue was that test servers could linger briefly after context cancellation, causing port conflicts when tests run in sequence. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- integrationtests/testhelpers.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'integrationtests') diff --git a/integrationtests/testhelpers.go b/integrationtests/testhelpers.go index b750de6..a6a5f50 100644 --- a/integrationtests/testhelpers.go +++ b/integrationtests/testhelpers.go @@ -216,6 +216,12 @@ func NewTestServer(t *testing.T) *TestServer { // Start starts the test server with the given log level func (ts *TestServer) Start(logLevel string) error { + // Add cleanup to ensure server is stopped when test ends + ts.t.Cleanup(func() { + ts.Stop() + // Give the server a moment to release the port + time.Sleep(100 * time.Millisecond) + }) return startTestServer(ts.t, ts.ctx, &ServerConfig{ Port: ts.port, BindAddress: ts.bindAddress, @@ -225,6 +231,12 @@ func (ts *TestServer) Start(logLevel string) error { // StartWithConfig starts the test server with custom configuration func (ts *TestServer) StartWithConfig(cfg *ServerConfig) error { + // Add cleanup to ensure server is stopped when test ends + ts.t.Cleanup(func() { + ts.Stop() + // Give the server a moment to release the port + time.Sleep(100 * time.Millisecond) + }) if cfg == nil { cfg = &ServerConfig{} } -- cgit v1.2.3