Skip to content

Commit

Permalink
ADD test for #2048
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Apr 13, 2020
1 parent 9f4f14d commit 791041c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/plugins/replication-graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Core.plugin(RxDBWatchForChangesPlugin);


export class RxGraphQLReplicationState {

constructor(
public collection: RxCollection,
url: string,
Expand Down Expand Up @@ -94,7 +95,12 @@ export class RxGraphQLReplicationState {
};
public _runningPromise: Promise<void> = 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<any> = undefined as any;

public recieved$: Observable<any> = undefined as any;
Expand Down Expand Up @@ -161,6 +167,8 @@ export class RxGraphQLReplicationState {
}

async _run() {
this._runCount = this._runCount + 1;

let willRetry = false;

if (this.push) {
Expand Down
28 changes: 28 additions & 0 deletions test/unit/replication-graphql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 791041c

Please sign in to comment.