Skip to content

Commit

Permalink
k6.fail() implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Emily Ekberg committed May 8, 2017
1 parent f750c4c commit 8778341
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions js/modules/k6/k6.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ import (
"github.com/loadimpact/k6/js/common"
"github.com/loadimpact/k6/lib/metrics"
"github.com/loadimpact/k6/stats"
"github.com/pkg/errors"
)

type K6 struct{}

func (*K6) Fail(msg string) (goja.Value, error) {
return goja.Undefined(), errors.New(msg)
}

func (*K6) Sleep(ctx context.Context, secs float64) {
timer := time.NewTimer(time.Duration(secs * float64(time.Second)))
select {
Expand Down
7 changes: 7 additions & 0 deletions js/modules/k6/k6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ import (
"github.com/stretchr/testify/assert"
)

func TestFail(t *testing.T) {
rt := goja.New()
rt.Set("k6", common.Bind(rt, &K6{}, nil))
_, err := common.RunString(rt, `k6.fail("blah")`)
assert.EqualError(t, err, "GoError: blah")
}

func TestSleep(t *testing.T) {
rt := goja.New()
ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 8778341

Please sign in to comment.