Skip to content

Commit

Permalink
Fix race condition in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Mar 12, 2020
1 parent 0a50f20 commit 9fa61d9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/executor/constant_arrival_rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,16 @@ func TestConstantArrivalRateRunCorrectTiming(t *testing.T) {
newET := es.ExecutionTuple.GetNewExecutionTupleBasedOnValue(config.MaxVUs.Int64)
rateScaled := newET.ScaleInt64(config.Rate.Int64)
var startTime = time.Now()
var expectedTime = test.start
var expectedTimeInt64 = int64(test.start)
var ctx, cancel, executor, logHook = setupExecutor(
t, config, es,
simpleRunner(func(ctx context.Context) error {
current := atomic.AddInt64(&count, 1)

var expectedTime = test.start
if current != 1 {
expectedTime += time.Millisecond * time.Duration(test.steps[(current-2)%int64(len(test.steps))])
expectedTime = time.Duration(atomic.AddInt64(&expectedTimeInt64,
int64(time.Millisecond)*test.steps[(current-2)%int64(len(test.steps))]))
}
assert.WithinDuration(t,
startTime.Add(expectedTime),
Expand Down

0 comments on commit 9fa61d9

Please sign in to comment.