Skip to content

Commit

Permalink
Remove checking execution status via HTTP API in E2E event tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mirić committed Jun 7, 2023
1 parent c8b17b8 commit be0f530
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
48 changes: 23 additions & 25 deletions cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2012,11 +2012,10 @@ func TestEventSystemOK(t *testing.T) {
ts := NewGlobalTestState(t)

moduleName := fmt.Sprintf("k6/x/testevents-%d", atomic.AddUint64(&uniqueModuleNumber, 1))
modules.Register(moduleName, events.New(
ts.GlobalState.DefaultFlags.Address, []event.Type{
event.Init, event.TestStart, event.IterStart, event.IterEnd,
event.TestEnd, event.Exit,
}))
modules.Register(moduleName, events.New([]event.Type{
event.Init, event.TestStart, event.IterStart, event.IterEnd,
event.TestEnd, event.Exit,
}))

ts.CmdArgs = []string{"k6", "--quiet", "run", "-"}
ts.Stdin = bytes.NewBuffer([]byte(fmt.Sprintf(`
Expand All @@ -2034,19 +2033,19 @@ func TestEventSystemOK(t *testing.T) {
cmd.ExecuteWithGlobalState(ts.GlobalState)

expLog := []string{
`got event Init with data '<nil>', test status: InitVUs`,
`got event TestStart with data '<nil>', test status: Running`,
`got event IterStart with data '{Iteration:0 VUID:1 ScenarioName:default Error:<nil>}', test status: Running`,
`got event IterEnd with data '{Iteration:0 VUID:1 ScenarioName:default Error:<nil>}', test status: Running`,
`got event IterStart with data '{Iteration:1 VUID:1 ScenarioName:default Error:<nil>}', test status: Running`,
`got event IterEnd with data '{Iteration:1 VUID:1 ScenarioName:default Error:<nil>}', test status: Running`,
`got event IterStart with data '{Iteration:2 VUID:1 ScenarioName:default Error:<nil>}', test status: Running`,
`got event IterEnd with data '{Iteration:2 VUID:1 ScenarioName:default Error:<nil>}', test status: Running`,
`got event IterStart with data '{Iteration:3 VUID:1 ScenarioName:default Error:<nil>}', test status: Running`,
`got event IterEnd with data '{Iteration:3 VUID:1 ScenarioName:default Error:<nil>}', test status: Running`,
`got event IterStart with data '{Iteration:4 VUID:1 ScenarioName:default Error:<nil>}', test status: Running`,
`got event IterEnd with data '{Iteration:4 VUID:1 ScenarioName:default Error:<nil>}', test status: Ended`,
`got event TestEnd with data '<nil>', test status: Ended`,
`got event Init with data '<nil>'`,
`got event TestStart with data '<nil>'`,
`got event IterStart with data '{Iteration:0 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event IterEnd with data '{Iteration:0 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event IterStart with data '{Iteration:1 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event IterEnd with data '{Iteration:1 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event IterStart with data '{Iteration:2 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event IterEnd with data '{Iteration:2 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event IterStart with data '{Iteration:3 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event IterEnd with data '{Iteration:3 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event IterStart with data '{Iteration:4 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event IterEnd with data '{Iteration:4 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event TestEnd with data '<nil>'`,
`got event Exit with data '&{Error:<nil>}'`,
}
log := ts.LoggerHook.Lines()
Expand All @@ -2060,10 +2059,9 @@ func TestEventSystemAborted(t *testing.T) {
ts := NewGlobalTestState(t)

moduleName := fmt.Sprintf("k6/x/testevents-%d", atomic.AddUint64(&uniqueModuleNumber, 1))
modules.Register(moduleName, events.New(
ts.GlobalState.DefaultFlags.Address, []event.Type{
event.Init, event.TestStart, event.TestEnd, event.Exit,
}))
modules.Register(moduleName, events.New([]event.Type{
event.Init, event.TestStart, event.TestEnd, event.Exit,
}))

ts.CmdArgs = []string{"k6", "--quiet", "run", "-"}
ts.ExpectedExitCode = int(exitcodes.ScriptAborted)
Expand All @@ -2086,9 +2084,9 @@ func TestEventSystemAborted(t *testing.T) {
cmd.ExecuteWithGlobalState(ts.GlobalState)

expLog := []string{
`got event Init with data '<nil>', test status: InitVUs`,
`got event TestStart with data '<nil>', test status: Running`,
`got event TestEnd with data '<nil>', test status: Interrupted`,
`got event Init with data '<nil>'`,
`got event TestStart with data '<nil>'`,
`got event TestEnd with data '<nil>'`,
`got event Exit with data '&{Error:test aborted: oops! at file:///-:13:14(12)}'`,
`test aborted: oops! at file:///-:13:14(12)`,
}
Expand Down
14 changes: 2 additions & 12 deletions cmd/tests/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
package events

import (
"fmt"
"sync"

"go.k6.io/k6/api/v1/client"
"go.k6.io/k6/event"
"go.k6.io/k6/js/modules"
)
Expand All @@ -14,7 +12,6 @@ import (
// instances for each VU.
type RootModule struct {
initOnce sync.Once
apiAddress string
subscribeEvents []event.Type
}

Expand All @@ -27,10 +24,9 @@ var (
)

// New returns a pointer to a new RootModule instance.
func New(apiAddress string, subscribeEvents []event.Type) *RootModule {
func New(subscribeEvents []event.Type) *RootModule {
return &RootModule{
initOnce: sync.Once{},
apiAddress: apiAddress,
subscribeEvents: subscribeEvents,
}
}
Expand All @@ -42,19 +38,13 @@ func (rm *RootModule) NewModuleInstance(vu modules.VU) modules.Instance {
sid, evtCh := vu.Events().Subscribe(rm.subscribeEvents...)
logger := vu.InitEnv().Logger
go func() {
api, _ := client.New(rm.apiAddress)
for {
select {
case evt, ok := <-evtCh:
if !ok {
return
}
var testStatus string
if evt.Type != event.Exit {
status, _ := api.Status(vu.Context())
testStatus = fmt.Sprintf(", test status: %s", status.Status.String())
}
logger.Infof("got event %s with data '%+v'%s", evt.Type, evt.Data, testStatus)
logger.Infof("got event %s with data '%+v'", evt.Type, evt.Data)
evt.Done()
if evt.Type == event.Exit {
vu.Events().Unsubscribe(sid)
Expand Down

0 comments on commit be0f530

Please sign in to comment.