Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
fix: Problems with integration tests timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki committed May 13, 2019
1 parent 698ff65 commit 1788d3e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"exclude": [
"**/*.test.ts",
"**/test/*.ts"
"**/test/**/*.ts"
]
}
}
24 changes: 20 additions & 4 deletions packages/sync/integration_test/test/offline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TestStore } from '../utils/testStore';
import { ToggleableNetworkStatus } from '../utils/network';
import server from '../utils/server';
import waitFor from '../utils/waitFor';
import timeout from '../utils/timeout';
import { ADD_TASK, GET_TASKS, UPDATE_TASK, DELETE_TASK, ONLINE_ONLY } from '../utils/graphql.queries';

// TODO: error handling when server is down
Expand Down Expand Up @@ -62,6 +63,11 @@ describe('Offline mutations', function () {
client = await newClient({ networkStatus, storage: store, mutationsQueueName });
});

async function isQueueEmpty(){
const store = await store.getItem(offlineMetaKey);
return store.length === 0
}

describe('save mutation to offlineMutationStore while offline', function () {

it('should succeed', async function () {
Expand Down Expand Up @@ -348,8 +354,10 @@ describe('Offline mutations', function () {
variables
});
} catch (ignore) { }

const offlineKeys = await store.getItem(offlineMetaKey);


const offlineMutation1 = await store.getItem("offline:" + offlineKeys[0]);
const offlineMutation2 = await store.getItem("offline:" + offlineKeys[1]);

Expand All @@ -359,8 +367,12 @@ describe('Offline mutations', function () {
expect(offlineMutation2.operation.variables.title).to.equal(variables.title);

networkStatus.setOnline(true);
console.log("offlineKeys for ", offlineKeys);
// console.log("waiting for 1", (await store.getItem("offline:" + offlineKeys[0])))
// console.log("waiting for 2", (await store.getItem("offline:" + offlineKeys[1])))

await waitFor(() => store.getItem("offline:" + offlineKeys[1]) === undefined);
await waitFor(() => isQueueEmpty, 100);
await timeout(100);

const response = await client.query({
query: GET_TASKS,
Expand All @@ -370,6 +382,7 @@ describe('Offline mutations', function () {
expect(response.data.allTasks).to.exist;
expect(response.data.allTasks.length).to.equal(1);
expect(response.data.allTasks[0].title).to.equal(variables.title);

});
});

Expand Down Expand Up @@ -403,7 +416,7 @@ describe('Offline mutations', function () {

variables.title = 'nomerge2';
try {
client.mutate({
await client.mutate({
mutation: UPDATE_TASK,
variables
});
Expand All @@ -420,7 +433,8 @@ describe('Offline mutations', function () {

networkStatus.setOnline(true);

await waitFor(() => store.getItem("offline:" + offlineKeys[1]) === undefined);
await waitFor(() => isQueueEmpty, 100);
await timeout(100);

const response = await client.query({
query: GET_TASKS,
Expand Down Expand Up @@ -487,3 +501,5 @@ describe('Offline mutations', function () {
});

});


5 changes: 5 additions & 0 deletions packages/sync/integration_test/utils/timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

export default timeout;

0 comments on commit 1788d3e

Please sign in to comment.