Skip to content

Commit

Permalink
[Heartbeat] Fix race condition in scheduler tests (#35728)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilioalvap authored Jun 14, 2023
1 parent 4a16c6a commit 0866673
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions heartbeat/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ func TestSchedTaskLimits(t *testing.T) {
numJobs: 50,
limit: math.MaxInt64,
expect: func(events []int) {
require.GreaterOrEqual(t, len(events), 50)
require.GreaterOrEqual(t, len(events), 250)
},
},
{
name: "runs 100 with limit not configured",
numJobs: 100,
limit: 0,
expect: func(events []int) {
require.GreaterOrEqual(t, len(events), 100)
require.GreaterOrEqual(t, len(events), 500)
},
},
}
Expand All @@ -254,11 +254,15 @@ func TestSchedTaskLimits(t *testing.T) {
}
s := Create(math.MaxInt64, monitoring.NewRegistry(), tarawaTime(), jobConfigByType, false)
var taskArr []int
mtx := sync.Mutex{}
wg := sync.WaitGroup{}
wg.Add(tt.numJobs)
for i := 0; i < tt.numJobs; i++ {
num := i
tf := makeTasks(4, func() {
mtx.Lock()
defer mtx.Unlock() // taskArr is shared across goroutines

taskArr = append(taskArr, num)
})
go func(tff TaskFunc) {
Expand Down

0 comments on commit 0866673

Please sign in to comment.