autocannon 随机数 改为 uuid

146 阅读1分钟

修改 autocannon 安装的源码。找到你的包的位置。修改lib/requestIterator.jslib/httpRequestBuilder.js我是 mac 下面全局安装的,我的修改如下:

为了[<id>]为 uuid , 要进行如下修改
/usr/local/lib/node_modules/autocannon/lib/requestIterator.js

修改如下:

3 // const hyperid = require('hyperid')(true)
3 const hyperid = require('hyperid')

111 // ? Buffer.from(data.toString().replace(/\[<id>\]/g, hyperid()))
111 ? Buffer.from(data.toString().replace(/\[<id>\]/g, hyperid().uuid))


/usr/local/lib/node_modules/autocannon/lib/httpRequestBuilder.js

90 // headers['Content-Length'] = `${bodyBuf.length + (idCount * 27)}`
90 headers['Content-Length'] = `${bodyBuf.length + (idCount * 30)}`

然后,就可以通过[<id>]实现随机uuid了。

autocannon -c 1 -p 1 -d 1 -I true -m POST -H "Content-Type":"application/x-www-form-urlencoded" -b 'strAnswer={"Patient":[{"PatientId":"[<id>]",.....}]}&InvestigationType=住院' http://somexxx