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
-7
View File
@@ -15,7 +15,6 @@ import (
func TestJobsHandler_CreateJob(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
token := setup.Token
@@ -50,7 +49,6 @@ func TestJobsHandler_CreateJob(t *testing.T) {
func TestJobsHandler_CreateJob_InvalidType(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
token := setup.Token
@@ -74,7 +72,6 @@ func TestJobsHandler_CreateJob_InvalidType(t *testing.T) {
func TestJobsHandler_GetJobStatus(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
token := setup.Token
@@ -119,7 +116,6 @@ func TestJobsHandler_GetJobStatus(t *testing.T) {
func TestJobsHandler_GetJobStatus_NotFound(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
token := setup.Token
@@ -139,7 +135,6 @@ func TestJobsHandler_GetJobStatus_NotFound(t *testing.T) {
func TestJobsHandler_CreateAndTrackJob(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
token := setup.Token
@@ -194,7 +189,6 @@ func TestJobsHandler_CreateAndTrackJob(t *testing.T) {
func TestJobsHandler_CreateJob_Unauthorized(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
jobReq := map[string]interface{}{
"type": "import",
@@ -215,7 +209,6 @@ func TestJobsHandler_CreateJob_Unauthorized(t *testing.T) {
func TestJobsHandler_GetJobStatus_Unauthorized(t *testing.T) {
setup := setupTestServer(t)
defer setup.Close()
jobID := uuid.New().String()