From d7c6497ad7df15367fa11fbf40e36525d2ee3fd3 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Wed, 29 May 2024 12:13:15 +0300 Subject: [PATCH] Fix race condition in ramping-vus tests During #3470 some sub tests were added and they access the same variable from the not sub test. This obviously is a race condition that nobody noticed. --- lib/executor/ramping_vus_test.go | 48 +++++++++++++++++--------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/executor/ramping_vus_test.go b/lib/executor/ramping_vus_test.go index 7806c7c4492..1413a58555a 100644 --- a/lib/executor/ramping_vus_test.go +++ b/lib/executor/ramping_vus_test.go @@ -20,35 +20,39 @@ import ( func TestRampingVUsConfigValidation(t *testing.T) { t.Parallel() + const maxConcurrentVUs = 100_000_000 - errs := NewRampingVUsConfig("default").Validate() - require.NotEmpty(t, errs) - assert.Contains(t, errs[0].Error(), "one stage has to be specified") - - c := NewRampingVUsConfig("stage") - c.Stages = []Stage{ - {Target: null.IntFrom(0), Duration: types.NullDurationFrom(12 * time.Second)}, - } - errs = c.Validate() - require.Empty(t, errs) // by default StartVUs is 1 - - c.StartVUs = null.IntFrom(0) - errs = c.Validate() - require.NotEmpty(t, errs) - assert.Contains(t, errs[0].Error(), "greater than 0") + t.Run("no stages", func(t *testing.T) { + t.Parallel() + errs := NewRampingVUsConfig("default").Validate() + require.NotEmpty(t, errs) + assert.Contains(t, errs[0].Error(), "one stage has to be specified") + }) + t.Run("basic 1 stage", func(t *testing.T) { + t.Parallel() + c := NewRampingVUsConfig("stage") + c.Stages = []Stage{ + {Target: null.IntFrom(0), Duration: types.NullDurationFrom(12 * time.Second)}, + } + errs := c.Validate() + require.Empty(t, errs) // by default StartVUs is 1 - const maxConcurrentVUs = 100_000_000 + c.StartVUs = null.IntFrom(0) + errs = c.Validate() + require.NotEmpty(t, errs) + assert.Contains(t, errs[0].Error(), "greater than 0") + }) t.Run("If startVUs are larger than maxConcurrentVUs, the validation should return an error", func(t *testing.T) { t.Parallel() - c = NewRampingVUsConfig("stage") + c := NewRampingVUsConfig("stage") c.StartVUs = null.IntFrom(maxConcurrentVUs + 1) c.Stages = []Stage{ {Target: null.IntFrom(0), Duration: types.NullDurationFrom(1 * time.Second)}, } - errs = c.Validate() + errs := c.Validate() require.NotEmpty(t, errs) assert.Contains(t, errs[0].Error(), "the startVUs exceed max limit of") }) @@ -56,13 +60,13 @@ func TestRampingVUsConfigValidation(t *testing.T) { t.Run("For multiple VU values larger than maxConcurrentVUs, multiple errors are returned", func(t *testing.T) { t.Parallel() - c = NewRampingVUsConfig("stage") + c := NewRampingVUsConfig("stage") c.StartVUs = null.IntFrom(maxConcurrentVUs + 1) c.Stages = []Stage{ {Target: null.IntFrom(maxConcurrentVUs + 2), Duration: types.NullDurationFrom(1 * time.Second)}, } - errs = c.Validate() + errs := c.Validate() require.Equal(t, 2, len(errs)) assert.Contains(t, errs[0].Error(), "the startVUs exceed max limit of") @@ -72,13 +76,13 @@ func TestRampingVUsConfigValidation(t *testing.T) { t.Run("VU values below maxConcurrentVUs will pass validation", func(t *testing.T) { t.Parallel() - c = NewRampingVUsConfig("stage") + c := NewRampingVUsConfig("stage") c.StartVUs = null.IntFrom(0) c.Stages = []Stage{ {Target: null.IntFrom(maxConcurrentVUs - 1), Duration: types.NullDurationFrom(1 * time.Second)}, } - errs = c.Validate() + errs := c.Validate() require.Empty(t, errs) }) }