Skip to content

Commit

Permalink
fix(pg): Fixed data race conditions in unit tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
elliotcourant authored and acaloiaro committed Oct 6, 2023
1 parent 42da4d8 commit 26c6921
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backends/postgres/postgres_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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")
}
}
Expand Down

0 comments on commit 26c6921

Please sign in to comment.