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 (ci): custom-parser.test.js is randomly failing with a 503 Service Unavailable #3626

Closed
2 tasks done
darkgl0w opened this issue Jan 16, 2022 · 0 comments · Fixed by #3627
Closed
2 tasks done

Comments

@darkgl0w
Copy link
Member

darkgl0w commented Jan 16, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Hello.

Following this #3622 (comment) - Failed CI Run Log.

This test is randomly failing on fastify CI runs returning a 503 HTTP Status code instead of the expected 200 at line 1381.

test('contentTypeParser should add multiple custom parsers with RegExp values', t => {
t.plan(10)
const fastify = Fastify()
fastify.post('/', (req, reply) => {
reply.send(req.body)
})
fastify.addContentTypeParser(/.*\+json$/, function (req, payload, done) {
jsonParser(payload, function (err, body) {
done(err, body)
})
})
fastify.addContentTypeParser(/.*\+xml$/, function (req, payload, done) {
done(null, 'xml')
})
fastify.addContentTypeParser(/.*\+myExtension$/, function (req, payload, done) {
let data = ''
payload.on('data', chunk => { data += chunk })
payload.on('end', () => {
done(null, data + 'myExtension')
})
})
fastify.listen(0, err => {
t.error(err)
sget({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port,
body: '{"hello":"world"}',
headers: {
'Content-Type': 'application/vnd.hello+json'
}
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.same(body.toString(), JSON.stringify({ hello: 'world' }))
})
sget({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port,
body: '{"hello":"world"}',
headers: {
'Content-Type': 'application/test+xml'
}
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.same(body.toString(), 'xml')
})
sget({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port,
body: 'abcdefg',
headers: {
'Content-Type': 'application/+myExtension'
}
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.same(body.toString(), 'abcdefgmyExtension')
fastify.close()
})
})
})

Possible fix: darkgl0w@e8a138c

Switching from simple-get to await fastify.inject, using teardown() to close the server, and making use of an async/await tap callback seems to solve the issue (needs to be confirmed by a couple runs on fastify CI).

@darkgl0w darkgl0w changed the title CI: custom-parser.test.js is randomly failing with a 503 Service Unavailable test (ci): custom-parser.test.js is randomly failing with a 503 Service Unavailable Jan 16, 2022
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 a pull request may close this issue.

1 participant