From 791041cb04971bd832499f96ff414beb8cb1c5af Mon Sep 17 00:00:00 2001 From: pubkey Date: Mon, 13 Apr 2020 20:27:46 +0200 Subject: [PATCH] ADD test for #2048 --- src/plugins/replication-graphql/index.ts | 8 +++++++ test/unit/replication-graphql.test.ts | 28 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/plugins/replication-graphql/index.ts b/src/plugins/replication-graphql/index.ts index 0006ac319a5..cfa6f3ac726 100644 --- a/src/plugins/replication-graphql/index.ts +++ b/src/plugins/replication-graphql/index.ts @@ -62,6 +62,7 @@ Core.plugin(RxDBWatchForChangesPlugin); export class RxGraphQLReplicationState { + constructor( public collection: RxCollection, url: string, @@ -94,7 +95,12 @@ export class RxGraphQLReplicationState { }; public _runningPromise: Promise = Promise.resolve(); public _subs: Subscription[] = []; + + // counts how often the replication has run + // used in tests + public _runCount = 0; public _runQueueCount: number = 0; + public initialReplicationComplete$: Observable = undefined as any; public recieved$: Observable = undefined as any; @@ -161,6 +167,8 @@ export class RxGraphQLReplicationState { } async _run() { + this._runCount = this._runCount + 1; + let willRetry = false; if (this.push) { diff --git a/test/unit/replication-graphql.test.ts b/test/unit/replication-graphql.test.ts index 4f589b0d5ff..ef73639dcab 100644 --- a/test/unit/replication-graphql.test.ts +++ b/test/unit/replication-graphql.test.ts @@ -2030,6 +2030,34 @@ describe('replication-graphql.test.js', () => { server.close(); db.destroy(); }); + it('#2048 GraphQL .run() fires exponentially', async () => { + const c = await humansCollection.createHumanWithTimestamp(0); + const server = await SpawnServer.spawn(getTestData(1)); + + const replicationState = c.syncGraphQL({ + url: server.url, + pull: { + queryBuilder + }, + live: true, + deletedFlag: 'deleted' + }); + assert.strictEqual(replicationState._runCount, 0); + + // call run() many times + const amount = 100; + await Promise.all( + new Array(amount).map( + () => replicationState.run() + ) + ); + + await AsyncTestUtil.wait(50); + assert.ok(replicationState._runCount > 0); + assert.ok(replicationState._runCount < amount); + + c.database.destroy(); + }); }); }); describe('browser', () => {