aboutsummaryrefslogtreecommitdiffstats
path: root/vm/dispatcher
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-07-22 12:21:45 +0200
committerAleksandr Nogikh <nogikh@google.com>2024-07-22 11:16:48 +0000
commit06ab36e109f8f409164cec63eda8e45709ac631b (patch)
treed8be070d241885f12c47232d7873db5913c082a0 /vm/dispatcher
parent1d8deff9858ae1bb5f58b286cd92180af23282db (diff)
vm/dispatcher: make the test more deterministic
There was a race between starting the job and resetting the reserved VM count. Rewrite the test to let it run regardless of the thread interleaving. Closes #5090.
Diffstat (limited to 'vm/dispatcher')
-rw-r--r--vm/dispatcher/pool_test.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/vm/dispatcher/pool_test.go b/vm/dispatcher/pool_test.go
index 275186a15..d27e83205 100644
--- a/vm/dispatcher/pool_test.go
+++ b/vm/dispatcher/pool_test.go
@@ -79,17 +79,14 @@ func TestPoolSplit(t *testing.T) {
startedRuns := make(chan bool)
stopRuns := make(chan bool)
- for i := 0; i < 10; i++ {
- go func() {
- mgr.Run(func(ctx context.Context, _ *testInstance, _ UpdateInfo) {
- startedRuns <- true
- select {
- case <-ctx.Done():
- case <-stopRuns:
- }
- })
- }()
+ job := func(ctx context.Context, _ *testInstance, _ UpdateInfo) {
+ startedRuns <- true
+ select {
+ case <-ctx.Done():
+ case <-stopRuns:
+ }
}
+ go mgr.Run(job)
// So far, there are no reserved instances.
for i := 0; i < count; i++ {
@@ -113,9 +110,12 @@ func TestPoolSplit(t *testing.T) {
}
assert.EqualValues(t, 3, defaultCount.Load())
- // Now let's finish all jobs.
+ // Now let's create and finish more jobs.
+ for i := 0; i < 10; i++ {
+ go mgr.Run(job)
+ }
mgr.ReserveForRun(2)
- for i := 0; i < 9; i++ {
+ for i := 0; i < 10; i++ {
<-startedRuns
stopRuns <- true
}