fix: remove redundant defer setup.Close() calls to enable library cleanup

Problem:
Tests were calling `defer setup.Close()` which was interfering with the
library cleanup added in the previous commit. The execution order was:

1. setupTestServer() registers t.Cleanup() with library deletion code
2. Test calls defer setup.Close()
3. Test finishes:
   - defer setup.Close() runs FIRST → closes DB pool
   - t.Cleanup() runs SECOND → tries to delete libraries but DB is closed!

This prevented "Job Status Test Library" and other test libraries from
being cleaned up, leaving residual data in the database after tests.

Root Cause:
The setupTestServer() function already handles cleanup via t.Cleanup(),
which calls setup.Close() at the end. The explicit defer calls were
redundant and caused the database pool to close before library cleanup
could execute.

Solution:
Removed all 17 occurrences of `defer setup.Close()` from test files:
- worker_test.go: 4 tests
- jobs_test.go: 7 tests
- scan_settings_integration_test.go: 3 tests
- library_browse_test.go: 1 test
- goroutine_leak_test.go: 1 test
- fsnotify_integration_test.go: 1 test

Now setupTestServer()'s t.Cleanup() function properly:
1. Deletes "test" libraries (while DB is still connected)
2. Then calls setup.Close() to close connections

This ensures all test libraries are cleaned up, leaving a clean database
after `make test-integration` completes.

Files changed:
- cmd/server/tests/worker_test.go: Removed 4 defer calls
- cmd/server/tests/jobs_test.go: Removed 7 defer calls
- cmd/server/tests/scan_settings_integration_test.go: Removed 3 defer calls
- cmd/server/tests/library_browse_test.go: Removed 1 defer call
- cmd/server/tests/goroutine_leak_test.go: Removed 1 defer call
- cmd/server/tests/fsnotify_integration_test.go: Removed 1 defer call
This commit is contained in:
2026-03-24 20:55:37 -04:00
parent 93c623bc1a
commit b700f64624
6 changed files with 0 additions and 17 deletions
-4
View File
@@ -21,7 +21,6 @@ import (
func TestWorker_DirectoryScanJob(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
token := setup.Token
@@ -122,7 +121,6 @@ func TestWorker_DirectoryScanJob(t *testing.T) {
func TestWorker_SetFoldersJob(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
token := setup.Token
@@ -192,7 +190,6 @@ func TestWorker_SetFoldersJob(t *testing.T) {
func TestWorker_ConcurrentJobs(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
ctx := context.Background()
@@ -253,7 +250,6 @@ func TestWorker_ConcurrentJobs(t *testing.T) {
func TestWorker_JobStatusTracking(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
ctx := context.Background()