Skip to content

Commit

Permalink
Enhance some integration tests to make 2 Engine tests redundant
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- committed Dec 4, 2022
1 parent a67cb56 commit 690fbbb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
37 changes: 27 additions & 10 deletions cmd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,19 +730,29 @@ func TestAbortedByUserWithRestAPI(t *testing.T) {

func TestAbortedByScriptSetupError(t *testing.T) {
t.Parallel()
script := []byte(`
depScript := []byte(`
export default function () {
baz();
}
function baz() {
throw new Error("baz");
}
`)
mainScript := []byte(`
import bar from "./bar.js";
export function setup() {
console.log('wonky setup');
throw new Error('foo');
}
export default function () {};
bar();
};
export default function() {};
`)

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

ts := newGlobalTestState(t)
require.NoError(t, afero.WriteFile(ts.fs, filepath.Join(ts.cwd, "test.js"), script, 0o644))
require.NoError(t, afero.WriteFile(ts.fs, filepath.Join(ts.cwd, "test.js"), mainScript, 0o644))
require.NoError(t, afero.WriteFile(ts.fs, filepath.Join(ts.cwd, "bar.js"), depScript, 0o644))

ts.envVars = map[string]string{"K6_CLOUD_HOST": srv.URL}
ts.args = []string{"k6", "run", "-v", "--out", "cloud", "--log-output=stdout", "test.js"}
ts.expectedExitCode = int(exitcodes.ScriptException)
Expand All @@ -759,7 +769,13 @@ func TestAbortedByScriptSetupError(t *testing.T) {

t.Log(stdOut)
assert.Contains(t, stdOut, `wonky setup`)
assert.Contains(t, stdOut, `Error: foo`)

rootPath := "file:///"
if runtime.GOOS == "windows" {
rootPath += "c:/"
}
assert.Contains(t, stdOut, `level=error msg="Error: baz\n\tat baz (`+rootPath+`test/bar.js:6:9(3))\n\tat `+
rootPath+`test/bar.js:3:3(3)\n\tat setup (`+rootPath+`test/test.js:5:3(9))\n\tat native\n" hint="script exception"`)
assert.Contains(t, stdOut, `level=debug msg="Sending test finished" output=cloud ref=111 run_status=7 tainted=false`)
}

Expand Down Expand Up @@ -796,8 +812,8 @@ func TestAbortedByScriptInitError(t *testing.T) {
iterations: 10,
};
if (__VU > 3) {
throw new Error('foo');
if (__VU == 2) {
throw new Error('oops in ' + __VU);
}
export default function () {};
Expand All @@ -822,7 +838,8 @@ func TestAbortedByScriptInitError(t *testing.T) {
ts.outMutex.Unlock()

t.Log(stdOut)
assert.Contains(t, stdOut, `Error: foo`)
assert.Contains(t, stdOut, `level=error msg="Error: oops in 2\n\tat file:///`)
assert.Contains(t, stdOut, `hint="error while initializing VU #2 (script exception)"`)
assert.Contains(t, stdOut, `level=debug msg="Sending test finished" output=cloud ref=111 run_status=7 tainted=false`)
}

Expand Down
2 changes: 2 additions & 0 deletions core/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ func TestRunTags(t *testing.T) {
}
}

// TODO: delete, functionality duplicated in cmd/integration_test.go
func TestSetupException(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -892,6 +893,7 @@ func TestSetupException(t *testing.T) {
}
}

// TODO: delete, functionality duplicated in cmd/integration_test.go
func TestVuInitException(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 690fbbb

Please sign in to comment.