Skip to content

Commit

Permalink
js: skip minIterationDuration in setup/teardown
Browse files Browse the repository at this point in the history
Close #1003
  • Loading branch information
cuonglm committed Sep 25, 2019
1 parent 19c6796 commit 504e1c6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
42 changes: 42 additions & 0 deletions core/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,3 +968,45 @@ func TestMinIterationDuration(t *testing.T) {
// But we expect the custom counter to be added to 4 times
assert.Equal(t, 4.0, getMetricSum(collector, "testcounter"))
}

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

runner, err := js.New(
&loader.SourceData{URL: &url.URL{Path: "/script.js"}, Data: []byte(`
import { sleep } from "k6";
export function setup() {
sleep(0.5);
}
export let options = {
minIterationDuration: "1s",
duration: "2s",
setupTimeout: "2s",
};
export default function () {
};`)},
nil,
lib.RuntimeOptions{},
)
require.NoError(t, err)

engine, err := NewEngine(local.New(runner), runner.GetOptions())
require.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())
errC := make(chan error)
go func() { errC <- engine.Run(ctx) }()

select {
case <-time.After(10 * time.Second):
cancel()
t.Fatal("Test timed out")
case err := <-errC:
cancel()
require.NoError(t, err)
require.False(t, engine.IsTainted())
}
}
3 changes: 2 additions & 1 deletion js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,10 @@ func (u *VU) runFn(

state.Samples <- u.Dialer.GetTrail(startTime, endTime, isFullIteration, stats.IntoSampleTags(&tags))

inVuStage := group.Name != stageSetup && group.Name != stageTeardown
// If MinIterationDuration is specified and the iteration wasn't cancelled
// and was less than it, sleep for the remainder
if isFullIteration && state.Options.MinIterationDuration.Valid {
if inVuStage && isFullIteration && state.Options.MinIterationDuration.Valid {
durationDiff := time.Duration(state.Options.MinIterationDuration.Duration) - endTime.Sub(startTime)
if durationDiff > 0 {
time.Sleep(durationDiff)
Expand Down

0 comments on commit 504e1c6

Please sign in to comment.