From fc29412f74e34d5e5df3457c4e796d4a4a38f058 Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Wed, 7 Aug 2024 14:21:12 +0200 Subject: [PATCH 1/6] RFC step_wait_promise --- rfcs/step_wait_promise.md | 85 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 rfcs/step_wait_promise.md diff --git a/rfcs/step_wait_promise.md b/rfcs/step_wait_promise.md new file mode 100644 index 00000000..44141780 --- /dev/null +++ b/rfcs/step_wait_promise.md @@ -0,0 +1,85 @@ +# RFC TODO: `step_wait_promise` method + +## Summary + +Add a `step_wait_promise(promise, timeout=default_timeout)` method to the wpt `Test` +object. This method waits for the given `promise` to resolve within the specified +`timeout`. If the promise is not resolved within the timeout period, it raises an +assertion error: `Timed out waiting on condition`. + +## Details + +* **`step_wait_promise(promise, description, timeout=default_timeout)`** + * `promise`: The Promise object to wait for. + * `description`: Error message to add to assert in case of failure. + * `timeout`: Timeout in ms. This is multiplied by the global + `timeout_multiplier`. Defaults to `step_wait_*` default of 3000ms. + * Behavior: + * The function waits for the given `promise` to resolve. + * If the `promise` resolves within the `timeout`, the function returns the + resolved value of the promise. + * If the `promise` does not resolve within the `timeout`, an `AssertionError` + is raised with the "Timed out waiting on condition", `description` and + stacktrace. + +## Motivation + +* Support for BiDi events: Facilitates testing scenarios involving BiDi events +in the testdriver API, where asynchronous events are expected. +* Improved efficiency compared to `step_wait`: Eliminates the need for periodic +checks with intervals, allowing the test to proceed immediately once the awaited +event occurs, potentially leading to faster test execution. Event though interval of +100ms seems to be small enough, it can still accumulate to a significant amount of +time. + +## Examples + +In [console/console-count-logging.html](https://github.com/web-platform-tests/wpt/blob/ea3f611e8d3e7debc3b9cb98b0e63254657fa7eb/console/console-count-logging.html#L33), +`log_entries_promise` is awaited without a wrapper, which in case of not having the +required events within the test timeout, the test will fail with a generic timeout +hiding the actual step and stacktrace. + +### Before: + +```javascript +// Wait for the log entries to be added. +const log_entries = await log_entries_promise; +``` + +In case of not having the required events, the test will crash with a generic +timeout error: + +``` +/console/console-count-logging.html + TIMEOUT Console count method default parameter should work - Test timed out + TIMEOUT /console/console-count-logging.html +``` + +### After + +```javascript +// Wait for the log entries to be added. +const log_entries = await test.step_wait_promise(log_entries_promise, + "Wait for the log entries to be added."); +``` + +In case of not having the required events, the test will crash with a generic +timeout error: + +``` +/console/console-count-logging.html + FAIL Console count method default parameter should work - step_wait_promise: Wait for the log entries to be added. Timed out waiting on condition + at async Test. (http://web-platform.test:8000/console/console-count-logging.html:33:29) +``` + + +## Risks + +* Adding API surface: Increases the complexity of the testing framework and requires +ongoing maintenance. + +## Considerations + +* The implementation should respect the "timeout multiplier" setting to ensure +consistency with other timeout-related behaviors in the testing framework and to work +correctly in the presence of slow or overloaded systems. From b9d6be80ae7edeab71f54809f3cd22faed82ebd8 Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Wed, 7 Aug 2024 14:24:01 +0200 Subject: [PATCH 2/6] update RFC number --- rfcs/step_wait_promise.md | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/rfcs/step_wait_promise.md b/rfcs/step_wait_promise.md index 44141780..17e6c0f4 100644 --- a/rfcs/step_wait_promise.md +++ b/rfcs/step_wait_promise.md @@ -1,9 +1,9 @@ -# RFC TODO: `step_wait_promise` method +# RFC 207: `step_wait_promise` method ## Summary Add a `step_wait_promise(promise, timeout=default_timeout)` method to the wpt `Test` -object. This method waits for the given `promise` to resolve within the specified +object. This method waits for the given `promise` to resolve within the specified `timeout`. If the promise is not resolved within the timeout period, it raises an assertion error: `Timed out waiting on condition`. @@ -13,30 +13,31 @@ assertion error: `Timed out waiting on condition`. * `promise`: The Promise object to wait for. * `description`: Error message to add to assert in case of failure. * `timeout`: Timeout in ms. This is multiplied by the global - `timeout_multiplier`. Defaults to `step_wait_*` default of 3000ms. + `timeout_multiplier`. Defaults to `step_wait_*` default of 3000ms. * Behavior: * The function waits for the given `promise` to resolve. * If the `promise` resolves within the `timeout`, the function returns the - resolved value of the promise. + resolved value of the promise. * If the `promise` does not resolve within the `timeout`, an `AssertionError` - is raised with the "Timed out waiting on condition", `description` and - stacktrace. + is raised with the "Timed out waiting on condition", `description` and + stacktrace. ## Motivation * Support for BiDi events: Facilitates testing scenarios involving BiDi events -in the testdriver API, where asynchronous events are expected. + in the testdriver API, where asynchronous events are expected. * Improved efficiency compared to `step_wait`: Eliminates the need for periodic -checks with intervals, allowing the test to proceed immediately once the awaited -event occurs, potentially leading to faster test execution. Event though interval of -100ms seems to be small enough, it can still accumulate to a significant amount of -time. + checks with intervals, allowing the test to proceed immediately once the awaited + event occurs, potentially leading to faster test execution. Event though interval + of + 100ms seems to be small enough, it can still accumulate to a significant amount of + time. ## Examples In [console/console-count-logging.html](https://github.com/web-platform-tests/wpt/blob/ea3f611e8d3e7debc3b9cb98b0e63254657fa7eb/console/console-count-logging.html#L33), `log_entries_promise` is awaited without a wrapper, which in case of not having the -required events within the test timeout, the test will fail with a generic timeout +required events within the test timeout, the test will fail with a generic timeout hiding the actual step and stacktrace. ### Before: @@ -72,14 +73,14 @@ timeout error: at async Test. (http://web-platform.test:8000/console/console-count-logging.html:33:29) ``` - ## Risks * Adding API surface: Increases the complexity of the testing framework and requires -ongoing maintenance. + ongoing maintenance. ## Considerations * The implementation should respect the "timeout multiplier" setting to ensure -consistency with other timeout-related behaviors in the testing framework and to work -correctly in the presence of slow or overloaded systems. + consistency with other timeout-related behaviors in the testing framework and to + work + correctly in the presence of slow or overloaded systems. From 85b235aab3dcb295b17ced9eccabf6445d7b811a Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Wed, 7 Aug 2024 14:26:05 +0200 Subject: [PATCH 3/6] add description --- rfcs/step_wait_promise.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rfcs/step_wait_promise.md b/rfcs/step_wait_promise.md index 17e6c0f4..f50c1491 100644 --- a/rfcs/step_wait_promise.md +++ b/rfcs/step_wait_promise.md @@ -2,10 +2,10 @@ ## Summary -Add a `step_wait_promise(promise, timeout=default_timeout)` method to the wpt `Test` -object. This method waits for the given `promise` to resolve within the specified -`timeout`. If the promise is not resolved within the timeout period, it raises an -assertion error: `Timed out waiting on condition`. +Add a `step_wait_promise(promise, description, timeout=default_timeout)` method to +the wpt `Test` object. This method waits for the given `promise` to resolve within +the specified `timeout`. If the promise is not resolved within the timeout period, it +raises an assertion error: `Timed out waiting on condition`. ## Details From 66be6c79a40f875fb48b25ba6b1345b22141bb88 Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Wed, 14 Aug 2024 14:44:18 +0200 Subject: [PATCH 4/6] describe promise rejection --- rfcs/step_wait_promise.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rfcs/step_wait_promise.md b/rfcs/step_wait_promise.md index f50c1491..bdcd305f 100644 --- a/rfcs/step_wait_promise.md +++ b/rfcs/step_wait_promise.md @@ -18,6 +18,8 @@ raises an assertion error: `Timed out waiting on condition`. * The function waits for the given `promise` to resolve. * If the `promise` resolves within the `timeout`, the function returns the resolved value of the promise. + * If the `promise` is rejected within the `timeout`, an `AssertionError` is + raised with the rejection reason, `description` and stacktrace. * If the `promise` does not resolve within the `timeout`, an `AssertionError` is raised with the "Timed out waiting on condition", `description` and stacktrace. From 681026904803967b14610b7034ca5f9dbc8570a6 Mon Sep 17 00:00:00 2001 From: Maksim Sadym <69349599+sadym-chromium@users.noreply.github.com> Date: Thu, 15 Aug 2024 09:18:05 +0200 Subject: [PATCH 5/6] Update rfcs/step_wait_promise.md Co-authored-by: Sam Sneddon --- rfcs/step_wait_promise.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rfcs/step_wait_promise.md b/rfcs/step_wait_promise.md index bdcd305f..bcbd1fec 100644 --- a/rfcs/step_wait_promise.md +++ b/rfcs/step_wait_promise.md @@ -30,7 +30,7 @@ raises an assertion error: `Timed out waiting on condition`. in the testdriver API, where asynchronous events are expected. * Improved efficiency compared to `step_wait`: Eliminates the need for periodic checks with intervals, allowing the test to proceed immediately once the awaited - event occurs, potentially leading to faster test execution. Event though interval + event occurs, potentially leading to faster test execution. Even though interval of 100ms seems to be small enough, it can still accumulate to a significant amount of time. From 1a3c18beb9cb15bcd942920cd54ba9f14ab6216b Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Thu, 15 Aug 2024 09:20:39 +0200 Subject: [PATCH 6/6] lines --- rfcs/step_wait_promise.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rfcs/step_wait_promise.md b/rfcs/step_wait_promise.md index bcbd1fec..29fd6c9e 100644 --- a/rfcs/step_wait_promise.md +++ b/rfcs/step_wait_promise.md @@ -31,9 +31,8 @@ raises an assertion error: `Timed out waiting on condition`. * Improved efficiency compared to `step_wait`: Eliminates the need for periodic checks with intervals, allowing the test to proceed immediately once the awaited event occurs, potentially leading to faster test execution. Even though interval - of - 100ms seems to be small enough, it can still accumulate to a significant amount of - time. + of 100ms seems to be small enough, it can still accumulate to a significant amount + of time. ## Examples