Skip to content

Commit

Permalink
Merge pull request #2745 from dome4/initial-replication
Browse files Browse the repository at this point in the history
graphql - await initial replication resolves on failed replication
  • Loading branch information
pubkey authored Dec 12, 2020
2 parents ad8a87f + 842d8b3 commit f68221e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugins/replication-graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class RxGraphQLReplicationState {
this._subjects.active.next(true);
const willRetry = await this._run(retryOnFail);
this._subjects.active.next(false);
if (!willRetry && this._subjects.initialReplicationComplete['_value'] === false) {
if (retryOnFail && !willRetry && this._subjects.initialReplicationComplete['_value'] === false) {
this._subjects.initialReplicationComplete.next(true);
}
this._runQueueCount--;
Expand Down
42 changes: 42 additions & 0 deletions test/unit/replication-graphql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,48 @@ describe('replication-graphql.test.js', () => {
const docsAfter = await c.find().exec();
assert.strictEqual(docsAfter.length, 1);

server.close();
c.database.destroy();
});
it('should fail because initial replication never resolves', async () => {
if (config.isFastMode()) {
// this test takes too long, do not run in fast mode
return;
}
const liveInterval = 4000;
const [c, server] = await Promise.all([
humansCollection.createHumanWithTimestamp(0),
SpawnServer.spawn()
]);

const replicationState = c.syncGraphQL({
url: ERROR_URL,
pull: {
queryBuilder
},
deletedFlag: 'deleted',
live: true,
liveInterval: liveInterval,
});

let timeoutId: any;
const timeout = new Promise((_, reject) => {
timeoutId = setTimeout(() => {
clearTimeout(timeoutId);
reject(new Error('Timeout reached'));
},
// small buffer until the promise rejects
liveInterval + 5000);
});

const raceProm = Promise.race([
replicationState.awaitInitialReplication(),
timeout
]).then(_ => clearTimeout(timeoutId));

// error should be thrown because awaitInitialReplication() should never resolve
await AsyncTestUtil.assertThrows(() => raceProm, Error, 'Timeout');

server.close();
c.database.destroy();
});
Expand Down

0 comments on commit f68221e

Please sign in to comment.