Skip to content

Handle non-exising entries for some metrics #29

@nadiamoe

Description

@nadiamoe

I encountered the following panic:

ERRO[0031] unexpected k6 panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:24 +0x5e
go.k6.io/k6/cmd.(*rootCommand).execute.func2()
	go.k6.io/k6@v0.55.0/cmd/root.go:100 +0x67
panic({0x1af4c00?, 0xc000a120c0?})
	runtime/panic.go:770 +0x132
sm.targetMetricsCollection.Write(0x2f41400?, {0x1f75640, 0xc000148468})
	sm@v0.0.0-00010101000000-000000000000/output.go:388 +0x1246
sm.(*Output).Stop(0xc0005cb3e0)
	sm@v0.0.0-00010101000000-000000000000/output.go:178 +0x432
go.k6.io/k6/output.(*Manager).stopOutputs(0xc000429200, {0x0, 0x0}, 0x3)
	go.k6.io/k6@v0.55.0/output/manager.go:112 +0x143
go.k6.io/k6/output.(*Manager).Start.func3({0x0, 0x0})
	go.k6.io/k6@v0.55.0/output/manager.go:80 +0x45
go.k6.io/k6/cmd.(*cmdRun).run.func9()
	go.k6.io/k6@v0.55.0/cmd/run.go:238 +0x8a
go.k6.io/k6/cmd.(*cmdRun).run(0xc00012e5d0, 0xc0002de2c8, {0xc00034bc20, 0x1, 0x3})
	go.k6.io/k6@v0.55.0/cmd/run.go:434 +0x184b
github.com/spf13/cobra.(*Command).execute(0xc0002de2c8, {0xc00034bbf0, 0x3, 0x3})
	github.com/spf13/cobra@v1.4.0/command.go:856 +0x69d
github.com/spf13/cobra.(*Command).ExecuteC(0xc000163348)
	github.com/spf13/cobra@v1.4.0/command.go:974 +0x38d
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.4.0/command.go:902
go.k6.io/k6/cmd.(*rootCommand).execute(0xc0000d1620)
	go.k6.io/k6@v0.55.0/cmd/root.go:108 +0x125
go.k6.io/k6/cmd.Execute()
	go.k6.io/k6@v0.55.0/cmd/root.go:130 +0x2f
main.main()
	k6/main.go:12 +0xf

Which seems to stem from this unchecked slice indexing:

out.Value(ti.status[0])

We should revisit these assumptions and if-guard them if needed.

import { browser } from 'k6/browser';
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
  thresholds: {
    checks: ['rate==1.0'],
  },
};

export default async function () {
  const context = await browser.newContext();
  const page = await context.newPage();

  try {
    await page.goto("https://www.amazon.es");

    await page.locator('input[name="login"]').type("admin");
    await page.locator('input[name="password"]').type("123");

    await Promise.all([
      page.waitForNavigation(),
      page.locator('input[type="submit"]').click(),
    ]);

    await check(page.locator("h2"), {
      'header': async h2 => await h2.textContent() == "Welcome, admin!"
    });
  } finally {
    await page.close();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions