Skip to content

Commit

Permalink
Revert "Try to respect zero target stages at the end (#2532)"
Browse files Browse the repository at this point in the history
This reverts commit b725f03.
  • Loading branch information
mstoykov committed Jun 20, 2022
1 parent 556747f commit 3e21e67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 89 deletions.
7 changes: 4 additions & 3 deletions lib/executor/ramping_vus.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ func (vlvc RampingVUsConfig) getRawExecutionSteps(et *lib.ExecutionTuple, zeroEn
fromVUs = stageEndVUs
}

if zeroEnd {
if zeroEnd && steps[len(steps)-1].PlannedVUs != 0 {
// If the last PlannedVUs value wasn't 0, add a last step with 0
steps = append(steps, lib.ExecutionStep{TimeOffset: timeTillEnd, PlannedVUs: 0})
}
return steps
Expand Down Expand Up @@ -457,8 +458,8 @@ func (vlvc RampingVUsConfig) GetExecutionRequirements(et *lib.ExecutionTuple) []
steps = vlvc.reserveVUsForGracefulRampDowns(steps, executorEndOffset)
}

// add one step for the end of the gracefulStop
if steps[len(steps)-1].PlannedVUs != 0 || steps[len(steps)-1].TimeOffset != executorEndOffset {
// If the last PlannedVUs value wasn't 0, add a last step with 0
if steps[len(steps)-1].PlannedVUs != 0 {
steps = append(steps, lib.ExecutionStep{TimeOffset: executorEndOffset, PlannedVUs: 0})
}

Expand Down
88 changes: 2 additions & 86 deletions lib/executor/ramping_vus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,18 +560,16 @@ func TestRampingVUsConfigExecutionPlanExampleOneThird(t *testing.T) {
{TimeOffset: 16 * time.Second, PlannedVUs: 1},
{TimeOffset: 20 * time.Second, PlannedVUs: 0},
}
expRawStepsZeroEnd := expRawStepsNoZeroEnd // no need to copy
expRawStepsZeroEnd = append(expRawStepsZeroEnd, lib.ExecutionStep{TimeOffset: 23 * time.Second, PlannedVUs: 0})
rawStepsNoZeroEnd := conf.getRawExecutionSteps(et, false)
assert.Equal(t, expRawStepsNoZeroEnd, rawStepsNoZeroEnd)
endOffset, isFinal := lib.GetEndOffset(rawStepsNoZeroEnd)
assert.Equal(t, 20*time.Second, endOffset)
assert.Equal(t, true, isFinal)

rawStepsZeroEnd := conf.getRawExecutionSteps(et, true)
assert.Equal(t, expRawStepsZeroEnd, rawStepsZeroEnd)
assert.Equal(t, expRawStepsNoZeroEnd, rawStepsZeroEnd)
endOffset, isFinal = lib.GetEndOffset(rawStepsZeroEnd)
assert.Equal(t, 23*time.Second, endOffset)
assert.Equal(t, 20*time.Second, endOffset)
assert.Equal(t, true, isFinal)

// GracefulStop and GracefulRampDown equal to the default 30 sec
Expand All @@ -580,7 +578,6 @@ func TestRampingVUsConfigExecutionPlanExampleOneThird(t *testing.T) {
{TimeOffset: 1 * time.Second, PlannedVUs: 2},
{TimeOffset: 42 * time.Second, PlannedVUs: 1},
{TimeOffset: 50 * time.Second, PlannedVUs: 0},
{TimeOffset: 53 * time.Second, PlannedVUs: 0},
}, conf.GetExecutionRequirements(et))

// Try a longer GracefulStop than the GracefulRampDown
Expand All @@ -590,7 +587,6 @@ func TestRampingVUsConfigExecutionPlanExampleOneThird(t *testing.T) {
{TimeOffset: 1 * time.Second, PlannedVUs: 2},
{TimeOffset: 42 * time.Second, PlannedVUs: 1},
{TimeOffset: 50 * time.Second, PlannedVUs: 0},
{TimeOffset: 103 * time.Second, PlannedVUs: 0},
}, conf.GetExecutionRequirements(et))

// Try a much shorter GracefulStop than the GracefulRampDown
Expand All @@ -614,86 +610,6 @@ func TestRampingVUsConfigExecutionPlanExampleOneThird(t *testing.T) {
assert.Equal(t, rawStepsZeroEnd, conf.GetExecutionRequirements(et))
}

func TestRampingVUsConfigExecutionPlanZerosAtEnd(t *testing.T) {
t.Parallel()
et, err := lib.NewExecutionTuple(nil, nil)
require.NoError(t, err)
conf := NewRampingVUsConfig("test")
conf.StartVUs = null.IntFrom(1)
conf.Stages = []Stage{
{Target: null.IntFrom(5), Duration: types.NullDurationFrom(4 * time.Second)},
{Target: null.IntFrom(0), Duration: types.NullDurationFrom(5 * time.Second)},
{Target: null.IntFrom(0), Duration: types.NullDurationFrom(5 * time.Second)},
}

expRawStepsNoZeroEnd := []lib.ExecutionStep{
{TimeOffset: 0 * time.Second, PlannedVUs: 1},
{TimeOffset: 1 * time.Second, PlannedVUs: 2},
{TimeOffset: 2 * time.Second, PlannedVUs: 3},
{TimeOffset: 3 * time.Second, PlannedVUs: 4},
{TimeOffset: 4 * time.Second, PlannedVUs: 5},
{TimeOffset: 5 * time.Second, PlannedVUs: 4},
{TimeOffset: 6 * time.Second, PlannedVUs: 3},
{TimeOffset: 7 * time.Second, PlannedVUs: 2},
{TimeOffset: 8 * time.Second, PlannedVUs: 1},
{TimeOffset: 9 * time.Second, PlannedVUs: 0},
}
expRawStepsZeroEnd := expRawStepsNoZeroEnd // no need to copy
expRawStepsZeroEnd = append(expRawStepsZeroEnd, lib.ExecutionStep{TimeOffset: 14 * time.Second, PlannedVUs: 0})
rawStepsNoZeroEnd := conf.getRawExecutionSteps(et, false)
assert.Equal(t, expRawStepsNoZeroEnd, rawStepsNoZeroEnd)
endOffset, isFinal := lib.GetEndOffset(rawStepsNoZeroEnd)
assert.Equal(t, 9*time.Second, endOffset)
assert.Equal(t, true, isFinal)

rawStepsZeroEnd := conf.getRawExecutionSteps(et, true)
assert.Equal(t, expRawStepsZeroEnd, rawStepsZeroEnd)
endOffset, isFinal = lib.GetEndOffset(rawStepsZeroEnd)
assert.Equal(t, 14*time.Second, endOffset)
assert.Equal(t, true, isFinal)
}

func TestRampingVUsConfigExecutionPlanZeroGracefuls(t *testing.T) {
t.Parallel()

config := RampingVUsConfig{
BaseConfig: BaseConfig{GracefulStop: types.NullDurationFrom(0 * time.Second)},
StartVUs: null.IntFrom(0),
GracefulRampDown: types.NullDurationFrom(0 * time.Second),
Stages: []Stage{
{
Duration: types.NullDurationFrom(1 * time.Second),
Target: null.IntFrom(2),
},
},
}

et, err := lib.NewExecutionTuple(nil, nil)
require.NoError(t, err)
es := lib.NewExecutionState(lib.Options{}, et, nil, 10, 50)
var done int64
ctx, cancel, executor, _ := setupExecutor(
t, config, es,
simpleRunner(func(ctx context.Context, _ *lib.State) error {
atomic.AddInt64(&done, 1)
<-ctx.Done()

return nil
}),
)
defer cancel()
errCh := make(chan error)
go func() { errCh <- executor.Run(ctx, nil) }()

select {
case err := <-errCh:
require.NoError(t, err)
case <-time.After(2 * time.Second): // way too much time
t.Fatal("Execution should've ended already")
}
require.Equal(t, int64(1), atomic.LoadInt64(&done))
}

func TestRampingVUsExecutionTupleTests(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 3e21e67

Please sign in to comment.