import http from 'k6/http';
import { check } from 'k6';

export default function () {


  /*


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


  ./k6 run --vus 100 -i 100    --batch 2000  --batch-per-host 1000   http_batch.js   --local-ips '192.168.10.1-192.168.10.99'



   ./k6 run --vus 30 -d 100s   --batch 20000  --batch-per-host 10000 http_batch.js   --local-ips '192.168.10.1-192.168.10.99'  


  */

  let array = new Array(1000); 
for (let i = 0; i < array.length; i++) {

  array[i] = {
    method: 'POST',
    url: 'http://192.168.1.220:8000/api/v1/demianhjw/aigic/0129',
    body: {
      "model_name": "Realistic_Vision_V1.4",
      "model_type": "tex2img",
      "desc": {
          "prompt": " a small car",
          "steps": 20
          }
    },
    params: {
      headers:  { "Content-Type": "application/json",
      "apikey":"6r9aCCENYah5KPARJ4GLFmlOLs0uAEr2",
      "async":"true"},
    },
  };

}

  const responses = http.batch(array);
  // httpbin.test.k6.io should return our POST data in the response body, so
  // we check the third response object to see that the POST worked.
  // check(responses[0], {
  //   'form data OK': (res) => JSON.parse(res.body)['form']['hello'] == 'world!',
  // });

  const res =  Promise.all(array)
  check(res, {
      "status is 200": (r) => r.status === 200,
  // "is key correct": (r) => j.json.key === "value",
  });
}


// export let options = {
//   stages: [
//       // Ramp-up from 1 to 5 VUs in 10s
//       { duration: "20s", target: 2000 },

//       // Stay at rest on 5 VUs for 5s
//       { duration: "10s", target: 1000 },

//       // Ramp-down from 5 to 0 VUs for 5s
//       { duration: "15s", target: 0 }
//   ]
// };