Skip to content

Commit

Permalink
Prevent data race in test
Browse files Browse the repository at this point in the history
  • Loading branch information
mileusna committed Aug 5, 2021
1 parent 3aecc7a commit 5f6295a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,19 @@ func TestRunAll(t *testing.T) {

ctab := crontab.New()

if err := ctab.AddJob("* * * * *", func() { testN++ }); err != nil {
var wg sync.WaitGroup
wg.Add(2)

if err := ctab.AddJob("* * * * *", func() { testN++; wg.Done() }); err != nil {
t.Fatal(err)
}

if err := ctab.AddJob("* * * * *", func(s string) { testS = s }, "param"); err != nil {
if err := ctab.AddJob("* * * * *", func(s string) { testS = s; wg.Done() }, "param"); err != nil {
t.Fatal(err)
}

ctab.RunAll()
time.Sleep(time.Second)
wg.Wait()

if testN != 1 {
t.Error("func not executed on RunAll()")
Expand Down

0 comments on commit 5f6295a

Please sign in to comment.