-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2093 from grafana/feat/1001-abort-test
Add JS function to abort test
- Loading branch information
Showing
18 changed files
with
377 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import exec from 'k6/execution'; | ||
|
||
export default function () { | ||
exec.test.abort(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import exec from 'k6/execution'; | ||
exec.test.abort(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import exec from 'k6/execution'; | ||
|
||
// This won't fail on initial parsing of the script, but on VU initialization. | ||
if (__VU == 1) { | ||
exec.test.abort(); | ||
} | ||
|
||
export default function() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import exec from 'k6/execution'; | ||
|
||
export default function () { | ||
exec.test.abort(); | ||
} | ||
|
||
export function teardown() { | ||
console.log('Calling teardown function after test.abort()'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
someUndefinedVar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2021 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/dop251/goja" | ||
"go.k6.io/k6/errext" | ||
"go.k6.io/k6/errext/exitcodes" | ||
) | ||
|
||
// InterruptError is an error that halts engine execution | ||
type InterruptError struct { | ||
Reason string | ||
} | ||
|
||
var _ errext.HasExitCode = &InterruptError{} | ||
|
||
// Error returns the reason of the interruption. | ||
func (i *InterruptError) Error() string { | ||
return i.Reason | ||
} | ||
|
||
// ExitCode returns the status code used when the k6 process exits. | ||
func (i *InterruptError) ExitCode() errext.ExitCode { | ||
return exitcodes.ScriptAborted | ||
} | ||
|
||
// AbortTest is the reason emitted when a test script calls test.abort() | ||
const AbortTest = "test aborted" | ||
|
||
// IsInterruptError returns true if err is *InterruptError. | ||
func IsInterruptError(err error) bool { | ||
if err == nil { | ||
return false | ||
} | ||
var intErr *InterruptError | ||
return errors.As(err, &intErr) | ||
} | ||
|
||
// UnwrapGojaInterruptedError returns the internal error handled by goja. | ||
func UnwrapGojaInterruptedError(err error) error { | ||
var gojaErr *goja.InterruptedError | ||
if errors.As(err, &gojaErr) { | ||
if e, ok := gojaErr.Value().(error); ok { | ||
return e | ||
} | ||
} | ||
return err | ||
} |
Oops, something went wrong.