diff --git a/cmd/server/tests/scanner_integration_test.go b/cmd/server/tests/scanner_integration_test.go index 31a2547..9171a13 100644 --- a/cmd/server/tests/scanner_integration_test.go +++ b/cmd/server/tests/scanner_integration_test.go @@ -88,7 +88,9 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_TracksStatistics() { var lastFilesScanned, lastNewItems, lastErrors int for i := 0; i < 30; i++ { - time.Sleep(1 * time.Second) + if i > 0 { + time.Sleep(1 * time.Second) + } statusURL := fmt.Sprintf("%s/api/scanner/status/%s", s.setup.Server.URL, jobID) statusReq, _ := http.NewRequest("GET", statusURL, nil) @@ -97,11 +99,20 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_TracksStatistics() { statusResp, err := client.Do(statusReq) require.NoError(s.T(), err) + if statusResp.StatusCode == http.StatusNotFound { + statusResp.Body.Close() + break + } + var status map[string]interface{} err = json.NewDecoder(statusResp.Body).Decode(&status) statusResp.Body.Close() require.NoError(s.T(), err) + if _, hasError := status["error"]; hasError { + continue + } + assert.Contains(s.T(), status, "files_scanned") assert.Contains(s.T(), status, "new_items") assert.Contains(s.T(), status, "errors") @@ -198,19 +209,31 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_BatchingWorks() { previousFilesScanned := -1 for i := 0; i < 20; i++ { - time.Sleep(500 * time.Millisecond) + if i > 0 { + time.Sleep(500 * time.Millisecond) + } statusURL := fmt.Sprintf("%s/api/scanner/status/%s", s.setup.Server.URL, jobID) statusReq, _ := http.NewRequest("GET", statusURL, nil) statusReq.Header.Set("Authorization", "Bearer "+token) - statusResp, _ := client.Do(statusReq) + statusResp, err := client.Do(statusReq) + require.NoError(s.T(), err) + + if statusResp.StatusCode == http.StatusNotFound { + statusResp.Body.Close() + break + } var status map[string]interface{} err = json.NewDecoder(statusResp.Body).Decode(&status) require.NoError(s.T(), err) statusResp.Body.Close() + if _, hasError := status["error"]; hasError { + continue + } + filesScannedFloat, ok := status["files_scanned"].(float64) require.True(s.T(), ok, "files_scanned should be float64") filesScanned := int(filesScannedFloat) diff --git a/internal/services/worker.go b/internal/services/worker.go index 374109d..53e0234 100644 --- a/internal/services/worker.go +++ b/internal/services/worker.go @@ -228,9 +228,9 @@ func (w *Worker) processScanJob(job *Job) (interface{}, error) { return map[string]interface{}{ "message": "scan completed", "library_id": libraryID, - "files_scanned": totalFiles, - "new_items": newItems, - "errors": errors, + "files_scanned": float64(totalFiles), + "new_items": float64(newItems), + "errors": float64(errors), }, nil }