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

Enable multiple k6-browser instances to run concurrent tests against a single browser #848

Merged
merged 17 commits into from
Apr 6, 2023

Commits on Apr 5, 2023

  1. Configuration menu
    Copy the full SHA
    2377503 View commit details
    Browse the repository at this point in the history
  2. Add session.Close

    This makes it easy to check if a session is closed from a non-select
    statement, like a switch or if.
    inancgumus committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    c348332 View commit details
    Browse the repository at this point in the history
  3. Fix panic: GoError: creating a new page: canceled

    When we run multi-VU/instance tests, one of the test runs can close a
    page of its own. Since each test run attaches to all the browser pages
    (this is another area we might want to discuss), this sometimes
    creates a race between the test runs. This check allows the test run
    to continue instead of panicking because of another test run's page
    detachments.
    
    This fix allows running the k6 browser in high concurrency with
    multiple VUs and instances. Note that it is still possible to get
    errors since we need to correctly handle the CDP messages while
    sending and receiving them (the order of them). This can cause
    timeout and other sorts of errors.
    
    Explanation:
    There are two instances and different sessions. However, both
    instances attach/detach from the same pages since we run in the same browser.
    
    instance1 ---> newPage                    page1
      attaches to: page1
    instance2
      attaches to: page1
    instance2 ---> newPage                    page1, page2
      attaches to: page2
    instance1
      attaches to: page2
    instance1 --> page1.Close()               page2
    instance1 <-- detachedFromTarget(page1)
      closes page1 session.
    
    This is the racy part that this PR fixes:
    
    instance2 <-- detachedFromTarget(page1)
      closes page1 session.
    instance2 ---> attachToTarget(page1)
      panic: session does not exist.
    
    instance2 panics while trying to send CDP messages to a closed web socket
    connection since it detaches from it and tries to attach to it
    concurrently.
    inancgumus committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    8b919fd View commit details
    Browse the repository at this point in the history
  4. Add testBrowser.browserType field

    This is for connecting to an existing browser over a WebSocket URL.
    inancgumus committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    1bef29e View commit details
    Browse the repository at this point in the history
  5. Add TestMultiConnectToSingleBrowser

    This will panic if the fix in this PR did not get applied. Since the
    panic occurs in a different routine, we can't catch the panic, and leave
    this test as naked (without using require.Panics).
    inancgumus committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    47567fc View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    1a167e7 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    d649616 View commit details
    Browse the repository at this point in the history
  8. Simplify var declaration in onAttachedToTarget

    Also move the log to top.
    inancgumus committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    ed2a3d2 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    34a0be1 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    3f43f23 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    abe212d View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    3a3c000 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    b5b5204 View commit details
    Browse the repository at this point in the history
  14. Add Browser.attachNewPage

    inancgumus committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    5b2ae23 View commit details
    Browse the repository at this point in the history
  15. Refactor to attachNewPage

    inancgumus committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    1b2a2fc View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    406d2c6 View commit details
    Browse the repository at this point in the history

Commits on Apr 6, 2023

  1. Fix log categories in page attachment

    Also move one logging out of locking.
    
    Co-authored-by: ankur22 <ankur.agarwal@grafana.com>
    inancgumus and ankur22 committed Apr 6, 2023
    Configuration menu
    Copy the full SHA
    745cf54 View commit details
    Browse the repository at this point in the history