Skip to content

Commit

Permalink
fix: handle flaky tests (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Aug 27, 2022
1 parent f25d973 commit b7d5685
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@graphql-tools/merge": "^8.0.0",
"@graphql-tools/schema": "^8.0.0",
"@graphql-tools/utils": "^8.0.0",
"@sinonjs/fake-timers": "^9.0.0",
"@sinonjs/fake-timers": "^9.1.2",
"@types/node": "^18.0.0",
"@types/ws": "^8.2.0",
"@types/isomorphic-form-data": "^2.0.0",
Expand All @@ -48,7 +48,7 @@
"snazzy": "^9.0.0",
"split2": "^4.0.0",
"standard": "^17.0.0",
"tap": "^16.0.0",
"tap": "^16.3.0",
"tsd": "^0.22.0",
"typescript": "^4.3.5",
"wait-on": "^6.0.0"
Expand Down
36 changes: 18 additions & 18 deletions test/gateway/retry-failed-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ test('gateway - retry mandatory failed services on startup', async (t) => {
advanceTimeDelta: 100
})

const service1 = await createTestService(5001, userService.schema, userService.resolvers)
const service1 = await createTestService(0, userService.schema, userService.resolvers)

let service2 = null
setTimeout(async () => {
service2 = await createTestService(5002, postService.schema, postService.resolvers)
service2 = await createTestService(5113, postService.schema, postService.resolvers)
}, 5000)

const app = Fastify()
Expand All @@ -140,12 +140,12 @@ test('gateway - retry mandatory failed services on startup', async (t) => {
services: [
{
name: 'user',
url: 'http://localhost:5001/graphql',
url: `http://localhost:${service1.server.address().port}/graphql`,
mandatory: false
},
{
name: 'post',
url: 'http://localhost:5002/graphql',
url: 'http://localhost:5113/graphql',
mandatory: true
}
]
Expand Down Expand Up @@ -221,11 +221,11 @@ test('gateway - should not call onGatewayReplaceSchemaHandler if the hook is not
advanceTimeDelta: 100
})

const service1 = await createTestService(5001, userService.schema, userService.resolvers)
const service1 = await createTestService(0, userService.schema, userService.resolvers)

let service2 = null
setTimeout(async () => {
service2 = await createTestService(5002, postService.schema, postService.resolvers)
service2 = await createTestService(5111, postService.schema, postService.resolvers)
}, 5000)

const app = Fastify()
Expand All @@ -242,12 +242,12 @@ test('gateway - should not call onGatewayReplaceSchemaHandler if the hook is not
services: [
{
name: 'user',
url: 'http://localhost:5001/graphql',
url: `http://localhost:${service1.server.address().port}/graphql`,
mandatory: false
},
{
name: 'post',
url: 'http://localhost:5002/graphql',
url: 'http://localhost:5111/graphql',
mandatory: true
}
],
Expand Down Expand Up @@ -319,7 +319,7 @@ test('gateway - dont retry non-mandatory failed services on startup', async (t)
advanceTimeDelta: 100
})

const service1 = await createTestService(5001, userService.schema, userService.resolvers)
const service1 = await createTestService(0, userService.schema, userService.resolvers)

const app = Fastify()
t.teardown(async () => {
Expand All @@ -334,12 +334,12 @@ test('gateway - dont retry non-mandatory failed services on startup', async (t)
services: [
{
name: 'user',
url: 'http://localhost:5001/graphql',
url: `http://localhost:${service1.server.address().port}/graphql`,
mandatory: false
},
{
name: 'post',
url: 'http://localhost:5002/graphql',
url: 'http://localhost:5112/graphql',
mandatory: false
}
],
Expand Down Expand Up @@ -406,11 +406,11 @@ test('gateway - should log error if retry throws', async (t) => {
advanceTimeDelta: 100
})

const service1 = await createTestService(5001, userService.schema, userService.resolvers)
const service1 = await createTestService(0, userService.schema, userService.resolvers)

let service2 = null
setTimeout(async () => {
service2 = await createTestService(5002, postService.schema, postService.resolvers)
service2 = await createTestService(5113, postService.schema, postService.resolvers)
}, 2000)

const app = Fastify()
Expand All @@ -436,12 +436,12 @@ test('gateway - should log error if retry throws', async (t) => {
services: [
{
name: 'user',
url: 'http://localhost:5001/graphql',
url: `http://localhost:${service1.server.address().port}/graphql`,
mandatory: false
},
{
name: 'post',
url: 'http://localhost:5002/graphql',
url: 'http://localhost:5113/graphql',
mandatory: true
}
],
Expand All @@ -456,8 +456,8 @@ test('gateway - should log error if retry throws', async (t) => {

await app.ready()

for (let i = 0; i < 10; i++) {
await clock.tickAsync(1000)
for (let i = 0; i < 100; i++) {
await clock.tickAsync(100)
}
})

Expand Down Expand Up @@ -497,7 +497,7 @@ test('gateway - stop retrying after no. of retries exceeded', async (t) => {
},
{
name: 'post',
url: 'http://localhost:5002/graphql',
url: 'http://localhost:5114/graphql',
mandatory: true
}
],
Expand Down

0 comments on commit b7d5685

Please sign in to comment.