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

browser.timeout option incorrectly applies as the global test timeout #865

Closed
ka3de opened this issue May 2, 2023 · 0 comments · Fixed by #866
Closed

browser.timeout option incorrectly applies as the global test timeout #865

ka3de opened this issue May 2, 2023 · 0 comments · Fixed by #866
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ka3de
Copy link
Collaborator

ka3de commented May 2, 2023

Brief summary

Currently (v0.9.0 commit 480c0c1) the BrowserType.Launch method accepts a timeout option which is defined in the documentation as:

timeout | string | '30s' | Default timeout to use for various actions and navigation.

But in practice this timeout also behaves as the total test timeout. This is because during the browser initialization process, in BrowserType.allocate here, a new context with timeout is created, based on the browser.options.timeout. Eventually, this context is passed into the browser process "execution command" here, which in practice will kill the process once the context is Done, which will happen after the set timeout elapses.

This context is also misused when passed into BrowserProcess.handleClose here during browser process initialization. In this case the BrowserProces.cancel() action does not finish the test, but is still a misleading action based on this context timeout.

xk6-browser version

v0.9.0

OS

Ubuntu 20.04.5 LTS

Chrome version

109.0.5414.119 (Official Build) (64-bit)

Docker version and image (if applicable)

No response

Steps to reproduce the problem

Execute the following tests:

import { chromium } from 'k6/experimental/browser';
import { sleep } from 'k6';

export default async function() {
  const browser = chromium.launch({
    headless: true,
    timeout: 2000,
  });
  const context = browser.newContext();
  const page = context.newPage();

  try {
    sleep(3);
  } finally {
    page.close();
    browser.close();
  }
}
import { chromium } from 'k6/experimental/browser';
import { sleep } from 'k6';

export default async function() {
  const browser = chromium.launch({
    headless: true,
    // No timeout set defaults to 30s
  });
  const context = browser.newContext();
  const page = context.newPage();

  try {
    sleep(31);
  } finally {
    page.close();
    browser.close();
  }
}

Expected behaviour

The test finishes correctly after ~3s and ~31s respectively.

Actual behaviour

The test finishes with error messages:

ERRO[0004] communicating with browser: websocket: close 1006 (abnormal closure): unexpected EOF  category=cdp elapsed="0 ms" goroutine=101
ERRO[0004] process with PID 15009 unexpectedly ended: signal: killed  category=browser elapsed="5 ms" goroutine=95
ERRO[0005] Uncaught (in promise) GoError: internal error while removing binding from page: websocket: close 1006 (abnormal closure): unexpected EOF
running at github.com/grafana/xk6-browser/api.Page.Close-fm (native)
default at file:///<path/to/script>/script.js:22:4(29)  executor=per-vu-iterations scenario=default

due to the process being killed "by force" when browser timeout finishes.

@ka3de ka3de added the bug Something isn't working label May 2, 2023
@ka3de ka3de added this to the v0.10.0 milestone May 2, 2023
@ka3de ka3de self-assigned this May 2, 2023
@ka3de ka3de closed this as completed in #866 May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant