Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non-exising entries for some metrics #29

Open
nadiamoe opened this issue Dec 17, 2024 · 1 comment
Open

Handle non-exising entries for some metrics #29

nadiamoe opened this issue Dec 17, 2024 · 1 comment

Comments

@nadiamoe
Copy link
Member

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/[email protected]/cmd/root.go:100 +0x67
panic({0x1af4c00?, 0xc000a120c0?})
	runtime/panic.go:770 +0x132
sm.targetMetricsCollection.Write(0x2f41400?, {0x1f75640, 0xc000148468})
	[email protected]/output.go:388 +0x1246
sm.(*Output).Stop(0xc0005cb3e0)
	[email protected]/output.go:178 +0x432
go.k6.io/k6/output.(*Manager).stopOutputs(0xc000429200, {0x0, 0x0}, 0x3)
	go.k6.io/[email protected]/output/manager.go:112 +0x143
go.k6.io/k6/output.(*Manager).Start.func3({0x0, 0x0})
	go.k6.io/[email protected]/output/manager.go:80 +0x45
go.k6.io/k6/cmd.(*cmdRun).run.func9()
	go.k6.io/[email protected]/cmd/run.go:238 +0x8a
go.k6.io/k6/cmd.(*cmdRun).run(0xc00012e5d0, 0xc0002de2c8, {0xc00034bc20, 0x1, 0x3})
	go.k6.io/[email protected]/cmd/run.go:434 +0x184b
github.com/spf13/cobra.(*Command).execute(0xc0002de2c8, {0xc00034bbf0, 0x3, 0x3})
	github.com/spf13/[email protected]/command.go:856 +0x69d
github.com/spf13/cobra.(*Command).ExecuteC(0xc000163348)
	github.com/spf13/[email protected]/command.go:974 +0x38d
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:902
go.k6.io/k6/cmd.(*rootCommand).execute(0xc0000d1620)
	go.k6.io/[email protected]/cmd/root.go:108 +0x125
go.k6.io/k6/cmd.Execute()
	go.k6.io/[email protected]/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();
  }
}
@nadiamoe
Copy link
Member Author

nadiamoe commented Dec 17, 2024

This seems to be exactly what #3 addresses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant