From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../src/unittests/async_expectations.spec.ts | 168 +++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 dom/webgpu/tests/cts/checkout/src/unittests/async_expectations.spec.ts (limited to 'dom/webgpu/tests/cts/checkout/src/unittests/async_expectations.spec.ts') diff --git a/dom/webgpu/tests/cts/checkout/src/unittests/async_expectations.spec.ts b/dom/webgpu/tests/cts/checkout/src/unittests/async_expectations.spec.ts new file mode 100644 index 0000000000..2d62978b8f --- /dev/null +++ b/dom/webgpu/tests/cts/checkout/src/unittests/async_expectations.spec.ts @@ -0,0 +1,168 @@ +/* eslint-disable @typescript-eslint/require-await */ +export const description = ` +Tests for eventualAsyncExpectation and immediateAsyncExpectation. +`; + +import { makeTestGroup } from '../common/framework/test_group.js'; +import { makeTestGroupForUnitTesting } from '../common/internal/test_group.js'; +import { assert, objectEquals, rejectOnTimeout, resolveOnTimeout } from '../common/util/util.js'; + +import { TestGroupTest } from './test_group_test.js'; +import { UnitTest } from './unit_test.js'; + +class FixtureToTest extends UnitTest { + public override immediateAsyncExpectation(fn: () => Promise): Promise { + return super.immediateAsyncExpectation(fn); + } + public override eventualAsyncExpectation(fn: (niceStack: Error) => Promise): void { + super.eventualAsyncExpectation(fn); + } +} + +export const g = makeTestGroup(TestGroupTest); + +g.test('eventual').fn(async t0 => { + const g = makeTestGroupForUnitTesting(FixtureToTest); + + const runState = [0, 0, 0, 0]; + let runStateIndex = 0; + + // Should pass in state 3 + g.test('noawait,resolve').fn(t => { + const idx = runStateIndex++; + + runState[idx] = 1; + t.eventualAsyncExpectation(async () => { + runState[idx] = 2; + await resolveOnTimeout(50); + runState[idx] = 3; + }); + runState[idx] = 4; + }); + + // Should fail in state 4 + g.test('noawait,reject').fn(t => { + const idx = runStateIndex++; + + runState[idx] = 1; + t.eventualAsyncExpectation(async () => { + runState[idx] = 2; + await rejectOnTimeout(50, 'rejected 1'); + runState[idx] = 3; + }); + runState[idx] = 4; + }); + + // Should fail in state 3 + g.test('nested,2').fn(t => { + const idx = runStateIndex++; + + runState[idx] = 1; + t.eventualAsyncExpectation(async () => { + runState[idx] = 2; + await resolveOnTimeout(50); // Wait a bit before adding a new eventualAsyncExpectation + t.eventualAsyncExpectation(() => rejectOnTimeout(100, 'inner rejected 1')); + runState[idx] = 3; + }); + runState[idx] = 4; + }); + + // Should fail in state 3 + g.test('nested,4').fn(t => { + const idx = runStateIndex++; + + runState[idx] = 1; + t.eventualAsyncExpectation(async () => { + t.eventualAsyncExpectation(async () => { + t.eventualAsyncExpectation(async () => { + runState[idx] = 2; + await resolveOnTimeout(50); // Wait a bit before adding a new eventualAsyncExpectation + t.eventualAsyncExpectation(() => rejectOnTimeout(100, 'inner rejected 2')); + runState[idx] = 3; + }); + }); + }); + runState[idx] = 4; + }); + + const resultsPromise = t0.run(g); + assert(objectEquals(runState, [0, 0, 0, 0])); + + const statuses = Array.from(await resultsPromise).map(([, v]) => v.status); + assert(objectEquals(runState, [3, 4, 3, 3]), () => runState.toString()); + assert(objectEquals(statuses, ['pass', 'fail', 'fail', 'fail']), () => statuses.toString()); +}); + +g.test('immediate').fn(async t0 => { + const g = makeTestGroupForUnitTesting(FixtureToTest); + + const runState = [0, 0, 0, 0, 0]; + + g.test('noawait,resolve').fn(t => { + runState[0] = 1; + void t.immediateAsyncExpectation(async () => { + runState[0] = 2; + await resolveOnTimeout(50); + runState[0] = 3; + }); + runState[0] = 4; + }); + + // (Can't g.test('noawait,reject') because it causes a top-level Promise + // rejection which crashes Node.) + + g.test('await,resolve').fn(async t => { + runState[1] = 1; + await t.immediateAsyncExpectation(async () => { + runState[1] = 2; + await resolveOnTimeout(50); + runState[1] = 3; + }); + }); + + g.test('await,reject').fn(async t => { + runState[2] = 1; + await t.immediateAsyncExpectation(async () => { + runState[2] = 2; + await rejectOnTimeout(50, 'rejected 3'); + runState[2] = 3; + }); + }); + + // (Similarly can't test 'nested,noawait'.) + + g.test('nested,await,2').fn(t => { + runState[3] = 1; + t.eventualAsyncExpectation(async () => { + runState[3] = 2; + await resolveOnTimeout(50); // Wait a bit before adding a new immediateAsyncExpectation + runState[3] = 3; + await t.immediateAsyncExpectation(() => rejectOnTimeout(100, 'inner rejected 3')); + runState[3] = 5; + }); + runState[3] = 4; + }); + + g.test('nested,await,4').fn(t => { + runState[4] = 1; + t.eventualAsyncExpectation(async () => { + t.eventualAsyncExpectation(async () => { + t.eventualAsyncExpectation(async () => { + runState[4] = 2; + await resolveOnTimeout(50); // Wait a bit before adding a new immediateAsyncExpectation + runState[4] = 3; + await t.immediateAsyncExpectation(() => rejectOnTimeout(100, 'inner rejected 3')); + runState[4] = 5; + }); + }); + }); + runState[4] = 4; + }); + + const resultsPromise = t0.run(g); + assert(objectEquals(runState, [0, 0, 0, 0, 0])); + + const statuses = Array.from(await resultsPromise).map(([, v]) => v.status); + assert(objectEquals(runState, [3, 3, 2, 3, 3])); + assert(objectEquals(statuses, ['fail', 'pass', 'fail', 'fail', 'fail'])); +}); -- cgit v1.2.3