Skip to content

Commit

Permalink
test(datastore): Refactor test names and make subscriptions more late…
Browse files Browse the repository at this point in the history
…nt / realistic
  • Loading branch information
stocaaro committed Jan 3, 2024
1 parent 354ab21 commit f197d77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('DataStore sync engine', () => {
blogId: 'blog id',
});

harness.userInputDelayed();
harness.latency = 'low';

await postHarness.revise('post title 0');
Expand Down Expand Up @@ -369,6 +370,7 @@ describe('DataStore sync engine', () => {
// and the updated content is observed (below)
['update from second client', 4],
['update from second client', 4],
['update from second client', 4],
['post title 2', 4],
['post title 2', 5],
['post title 2', 5],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class UpdateSequenceHarness {
*/
async outboxSettled() {
await waitForEmptyOutbox();
await Promise.all(subscriptionDeliveryPromiseList);
}

/**
Expand Down Expand Up @@ -267,7 +268,7 @@ export class UpdateSequenceHarness {
const original = await this.datastoreFake.DataStore.save(
new this.datastoreFake.Post(args)
);
// We set this to `false` when we want to test updating a record that is still in the outbox.
// We set this to `false` when we want to test updating a record that is still in the outbox.
if (settleOutbox) {
await this.outboxSettled();
}
Expand Down
9 changes: 9 additions & 0 deletions packages/datastore/__tests__/helpers/fakes/graphqlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ const defaultLatencies: FakeLatencies = {
jitter: 5,
};

export let subscriptionDeliveryPromiseList: Promise<void>[] = [];

/**
* Clear the subscription delivery promise list
*/
export function clearSubscriptionDeliveryPromiseList() {
subscriptionDeliveryPromiseList = [];
}

/**
* Keep a list of all subscription delivery promises where each promise
* resolves after the related message is delivered to all subscribers.
Expand Down

0 comments on commit f197d77

Please sign in to comment.