Skip to content

Commit f831bef

Browse files
committed
Test buffer.mapAsync() early rejection
With this WebGPU spec change gpuweb/gpuweb#3348 buffer.mapAsync() rejects immediately if it is pending map. This commit adds a test to check it.
1 parent 09447fa commit f831bef

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/webgpu/api/validation/buffer/mapping.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,39 @@ g.test('mapAsync,offsetAndSizeOOB')
280280
await t.testMapAsyncCall(success, 'OperationError', buffer, mapMode, offset, size);
281281
});
282282

283+
g.test('mapAsync,earlyRejection')
284+
.desc("Test that mapAsync fails immediately if it's pending map.")
285+
.paramsSubcasesOnly(u => u.combine('mapMode', kMapModeOptions).combine('offset2', [0, 8]))
286+
.fn(async t => {
287+
const { mapMode, offset2 } = t.params;
288+
289+
const bufferSize = 16;
290+
const mapSize = 8;
291+
const offset1 = 0;
292+
293+
const buffer = t.createMappableBuffer(mapMode, bufferSize);
294+
295+
const p1 = buffer.mapAsync(mapMode, offset1, mapSize); // succeeds
296+
let success = false;
297+
{
298+
let caught = false;
299+
// should be already rejected
300+
const p2 = buffer.mapAsync(mapMode, offset2, mapSize);
301+
// queues a microtask catching the rejection
302+
p2.catch(() => {
303+
caught = true;
304+
});
305+
// queues a second microtask to capture the state immediately after the catch.
306+
// Test fails if p2 isn't rejected before the second microtask is fired or
307+
// p1 is resolved.
308+
queueMicrotask(() => {
309+
success = caught;
310+
});
311+
}
312+
await p1; // ensure the original map still succeeds
313+
assert(success);
314+
});
315+
283316
g.test('getMappedRange,state,mapped')
284317
.desc('Test that it is valid to call getMappedRange in the mapped state')
285318
.paramsSubcasesOnly(u => u.combine('mapMode', kMapModeOptions))

0 commit comments

Comments
 (0)