Skip to content

Commit ba2eb54

Browse files
authored
Merge pull request #276 from form3tech-oss/nvloff-268
fix: users in a staged run would exit immediately without max iterations
2 parents 909ed45 + 6ea37f7 commit ba2eb54

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

internal/run/run_cmd_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"time"
66
)
77

8+
const Any = int64(-1)
9+
810
func TestSimpleFlow(t *testing.T) {
911
t.Parallel()
1012

@@ -49,7 +51,7 @@ type testParam struct {
4951
constantRate string
5052
testDuration time.Duration
5153
expectedRunTime time.Duration
52-
expectedCompletedTests uint32
54+
expectedCompletedTests int64
5355
concurrency int
5456
iterationDuration time.Duration
5557
expectedDroppedIterations uint64
@@ -349,6 +351,15 @@ func TestParameterised(t *testing.T) {
349351
expectedRunTime: 1800 * time.Millisecond,
350352
expectedCompletedTests: 105,
351353
},
354+
{
355+
name: "staged users without max iterations",
356+
triggerType: File,
357+
configFile: "../testdata/config-file-issue-268.yaml",
358+
testDuration: 5 * time.Second,
359+
iterationDuration: 0,
360+
expectedRunTime: 3000 * time.Millisecond,
361+
expectedCompletedTests: Any,
362+
},
352363
{
353364
name: "config file test using limited max-duration",
354365
triggerType: File,

internal/run/run_stage_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,12 @@ func (s *RunTestStage) the_command_should_have_run_for_approx(expectedDuration t
261261
return s
262262
}
263263

264-
func (s *RunTestStage) the_number_of_started_iterations_should_be(expected uint32) *RunTestStage {
265-
s.assert.Equal(int(expected), int(s.runCount.Load()), "number of started iterations")
264+
func (s *RunTestStage) the_number_of_started_iterations_should_be(expected int64) *RunTestStage {
265+
if expected == Any {
266+
s.assert.Positive(s.runCount.Load())
267+
} else {
268+
s.assert.Equal(int(expected), int(s.runCount.Load()), "number of started iterations")
269+
}
266270
return s
267271
}
268272

@@ -355,8 +359,12 @@ func (s *RunTestStage) setup_teardown_is_called() *RunTestStage {
355359
return s
356360
}
357361

358-
func (s *RunTestStage) iteration_teardown_is_called_n_times(n uint32) *RunTestStage {
359-
s.assert.Equal(int(n), int(s.iterationTeardownCount.Load()), "iteration teardown was not called expected times")
362+
func (s *RunTestStage) iteration_teardown_is_called_n_times(n int64) *RunTestStage {
363+
if n == Any {
364+
s.assert.Positive(s.iterationTeardownCount.Load())
365+
} else {
366+
s.assert.Equal(int(n), int(s.iterationTeardownCount.Load()), "iteration teardown was not called expected times")
367+
}
360368
return s
361369
}
362370

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
scenario: test
2+
limits:
3+
max-duration: 5s
4+
max-iterations: 0
5+
concurrency: 5
6+
ignore-dropped: true
7+
stages:
8+
- duration: 3s
9+
mode: users

internal/trigger/users/users_rate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ func NewWorker(concurrency int) api.WorkTriggerer {
4848
return func(ctx context.Context, _ *ui.Output, workers *workers.PoolManager, _ options.RunOptions) {
4949
pool := workers.NewContinuousPool(concurrency)
5050
pool.Start(ctx)
51+
<-workers.WaitForCompletion()
5152
}
5253
}

0 commit comments

Comments
 (0)