loadtest.js 2.65 KB
const loadtest = require('loadtest');
 
function statusCallback(error, result, latency) {
    console.log('Current latency %j, result %j, error %j', latency, result, error);
    console.log('----');
    if(result) {
        console.log('Request elapsed milliseconds: ', result.requestElapsed);
        console.log('Request index: ', result.requestIndex);
        console.log('Request loadtest() instance index: ', result.instanceIndex);
    }
}
 
// const options = {
//     url: 'http://127.0.0.1:5001/api/v3/mpay/billingonbehalf/reserveAndChargeVolume.json',
//     maxRequests: 10000,
//     requestsPerSecond: 100,
//     headers : {
//         "Content-Type":"application/json",
//         "x-app":"partnerId=30163; ptsAppKeyName=PICO|Browser|1.0.0",
//         "x-tid":"SACF-300519siwkxkw7du",
//         "X-Public-Id":"sgltest7@corp.ais900dev.org",
//         "X-Private-Id":"NI5smn3wWpoPX1ma2jbPiE8hK4QcDqHR1582013702233"
//     },
//     method: "POST",
//     body : {
//         "endUserIdentifier":"66932019877",
//         "volume":"0",
//         "out_trade_no":"nw424bc0bb690c73518a762a2d1a339d7f_COINS12000_20190219095515",
//         "subject":"Purchased 12000 coins.",
//         "pay_time":"2020-03-24 20:20:20",
//         "device_id":"90c73518a762a2d1a339d7f",
//         "buyer_pay_fee":"Paid by user",
//         "coupon_fee":"20",
//         "terminal_type":"IOS",
//         "billingText":"test",
//         "parameters":{
//            "amount":"0",
//            "serviceNumber":"35000900022",
//            "serviceType":"Download",
//            "transactionID":"50609152601999918991",
//            "currency":"THB",
//            "taxDev":"0",
//            "productCode":"Purchased 12000 coins that can be spent on weapons.",
//            "productInfo":"COINS12000",
//            "merchantContact":"MerchantContactTest",
//            "cct":"0",
//            "expireDate":"20200523142045",
//            "senderName":"Huawei"
//         }
//      },
//     contentType : "application/json",
//     statusCallback: statusCallback
// };

const options = {
    url: 'http://10.1.2.136:9201/api/v1/register/scanDevice/TpZ3EgSQ',
    maxRequests: 1000,
    requestsPerSecond: 30,
    headers : {
        "Content-Type":"application/json",
        "x-transaction-id":"NI5smn3wWpoPX1ma2jbPiE8hK4QcDqHR1582013702233",
        "x-req-timestamp":"NI5smn3wWpoPX1ma2jbPiE8hK4QcDqHR1582013702233"
    },
    method: "GET",
    body : null,
    contentType : "application/json",
    statusCallback: statusCallback
};
 
loadtest.loadTest(options, function(error) {
    if (error) {
        return console.error('Got an error: %s', error);
    }
    console.log('Tests run successfully');
});