Commit 83186670 authored by Your Name's avatar Your Name

update test script

parent bcfc6589
import http from 'k6/http';
import { check } from "k6";
export const options = {
// A number specifying the number of VUs to run concurrently.
vus: 10,
// A string specifying the total duration of the test run.
duration: '30s'
};
export default async () => {
let array = new Array(1000);
for (let i = 0; i < array.length; i++) {
//array[i] = i + 1; // 从1开始赋值
array[i] = http.asyncRequest('POST', 'http://192.168.1.220:8000/api/v1/demianhjw/aigic/0129', {
"model_name": "Realistic_Vision_V1.4",
"model_type": "tex2img",
"desc": {
"prompt": " a small car",
"steps": 20
}
}, { headers:
{ "Content-Type": "application/json",
"apikey":"6r9aCCENYah5KPARJ4GLFmlOLs0uAEr2",
"async":"true"}
});
}
//console.log(array); // 输出: [1, 2, 3, 4, 5]
const res = await Promise.all(array)
check(res, {
"status is 200": (r) => r.status === 200,
// "is key correct": (r) => j.json.key === "value",
});
// console.log('----', res);
}
/*
curl --location --request POST 'http://192.168.1.220:8000/api/v1/txt2Img/demianhjw/aigic' \
--header 'apikey: 6r9aCCENYah5KPARJ4GLFmlOLs0uAEr2' \
--header 'Content-Type: application/json' \
--header 'async":true' \
--data-raw '{
"model_name": "Realistic_Vision_V1.4",
"model_type": "tex2img",
"desc": {
"prompt": "small noodles",
"steps": 20
}
}'
curl http://192.168.1.220:8000/api/v1/demianhjw/aigic/0129 -H "Content-Type: application/json" -H "apikey: 6r9aCCENYah5KPARJ4GLFmlOLs0uAEr2" -H "async:true" -d '{
"model_name": "Realistic_Vision_V1.4",
"model_type": "tex2img",
"desc": {
"prompt": " a small car",
"steps": 20
}
}'
*/
// export default async () => {
// const urlOne = `https://httpbin.test.k6.io/delay/${randomInt(1, 5)}`
// const urlTwo = `https://httpbin.test.k6.io/delay/${randomInt(1, 5)}`
// const urlThree = `https://httpbin.test.k6.io/delay/${randomInt(1, 5)}`
// const urlFour = `https://httpbin.test.k6.io/delay/${randomInt(1, 5)}`
// const urlFive = `https://httpbin.test.k6.io/delay/${randomInt(1, 5)}`
// const one = http.asyncRequest('GET', urlOne);
// const two = http.asyncRequest('GET', urlTwo);
// const three = http.asyncRequest('GET', urlThree);
// const four = http.asyncRequest('GET', urlFour);
// const five = http.asyncRequest('GET', urlFive);
// console.log('Racing:')
// console.log(urlOne);
// console.log(urlTwo);
// console.log(urlThree);
// console.log(urlFour);
// console.log(urlFive);
// const res = await Promise.race([one, two, three,four,five])
// console.log('winner is', res.url, 'with duration of', res.timings.duration+'ms');
// }
// function randomInt(min, max) {
// return Math.floor(Math.random() * (max - min) + min);
// }
\ No newline at end of file
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';
import { check } from "k6";
const session = new Httpx({
//http://192.168.1.220:8000/api/v1/demianhjw/aigic/0129
//baseURL: 'http://192.168.1.220:8000/api/v1/demianhjw/aigic/0129',
baseURL: 'http://192.168.1.220:8000',
//baseURL: 'https://httpbin.test.k6.io',
timeout: 20000, // 20s timeout.
});
export default function testSuite() {
// let body = JSON.stringify({
// "model_name": "Realistic_Vision_V1.4",
// "model_type": "tex2img",
// "desc": {
// "prompt": " a small car",
// "steps": 20
// }
// });
//asyncRequest(method, url, [body], [params])
//var currentTime = new Date();
// console.log("await beginTime",currentTime);
//const respPost = await session.asyncPost(`/api/v1/demianhjw/aigic/0129`, {
const respPost = session.asyncPost(`/api/v1/demianhjw/aigic/0129`, {
"model_name": "Realistic_Vision_V1.4",
"model_type": "tex2img",
"desc": {
"prompt": " a small car",
"steps": 20
}
}, { headers:
{ "Content-Type": "application/json",
"apikey":"6r9aCCENYah5KPARJ4GLFmlOLs0uAEr2",
"async":"true"}
});
//var endTime = new Date();
//console.log("endTime",endTime);
//console.log(respPost.body)
// check(respPost, {
// "status is 200": (r) => r.status === 200,
// // "is key correct": (r) => j.json.key === "value",
// });
// const resp_get = await session.asyncRequest('GET', `/status/200`);
// const resp_post = await session.asyncRequest('POST', `/status/200`, { key: 'value' });
// const resp_put = await session.asyncRequest('PUT', `/status/200`, { key: 'value' });
// const resp_patch = await session.asyncRequest('PATCH', `/status/200`, { key: 'value' });
// const resp_delete = await session.asyncRequest('DELETE', `/status/200`);
// // specific methods are also available.
// const respGet = await session.asyncGet(`/status/200`);
// const respPost = await session.asyncPost(`/status/200`, { key: 'value' });
// const respPut = await session.asyncPut(`/status/200`, { key: 'value' });
// const respPatch = await session.asyncPatch(`/status/200`, { key: 'value' });
// const respDelete = await session.asyncDelete(`/status/200`);
}
\ No newline at end of file
......@@ -86,7 +86,7 @@ export default function() {
let res = http.post('http://192.168.1.220:8000/api/v1/demianhjw/aigic/0129', body, { headers:
{ "Content-Type": "application/json",
"apikey":"6r9aCCENYah5KPARJ4GLFmlOLs0uAEr2",
"sync":"true"}
"async":"true"}
});
// Use JSON.parse to deserialize the JSON (instead of using the r.json() method)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment