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

Move taskqueue to mapping layer #1069

Merged
merged 17 commits into from
Oct 23, 2023
Merged

Move taskqueue to mapping layer #1069

merged 17 commits into from
Oct 23, 2023

Commits on Oct 23, 2023

  1. Move TaskQueue to mapping layer

    Removes the goja TaskQueue from the page implementation and instead
    places it in the mapping layer by wrapping the handler in a function
    that will execute it in the local TaskQueue.
    ka3de authored and ankur22 committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    c89a240 View commit details
    Browse the repository at this point in the history
  2. Modify consoleEventHandlerFunc to not return error

    It's no longer required to return an error from the handler, as this is
    handled in the TaskQueue wrapper in the mapping layer.
    
    This change also refactors the test so that:
    1. it no longer returns an error from the handler;
    2. the event loop has been removed since the taskqueue has been removed
       from the business logic, making the test simpler to understand with
       less orchestration.
    ka3de authored and ankur22 committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    24fab41 View commit details
    Browse the repository at this point in the history
  3. Move TaskQueue to moduleVU scope

    With this change we only use the TaskQueue from the main thread, as it's
    required to avoid race conditions with goja. Unfortunately this implies
    an explicit close call for the TaskQueue that we are wrapping in the
    page.close() call in the mapping layer.
    ka3de authored and ankur22 committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    7a3f047 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    8f2bc52 View commit details
    Browse the repository at this point in the history
  5. Refactor taskqueue for waitForEvent

    To enable us to work with the task queue outside of the business logic
    and allow the setup of the predicate function within the task queue
    we need to:
    1. Parse the options in the mapping layer.
    2. Create a func that can call the predicate function from within a
       taskqueue.
    3. We need to wait for the taskqueue call to complete and return the
       response back to the caller.
    4. Change the browserContext API within the go code.
    ankur22 committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    f7bddc2 View commit details
    Browse the repository at this point in the history
  6. Refactor browserContext.waitForEvent tests

    This refactors the tests so that it matches the new signature for
    waitForEvent, which is that it takes in a predicate method and a
    timeout.
    
    The predicate method will now be wrapped and added to a taskqueue in
    the mapping layer which means we do not need to work with the event
    loop in the test itself.
    
    Since the options are now parsed in the mapping layer, this also
    simplifies how we pass the predicate and timeout arguments to
    waitForEvent.
    ankur22 committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    8bf40ed View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    646b45b View commit details
    Browse the repository at this point in the history
  8. Refactor internal waitForEvent method

    This is just cleaning up the arguments so that they are grouped in a
    better way, as well as shortening the line length to avoid the linter
    issue.
    ankur22 committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    caf9ad4 View commit details
    Browse the repository at this point in the history
  9. Add thread safety to the taskqueue

    Since waitForEvent is a promisified function, we need to make the
    taskqueue thread safe.
    ankur22 committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    9180b7b View commit details
    Browse the repository at this point in the history
  10. Fix taskqueue so it is per page

    The taskqueue wasn't working when it was one per vu since it became
    difficult to understand exactly when it was best to close the taskqueue
    if there were multiple pages.
    
    This change now creates a taskqueue per page, but the taskqueues is
    stored in the vu rather than in the page struct itself, which helps
    ensure that the taskqueue is kept away from the page business logic.
    ankur22 committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    fffd720 View commit details
    Browse the repository at this point in the history
  11. Add a taskqueue registry

    This will be used to register, retrieve and close the taskqueues which
    is required by the page.on and browserContext.waitForEvent APIs.
    ankur22 committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    90a2125 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    a8901f5 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    ba1f3e8 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    82a6544 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    08b9c00 View commit details
    Browse the repository at this point in the history
  16. Fix assertion in goroutine

    Since a require.True will FailNow in the current goroutine and not the
    root goroutine of the test, it's best to pass an error back to assert
    on in the test's root goroutine.
    ankur22 committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    1af173f View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    468d84c View commit details
    Browse the repository at this point in the history