Skip to content

Commit 3647631

Browse files
committed
Add a timeout to the Promise to ensure the test doesn't hang indefinitely if the error event is never emitted.
1 parent b699fbd commit 3647631

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

packages/request-client.js/test/http-data-access.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ describe('HttpDataAccess', () => {
3030
},
3131
});
3232
const returnPersistTransaction = await httpDataAccess.persistTransaction({}, '', []);
33-
await new Promise<void>((resolve) => {
34-
returnPersistTransaction.on('error', (e: any) => {
35-
expect(e.message).toBe(
36-
`The Request Network SDK timed-out while polling the Request Node to confirm that the Request was persisted successfully. It is likely that the persisted Request will be confirmed eventually. App Builders are discouraged from calling persistTransaction() a second time, which would create a duplicate Request. Instead, App Builders are recommended to catch this error and continue polling the Request Node using getConfirmedTransaction() or by calling the /getConfirmedTransaction endpoint. To avoid timeouts in the future, try adjusting the httpConfig values when instantiating the RequestNetwork object. The current httpConfig settings are: getConfirmationDeferDelay: 0ms, getConfirmationMaxRetries: 0, getConfirmationRetryDelay: 1000ms, getConfirmationExponentialBackoffDelay: 0ms, getConfirmationMaxExponentialBackoffDelay: 30000ms`,
37-
);
38-
resolve();
39-
});
40-
});
33+
await Promise.race([
34+
new Promise<void>((resolve) => {
35+
returnPersistTransaction.on('error', (e: any) => {
36+
expect(e.message).toBe(
37+
'The Request Network SDK timed-out while polling the Request Node to confirm that the Request was persisted successfully. It is likely that the persisted Request will be confirmed eventually. App Builders are discouraged from calling persistTransaction() a second time, which would create a duplicate Request. Instead, App Builders are recommended to catch this error and continue polling the Request Node using getConfirmedTransaction() or by calling the /getConfirmedTransaction endpoint. To avoid timeouts in the future, try adjusting the httpConfig values when instantiating the RequestNetwork object. The current httpConfig settings are: getConfirmationDeferDelay: 0ms, getConfirmationMaxRetries: 0, getConfirmationRetryDelay: 1000ms, getConfirmationExponentialBackoffDelay: 0ms, getConfirmationMaxExponentialBackoffDelay: 30000ms',
38+
);
39+
resolve();
40+
});
41+
}),
42+
new Promise((_, reject) => setTimeout(() => reject(new Error('Test timed out')), 5000)),
43+
]);
4144
});
4245
});
4346
});

0 commit comments

Comments
 (0)