From 26c69211a93beb459759047d5010461bf4c0df4a Mon Sep 17 00:00:00 2001 From: Elliot Courant Date: Fri, 6 Oct 2023 12:17:48 -0500 Subject: [PATCH] fix(pg): Fixed data race conditions in unit tests Since these values are being written in a separate go routine, it is possible for a datarace to happen since we are reading them unatomically. This just makes it so that both the reads ands writes are done atomically. Resolves #76 --- backends/postgres/postgres_backend_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backends/postgres/postgres_backend_test.go b/backends/postgres/postgres_backend_test.go index 5297535..352b868 100644 --- a/backends/postgres/postgres_backend_test.go +++ b/backends/postgres/postgres_backend_test.go @@ -213,7 +213,7 @@ func TestMultipleProcessors(t *testing.T) { wg.Wait() // Make sure that we executed the expected number of jobs. - if execCount != uint32(ConcurrentWorkers) { + if atomic.LoadUint32(&execCount) != uint32(ConcurrentWorkers) { t.Fatalf("mismatch number of executions. Expected: %d Found: %d", ConcurrentWorkers, execCount) } } @@ -429,11 +429,11 @@ func TestMultipleCronNodes(t *testing.T) { // allow time for listener to start and for at least one job to process time.Sleep(WaitForJobTime) - if jobsCompleted == 0 { + if atomic.LoadUint32(&jobsCompleted) == 0 { t.Fatalf("no jobs were completed after %v", WaitForJobTime) } - if duplicateJobs > 0 { + if atomic.LoadUint32(&duplicateJobs) > 0 { t.Fatalf("some jobs were processed more than once") } }