Skip to content

Commit

Permalink
Add an integration test to verify minIterationDuration behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- committed Dec 4, 2022
1 parent e1491c4 commit a67cb56
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,3 +1065,45 @@ func TestActiveVUsCount(t *testing.T) {
}
}
}

func TestMinIterationDuration(t *testing.T) {
t.Parallel()
script := []byte(`
import { Counter } from 'k6/metrics';
export let options = {
minIterationDuration: '5s',
setupTimeout: '2s',
teardownTimeout: '2s',
thresholds: {
'test_counter': ['count == 3'],
},
};
var c = new Counter('test_counter');
export function setup() { c.add(1); };
export default function () { c.add(1); };
export function teardown() { c.add(1); };
`)

srv := getCloudTestEndChecker(t, lib.RunStatusFinished, cloudapi.ResultStatusPassed)

ts := newGlobalTestState(t)
require.NoError(t, afero.WriteFile(ts.fs, filepath.Join(ts.cwd, "test.js"), script, 0o644))
ts.envVars = map[string]string{"K6_CLOUD_HOST": srv.URL}
ts.args = []string{"k6", "run", "--quiet", "--log-output=stdout", "--out", "cloud", "test.js"}

start := time.Now()
newRootCommand(ts.globalState).execute()
elapsed := time.Since(start)
assert.Greater(t, elapsed, 5*time.Second, "expected more time to have passed because of minIterationDuration")
assert.Less(
t, elapsed, 10*time.Second,
"expected less time to have passed because minIterationDuration should not affect setup() and teardown() ",
)

stdOut := ts.stdOut.String()
t.Log(stdOut)
assert.Contains(t, stdOut, "✓ test_counter.........: 3")
}
1 change: 1 addition & 0 deletions core/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ func TestMetricsEmission(t *testing.T) {
}
}

// TODO: delete, functionality duplicated in cmd/integration_test.go
func TestMinIterationDurationInSetupTeardownStage(t *testing.T) {
t.Parallel()
setupScript := `
Expand Down

0 comments on commit a67cb56

Please sign in to comment.