Skip to content

Commit 8dc726f

Browse files
committed
Fix test promise handling.
1 parent cd19ba2 commit 8dc726f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

modules/module-mongodb/test/src/change_stream_utils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { clearTestDb, TEST_CONNECTION_OPTIONS } from './util.js';
2222
export class ChangeStreamTestContext {
2323
private _walStream?: ChangeStream;
2424
private abortController = new AbortController();
25-
private streamPromise?: Promise<any>;
25+
private streamPromise?: Promise<PromiseSettledResult<void>>;
2626
public storage?: SyncRulesBucketStorage;
2727

2828
/**
@@ -143,15 +143,19 @@ export class ChangeStreamTestContext {
143143
}
144144

145145
startStreaming() {
146-
this.streamPromise = this.streamer.streamChanges().catch((e) => e);
146+
this.streamPromise = this.streamer
147+
.streamChanges()
148+
.then(() => ({ status: 'fulfilled', value: undefined }) satisfies PromiseFulfilledResult<void>)
149+
.catch((reason) => ({ status: 'rejected', reason }) satisfies PromiseRejectedResult);
150+
return this.streamPromise;
147151
}
148152

149153
async getCheckpoint(options?: { timeout?: number }) {
150154
let checkpoint = await Promise.race([
151155
getClientCheckpoint(this.client, this.db, this.factory, { timeout: options?.timeout ?? 15_000 }),
152156
this.streamPromise?.then((e) => {
153-
if (e != null) {
154-
throw e;
157+
if (e.status == 'rejected') {
158+
throw e.reason;
155159
}
156160
})
157161
]);

modules/module-mongodb/test/src/resume.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ function defineResumeTest(factoryGenerator: (options?: TestStorageOptions) => Pr
5858
context2.storage = factory.getInstance(activeContent!);
5959

6060
// If this test times out, it likely didn't throw the expected error here.
61-
const error = await context2.startStreaming().catch((ex) => ex);
61+
const result = await context2.startStreaming();
6262
// The ChangeStreamReplicationJob will detect this and throw a ChangeStreamInvalidatedError
63-
expect(error).toBeInstanceOf(ChangeStreamInvalidatedError);
63+
expect(result.status).toEqual('rejected');
64+
expect((result as PromiseRejectedResult).reason).toBeInstanceOf(ChangeStreamInvalidatedError);
6465
});
6566
}

0 commit comments

Comments
 (0)