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);
// }