From 06ab36e109f8f409164cec63eda8e45709ac631b Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Mon, 22 Jul 2024 12:21:45 +0200 Subject: 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. --- vm/dispatcher/pool_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'vm/dispatcher') 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 } -- cgit mrf-deployment