Skip to content

Commit 5593715

Browse files
committed
test: remove go-cron race condition workaround
go-cron v0.7.1 fixed the race conditions when adding/removing jobs while the scheduler is running. This removes the workaround that stopped the scheduler before adding new jobs in the concurrent operations test. Ref: netresearch/go-cron#262
1 parent 3c35ec8 commit 5593715

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

core/scheduler_edge_cases_test.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,11 @@ func TestSchedulerConcurrentOperations(t *testing.T) {
177177
scheduler := NewScheduler(&TestLogger{})
178178
scheduler.SetMaxConcurrentJobs(5)
179179

180-
// go-cron has internal race conditions when AddJob is called concurrently
181-
// while the scheduler is running. We pre-add jobs before starting,
182-
// then only test concurrent read/update operations which are safe.
183180
// Reduced worker count to avoid CI timeouts with race detector
184181
const numWorkers = 5
185182
const jobsPerWorker = 3
186183

187-
// Pre-add all jobs BEFORE starting the scheduler to avoid race conditions
188-
// in go-cron's internal map access during concurrent AddJob calls
184+
// Pre-add jobs before starting the scheduler
189185
for worker := 0; worker < numWorkers; worker++ {
190186
for jobIdx := 0; jobIdx < jobsPerWorker; jobIdx++ {
191187
jobName := fmt.Sprintf("worker%d-job%d", worker, jobIdx)
@@ -200,6 +196,7 @@ func TestSchedulerConcurrentOperations(t *testing.T) {
200196
if err := scheduler.Start(); err != nil {
201197
t.Fatalf("Failed to start scheduler: %v", err)
202198
}
199+
defer scheduler.Stop()
203200

204201
var wg sync.WaitGroup
205202
wg.Add(numWorkers)
@@ -244,15 +241,10 @@ func TestSchedulerConcurrentOperations(t *testing.T) {
244241
t.Error("Scheduler should still be running after concurrent operations")
245242
}
246243

247-
// Stop scheduler before adding new jobs to avoid race conditions in go-cron
248-
// Note: In our testing, go-cron exhibits race conditions when AddJob is called while running
249-
// See: https://github.com/netresearch/go-cron/issues/262
250-
scheduler.Stop()
251-
252-
// Test basic functionality still works (add a new job after stress test)
244+
// Test adding a new job while scheduler is running (go-cron v0.7.1 fixed race conditions)
253245
testJob := NewErrorJob("final-test", "@daily")
254246
if err := scheduler.AddJob(testJob); err != nil {
255-
t.Errorf("Scheduler should still accept jobs after stress test: %v", err)
247+
t.Errorf("Scheduler should accept jobs while running: %v", err)
256248
}
257249
}
258250

0 commit comments

Comments
 (0)