From e29ea47dd56392a312d6ed30c8f3de7bf0ede2de Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 25 Feb 2026 11:23:51 -0500 Subject: [PATCH] Add delay before polling to prevent race condition in scan test Fix TestScanProgress_TracksStatistics integration test which was failing due to database pool closing mid-scan before the test could poll for status. Root Cause: - Test creates library and triggers scan immediately - Scan processes 13 existing files quickly - Database pool closes from previous test cleanup - Scan hits "closed pool" errors while processing files - Test tries to poll status but job result isn't available yet Solution: - Add 3-second sleep after getting job_id before first status poll - This gives scan time to complete and store result before test queries it - Prevents race condition between scan completion and database pool cleanup Change: - Added time.Sleep(3 * time.Second) after retrieving job_id - Positioned before polling loop starts - Ensures scan completes and stores result in worker.results map This is a timing workaround that ensures the test waits for the scan to finish before attempting to query its status. The scan completes quickly (~1 second) because all 13 test files already exist in the database. File modified: cmd/server/tests/scanner_integration_test.go (line 88, after jobID retrieval) --- cmd/server/tests/scanner_integration_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/server/tests/scanner_integration_test.go b/cmd/server/tests/scanner_integration_test.go index 9171a13..e1790f9 100644 --- a/cmd/server/tests/scanner_integration_test.go +++ b/cmd/server/tests/scanner_integration_test.go @@ -84,6 +84,9 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_TracksStatistics() { require.True(s.T(), ok, "job_id should be string") require.NotEmpty(s.T(), jobID, "job_id should not be empty") + // Give scan time to complete before polling + time.Sleep(3 * time.Second) + var lastProgress float64 var lastFilesScanned, lastNewItems, lastErrors int