Skip to content

Commit 832e77f

Browse files
committed
Ensure all benches return proper content-type
1 parent 6d59537 commit 832e77f

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

bench/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const { fork } = require('child_process')
44
const { join } = require('path')
5-
const getScrud = require('get-scrud')
5+
const { get } = require('axios')
66
const autocannon = require('autocannon')
77
const table = require('tty-table')
88
const ports = {http: 3010, fastify: 3011, polka: 3012, scrud: 3013, express: 3014}
@@ -81,14 +81,15 @@ const bencher = (title) => new Promise((resolve, reject) => {
8181
let last = {}
8282
const checkConsistency = async (name) => {
8383
let port = ports[name]
84-
let { read } = getScrud(urlTemplate(port))
85-
let tmpRes = await read('bench', benchId)
86-
if (!tmpRes || (last.lib && last.result !== tmpRes)) {
84+
let { data, headers } = await get(urlTemplate(port, true))
85+
let isJSON = headers['content-type'].indexOf('application/json') !== -1
86+
data = `${JSON.stringify(data)}-isJson:${isJSON}`
87+
if (!data || (last.lib && last.result !== data)) {
8788
let err = new Error(`Got inconsistent results from libraries`)
88-
err.meta = [`${last.lib} - ${last.result}`, `${name} - ${tmpRes}`]
89+
err.meta = [`${last.lib} - ${last.result}`, `${name} - ${data}`]
8990
throw err
9091
}
91-
last = {lib: name, result: tmpRes}
92+
last = {lib: name, result: data}
9293
}
9394

9495
const getEndMemory = (name) => new Promise((resolve, reject) => {

bench/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const start = {
1919
http: () => {
2020
const http = require('http')
2121
http.createServer((req, res) => {
22-
res.setHeader('Content-Type', 'application/json')
22+
res.setHeader('Content-Type', 'application/json; charset=utf-8')
2323
res.end(preRendered)
2424
}).listen(ports.http, () => logStart('http'))
2525
},
@@ -33,6 +33,7 @@ const start = {
3333
polka: () => {
3434
const polka = require('polka')
3535
polka().get('/bench/:id', (req, res) => {
36+
res.setHeader('Content-Type', 'application/json; charset=utf-8')
3637
res.end(JSON.stringify({data: toSend, error: null}))
3738
}).listen(ports.polka).then(() => logStart('polka'))
3839
},

0 commit comments

Comments
 (0)