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

Remove unneeded awaits for events from input actions #17378

Closed

Conversation

lutien
Copy link

@lutien lutien commented Dec 5, 2023

This logic is problematic to run with WebDriver BiDi, because if we don't await on the script evaluation, we have no guarantee that the script was fully run before the code goes to the next step. In this case, for example, the event listener is set up after the input actions are triggered, so the event is never caught and promise is never resolved.
It looks like it's not really needed here, neither for WebDriver BiDi nor for CDP.

@whimboo
Copy link
Contributor

whimboo commented Dec 5, 2023

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @whimboo received. Current queue size: 0

Live output at: http://54.241.84.105:8877/52f0be53907afd9/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @whimboo received. Current queue size: 0

Live output at: http://54.193.163.58:8877/e80614651e4316e/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/52f0be53907afd9/output.txt

Total script time: 23.89 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 13
  different first/second rendering: 1

Image differences available at: http://54.241.84.105:8877/52f0be53907afd9/reftest-analyzer.html#web=eq.log

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/e80614651e4316e/output.txt

Total script time: 34.68 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 19

Image differences available at: http://54.193.163.58:8877/e80614651e4316e/reftest-analyzer.html#web=eq.log

@calixteman
Copy link
Contributor

We use a similar pattern at different places in the tests for example:

const waitForPointerUp = page =>

const promise = waitForPointerUp(page);
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x + 50, y + 50);
await page.mouse.up();
await promise;

@whimboo
Copy link
Contributor

whimboo commented Dec 5, 2023

We use a similar pattern at different places in the tests for example:

const waitForPointerUp = page =>

const promise = waitForPointerUp(page);
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x + 50, y + 50);
await page.mouse.up();
await promise;

Yes, we wanted to get these tests running in CI first for this particular case with CDP to see if that makes a difference. While this is fine other tests are failing. Not sure if that is a known issue with reference images or not?

Also please note that when I checked the puppeteer unit tests none of the input tests actually checked for events, so whenever such a related command has been awaited for we probably can assume that the event has been dispatched on the page. CC @OrKoN for proper feedback from the Puppeteer team.

@calixteman
Copy link
Contributor

Yes, we wanted to get these tests running in CI first for this particular case with CDP to see if that makes a difference. While this is fine other tests are failing. Not sure if that is a known issue with reference images or not?

Yes, those failures in ref tests are known (due to small invisible pixel differences because of antialiasing most of the time).

@OrKoN
Copy link

OrKoN commented Dec 5, 2023

This logic is problematic to run with WebDriver BiDi, because if we don't await on the script evaluation, we have no guarantee that the script was fully run before the code goes to the next step. In this case, for example, the event listener is set up after the input actions are triggered, so the event is never caught and promise is never resolved.
It looks like it's not really needed here, neither for WebDriver BiDi nor for CDP.

I wonder if we should address this in the BiDi spec. The pattern is relatively common in CDP/Puppeteer and I know that it used often in tests. In Chrome, the script is guaranteed to run first because both commands run on the page's main thread eventually. Is it not the case for Firefox?

@OrKoN
Copy link

OrKoN commented Dec 5, 2023

I am not sure that those awaits are completely unnecessary since they allow verifying that the even has been dispatched on an expected element which allows failing the test earlier.

@OrKoN
Copy link

OrKoN commented Dec 6, 2023

So to correct myself above: the dispatch of the evaluate was happening synchronously at some point but it has regressed. I'd recommend using the following pattern which would be more reliable:

          using promise = await page.evaluateHandle(
            () =>
              [new Promise(resolve => {
                document.addEventListener("selectionchange", resolve, {
                  once: true,
                });
              })]
          );
          await page.click("#pageNumber");
          await promise.evaluate(promise => promise[0]);

calixteman added a commit to calixteman/pdf.js that referenced this pull request Dec 6, 2023
calixteman added a commit to calixteman/pdf.js that referenced this pull request Dec 6, 2023
calixteman added a commit to calixteman/pdf.js that referenced this pull request Dec 6, 2023
@calixteman
Copy link
Contributor

@whimboo, @lutien, I made this PR:
#17387
so I guess this one is useless now.

@lutien lutien closed this Dec 6, 2023
calixteman added a commit to calixteman/pdf.js that referenced this pull request Dec 6, 2023
calixteman added a commit to calixteman/pdf.js that referenced this pull request Dec 7, 2023
calixteman added a commit to calixteman/pdf.js that referenced this pull request Dec 7, 2023
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.

5 participants