diff --git a/packages/test/test-end-to-end-tests/src/test/handleValidation.spec.ts b/packages/test/test-end-to-end-tests/src/test/handleValidation.spec.ts index 10bcf968c178..3c3d771311a2 100644 --- a/packages/test/test-end-to-end-tests/src/test/handleValidation.spec.ts +++ b/packages/test/test-end-to-end-tests/src/test/handleValidation.spec.ts @@ -39,6 +39,7 @@ import { createAndAttachContainer, ITestFluidObject, type ITestObjectProvider, + timeoutAwait, } from "@fluidframework/test-utils/internal"; import { ITree, @@ -376,14 +377,25 @@ describeCompat("handle validation", "NoCompat", (getTestObjectProvider, apis) => await queue.add(handle); }, async readHandle(): Promise { - const value = await new Promise((resolve, reject) => { - queue - .acquire(async (result: FluidObject) => { - resolve(result); - return ConsensusResult.Release; - }) - .catch((error) => reject(error)); - }); + const value = await timeoutAwait( + new Promise((resolve, reject) => { + queue + .acquire(async (result: FluidObject) => { + resolve(result); + return ConsensusResult.Release; + }) + .then((wasNonempty) => { + if (!wasNonempty) { + // This could happen if a test never calls `storeHandle` before attempting to read it. + // Other modes of failure are possible (e.g. correctness issues in ConsensusQueue causing it to have the wrong data). + // Resolving the promise with `undefined` here could be another reasonable option, but this gives slightly more information. + reject(new Error("No values found in consensus queue.")); + } + }) + .catch((error) => reject(error)); + }), + { errorMsg: "Timeout waiting for acquiring value from consensus queue." }, + ); return value; }, handle: queue.handle,