Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Heartbeat] Fix race condition in scheduler tests #35728

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels wrong, Even though the limit is maxed out, any reason why we are going far of the configured number of jobs? Probably I am missing something here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each task is generating 4 additional continuations, which it didn't originally account for

tf := makeTasks(4, func() {
.

},
},
{
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