Skip to content

Conversation

ankur22
Copy link
Contributor

@ankur22 ankur22 commented Aug 13, 2025

What?

This PR aims to tidy up the tests and add new ones where necessary including a refactor in the implementation for waitForURL:

  1. Refactor to work with parseStringOrRegex in waitForURL;
  2. Refactor tests so that they're easier to maintain and fix when/if they fail;
  3. Refactor tests so that they're not flakey;
  4. Add waitForURL tests to frame.

Why?

Refactors based on comments made in this PR: #4920

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

#4920

@ankur22 ankur22 added this to the v1.3.0 milestone Aug 13, 2025
@ankur22 ankur22 force-pushed the add/refactor-waitForURL-tests branch 2 times, most recently from 5b13e80 to 38d26a8 Compare August 18, 2025 09:16
@ankur22 ankur22 marked this pull request as ready for review August 18, 2025 10:36
@ankur22 ankur22 requested a review from a team as a code owner August 18, 2025 10:36
@ankur22 ankur22 requested review from codebien and oleiade and removed request for a team August 18, 2025 10:36
`)
require.NoError(t, err)

// Test when already at matching URL (should just wait for load state)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make this into a table test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to have it

Copy link
Contributor Author

@ankur22 ankur22 Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a3cf2b0 db6537e

@ankur22 ankur22 force-pushed the add/refactor-waitForURL-tests branch 4 times, most recently from e4a7e29 to db6537e Compare August 26, 2025 14:01
assert.False(t, checked)
}

//nolint:tparallel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unexpected. Do we really need? Can't we mitigate it? How can we guarantee that we are not hiding a race condition here?

If this is needed, then the comment should document The Why.

Copy link
Contributor Author

@ankur22 ankur22 Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here's my motivation for doing it:

  1. Parallelising browser integration tests i think is quite expensive due to them needing their own chrome instance. So i personally think we should possibly reconsider this approach with browser tests, mainly in CI. I don't have numbers though, so i can't tell you whether it's a good assumption.
  2. I've started to prefer trying to perform a single setup function at the top, with only the important test logic in the test block in for _, tt := range tests.

Since we've not discussed this before i'll change it to working with parallel tests for now.

Done in 58fcc25

Copy link
Contributor

@codebien codebien Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I have the feeling the problem is quite complex and we should open an issue identifying the problem. I see various possible ways for addressing it. For example, did we consider to have a pool of browsers to use? It would automatically rate limit the parallelism.
However, any assumption if not supported by data could be difficult to justify.

I don't have numbers though, so i can't tell you whether it's a good assumption.

So this sounds a requirement if we want to optimize in any direction.

However, if the decision is to stop the parallelism then I'd prefer if we add a condition for the entire package. So we don't have to add it for each test.

@ankur22 ankur22 force-pushed the add/refactor-waitForURL-tests branch 3 times, most recently from 1cf6276 to 58fcc25 Compare August 29, 2025 11:12
@ankur22 ankur22 requested a review from codebien August 29, 2025 11:53
The implementation of waitForURL and url option on waitForNavigation
no longer require the need to call page.close. The taskqueue is closed
when the methods resolve/reject.
Each sub test is separated into it's own async run function so that we
can easily debug issues with tests.
@ankur22 ankur22 force-pushed the add/refactor-waitForURL-tests branch from 58fcc25 to b8a0870 Compare September 4, 2025 14:11
@ankur22 ankur22 removed the request for review from oleiade September 5, 2025 12:00
@ankur22 ankur22 requested a review from mstoykov September 5, 2025 12:00
@ankur22 ankur22 merged commit 3dd1f71 into master Sep 5, 2025
36 of 37 checks passed
@ankur22 ankur22 deleted the add/refactor-waitForURL-tests branch September 5, 2025 14:20
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

Successfully merging this pull request may close these issues.

3 participants