From 3e21e678fa13f1cdd442877a105a12f0f255c505 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Mon, 20 Jun 2022 10:12:42 +0300 Subject: [PATCH] Revert "Try to respect zero target stages at the end (#2532)" This reverts commit b725f03be5873b9b0d933b94a83924ff7c1f15e4. --- lib/executor/ramping_vus.go | 7 +-- lib/executor/ramping_vus_test.go | 88 +------------------------------- 2 files changed, 6 insertions(+), 89 deletions(-) diff --git a/lib/executor/ramping_vus.go b/lib/executor/ramping_vus.go index 10bcdff20ba..4e1bb0cd768 100644 --- a/lib/executor/ramping_vus.go +++ b/lib/executor/ramping_vus.go @@ -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 @@ -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}) } diff --git a/lib/executor/ramping_vus_test.go b/lib/executor/ramping_vus_test.go index b6d3dfc3687..bd38bafe965 100644 --- a/lib/executor/ramping_vus_test.go +++ b/lib/executor/ramping_vus_test.go @@ -560,8 +560,6 @@ 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) @@ -569,9 +567,9 @@ func TestRampingVUsConfigExecutionPlanExampleOneThird(t *testing.T) { 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 @@ -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 @@ -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 @@ -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()