Skip to content

Commit

Permalink
Fix race condition in ramping-vus tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mstoykov committed May 29, 2024
1 parent bdbe5b5 commit 93649df
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions lib/executor/ramping_vus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,53 @@ 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")
})

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")

Expand All @@ -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)
})
}
Expand Down

0 comments on commit 93649df

Please sign in to comment.