forked from sebastianwessel/quickjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadtest.ts
50 lines (37 loc) · 948 Bytes
/
loadtest.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import autocannon from 'autocannon'
const promiseTestBody = `const fn = async ()=> {
const x = await new Promise((resolve,reject)=>{
resolve('resolve')
})
return x
}
export default await fn()`
const fetchTestBody = `import * as path from 'node:path'
import { writeFileSync, readFileSync } from 'node:fs'
const fn = async ()=>{
// console.log(path.join('src','dist'))
const url = new URL('https://example.com')
const f = await fetch(url)
const text = await f.text()
writeFileSync('/test.html', 'stored: ' + text)
const result = readFileSync('/test.html')
return result
}
export default await fn()`
autocannon(
{
url: 'http://127.0.0.1:3000/execute',
duration: 60,
method: 'POST',
body: promiseTestBody,
},
(_err, result) => {
for (const [key, value] of Object.entries(result)) {
if (Array.isArray(value)) {
console.table(value)
} else {
console.log(key, value)
}
}
},
)