Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky tests #54

Merged
merged 7 commits into from
Jan 27, 2023
Merged

test: fix flaky tests #54

merged 7 commits into from
Jan 27, 2023

Conversation

marco-ippolito
Copy link
Contributor

@marco-ippolito marco-ippolito commented Jan 25, 2023

resolves: #53
I'll try to fix flakiness of some tests.
On this one I think its the timers

test('gateway - should log error if retry throws', async t => {
t.plan(1)
const service1 = await createTestService(
0,
userService.schema,
userService.resolvers
)
let service2 = null
t.context.clock.setTimeout(async () => {
service2 = await createTestService(
5114,
postService.schema,
postService.resolvers
)
}, 2000)
const gateway = Fastify()
let errCount = 0
gateway.log.error = error => {
if (error.message.includes('kaboom') && errCount === 0) {
errCount++
t.pass()
}
}
t.teardown(async () => {
await gateway.close()
await service1.close()
await service2.close()
})
await gateway.register(plugin, {
gateway: {
services: [
{
name: 'user',
url: `http://localhost:${service1.server.address().port}/graphql`,
mandatory: false
},
{
name: 'post',
url: 'http://localhost:5114/graphql',
mandatory: true
}
],
retryServicesCount: 1,
retryServicesInterval: 3000
},
jit: 1
})
gateway.graphqlGateway.addHook('onGatewayReplaceSchema', async () => {
throw new Error('kaboom')
})
await gateway.ready()
for (let i = 0; i < 200; i++) {
await t.context.clock.tickAsync(50)
}
})

@marco-ippolito
Copy link
Contributor Author

marco-ippolito commented Jan 27, 2023

it seems starting service2 a bit earlier and removing the error count, make the test more stable, I dont think it these changes make the test less meaningful wdyt @mcollina

@marco-ippolito marco-ippolito marked this pull request as ready for review January 27, 2023 09:34
@marco-ippolito marco-ippolito changed the title [WIP] fix flaky tests test: fix flaky tests Jan 27, 2023
Copy link
Contributor

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 49afc34 into mercurius-js:main Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate flaky tests
2 participants