-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
rt := common.GetRuntime(ctx) | ||
if rt == nil { | ||
return nil, errors.New("goja runtime is nil in context") | ||
} | ||
|
||
ti := map[string]func() interface{}{ | ||
// stop the test run | ||
"abort": func() interface{} { | ||
return func(msg goja.Value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a slight issue with this approach.
This script:
import exec from 'k6/x/execution';
exec.test.abort;
export default function () {
console.log(exec.test.duration);
}
Outputs:
ERRO[0000] getting test information in the init context is not supported
at file:///tmp/test.js:6:15(7) executor=per-vu-iterations scenario=default source=stacktrace
This happens on the test.duration
access, so it seems that accessing test.abort
in init
caches the nil
*ExecutionState
. Actually calling test.abort()
or commenting out that line works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think that you should just move to getting the ctx
and rt
in each of the callbacks so it's always just get the current one. Hopefully with the new Modules this will be even cheaper and already the whole goja reflection parts are probably way more expensive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So with the rebase on #2 this is no longer an issue 🎉
I'm not sure if it's because of the ModuleV2
change or the removal of Proxy
/DynamicObject
, but I didn't want to do any additional changes, as it doesn't seem necessary to get ctx
and rt
in each function. We do need a fresh ExecutionState
though, but that was required before this update.
39b69b3
to
e231d17
Compare
This is superseded by grafana/k6#2093 and won't be merged. |
This is the JS API that exposes the core changes in grafana/k6#2093, adapted from grafana/k6#1920. The tests are slightly changed and some didn't make it (the ones for
cmd
), but they're in the history of grafana/k6#2093 so we can bring them back once this extension is moved to core.It's based on #2 so let's merge that first.