Skip to content

Commit

Permalink
feat(mojaloop/3471): added no callback scenario (#23)
Browse files Browse the repository at this point in the history
* feat: added no callback scenario

* feat; added new config files for new scenarios
  • Loading branch information
vijayg10 authored Aug 25, 2023
1 parent 12d4a15 commit d85bd9f
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/k6-tests/config/fspiopSingleTransfer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"scenarios": {
"fspiopTransfers": {
"executor": "shared-iterations",
"exec": "fspiopTransfersScenarios",
"env": {
"UNIDIRECTIONAL": "false"
},
"vus": 1,
"iterations": 1
}
},
"thresholds": {
"iteration_duration": [ "p(95)<1000" ],
"http_req_failed": [ "rate<0.01" ],
"http_req_duration": [ "p(95)<1000" ]
}
}
18 changes: 18 additions & 0 deletions packages/k6-tests/config/fspiopTransfersNoCallback.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"scenarios": {
"fspiopTransfers": {
"executor": "shared-iterations",
"exec": "fspiopTransfersNoCallbackScenarios",
"env": {
"UNIDIRECTIONAL": "false"
},
"vus": 1,
"iterations": 5000
}
},
"thresholds": {
"iteration_duration": [ "p(95)<1000" ],
"http_req_failed": [ "rate<0.01" ],
"http_req_duration": [ "p(95)<1000" ]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"scenarios": {
"fspiopTransfers": {
"executor": "constant-arrival-rate",
"exec": "fspiopTransfersNoCallbackScenarios",
"env": {
"UNIDIRECTIONAL": "false"
},
"preAllocatedVUs": 1,
"timeUnit": "1s",
"duration": "1m",
"rate": 300
}
},
"thresholds": {
"iteration_duration": [ "p(95)<1000" ],
"http_req_failed": [ "rate<0.01" ],
"http_req_duration": [ "p(95)<1000" ]
}
}
26 changes: 26 additions & 0 deletions packages/k6-tests/config/fspiopTransfersNoCallbackRampingRate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"scenarios": {
"fspiopTransfers": {
"executor": "ramping-arrival-rate",
"exec": "fspiopTransfersNoCallbackScenarios",
"env": {
"UNIDIRECTIONAL": "false"
},
"preAllocatedVUs": 1,
"timeUnit": "1s",
"startRate": 30,
"stages": [
{ "target": 50, "duration": "2m" },
{ "target": 100, "duration": "2m" },
{ "target": 150, "duration": "2m" },
{ "target": 150, "duration": "2m" },
{ "target": 200, "duration": "15m" }
]
}
},
"thresholds": {
"iteration_duration": [ "p(95)<1000" ],
"http_req_failed": [ "rate<0.01" ],
"http_req_duration": [ "p(95)<1000" ]
}
}
24 changes: 24 additions & 0 deletions packages/k6-tests/config/fspiopTransfersRampingRate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"scenarios": {
"fspiopTransfers": {
"executor": "ramping-arrival-rate",
"exec": "fspiopTransfersScenarios",
"env": {
"UNIDIRECTIONAL": "false"
},
"preAllocatedVUs": 50,
"timeUnit": "1s",
"startRate": 10,
"stages": [
{ "target": 100, "duration": "5m" },
{ "target": 200, "duration": "5m" },
{ "target": 300, "duration": "10m" }
]
}
},
"thresholds": {
"iteration_duration": [ "p(95)<1000" ],
"http_req_failed": [ "rate<0.01" ],
"http_req_duration": [ "p(95)<1000" ]
}
}
1 change: 1 addition & 0 deletions packages/k6-tests/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { fspiopDiscoveryScenarios } from './scenarios/fspiopDiscovery.js';
export { fspiopTransfersScenarios } from './scenarios/fspiopTransfers.js';
export { fspiopTransfersNoCallbackScenarios } from './scenarios/fspiopTransfersNoCallback.js';

const configFile = __ENV.K6_SCRIPT_CONFIG_FILE_NAME ? './config/' + __ENV.K6_SCRIPT_CONFIG_FILE_NAME : './config/test.json';
const testConfig = JSON.parse(open(configFile));
Expand Down
6 changes: 6 additions & 0 deletions packages/k6-tests/scenarios/fspiopTransfersNoCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { postTransfersNoCallback } from "../scripts/postTransfersNoCallback.js";


export function fspiopTransfersNoCallbackScenarios() {
postTransfersNoCallback();
}
74 changes: 74 additions & 0 deletions packages/k6-tests/scripts/postTransfersNoCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import http from 'k6/http';
import { crypto } from "k6/experimental/webcrypto";
import { check, fail, sleep, group } from 'k6';
import { Trace } from "../common/trace.js";
import { getTwoItemsFromArray } from "../common/utils.js";

console.log(`Env Vars -->
K6_SCRIPT_FSPIOP_TRANSFERS_ENDPOINT_URL=${__ENV.K6_SCRIPT_FSPIOP_TRANSFERS_ENDPOINT_URL},
K6_SCRIPT_FSPIOP_FSP_POOL=${__ENV.K6_SCRIPT_FSPIOP_FSP_POOL}
`);

const fspList = JSON.parse(__ENV.K6_SCRIPT_FSPIOP_FSP_POOL)

const ilpPacket = __ENV.K6_SCRIPT_FSPIOP_TRANSFERS_ILPPACKET
const condition = __ENV.K6_SCRIPT_FSPIOP_TRANSFERS_CONDITION
const amount = __ENV.K6_SCRIPT_FSPIOP_TRANSFERS_AMOUNT.toString()
const currency = __ENV.K6_SCRIPT_FSPIOP_TRANSFERS_CURRENCY

export function postTransfersNoCallback() {
group("Post Transfers", function () {
let payerFsp
let payeeFsp

if (__ENV.UNIDIRECTIONAL === "true" || __ENV.UNIDIRECTIONAL === "TRUE") {
payerFsp = fspList[0]
payeeFsp = fspList[1]
} else {
const selectedFsps = getTwoItemsFromArray(fspList)
payerFsp = selectedFsps[0]
payeeFsp = selectedFsps[1]
}

const startTs = Date.now();
const transferId = crypto.randomUUID();
const payerFspId = payerFsp['fspId'];
const payeeFspId = payeeFsp['fspId'];
const traceParent = Trace();
const traceId = traceParent.traceId;

const params = {
tags: {
payerFspId,
payeeFspId
},
headers: {
'Accept': 'application/vnd.interoperability.transfers+json;version=1.1',
'Content-Type': 'application/vnd.interoperability.transfers+json;version=1.1',
'FSPIOP-Source': payerFspId,
'FSPIOP-Destination': payeeFspId,
'Date': (new Date()).toUTCString(),
'traceparent': traceParent.toString(),
'tracestate': `tx_end2end_start_ts=${startTs}`
},
};

const body = {
"transferId": transferId,
"payerFsp": payerFspId,
"payeeFsp": payeeFspId,
"amount": {
amount,
currency
},
"expiration": "2030-01-01T00:00:00.000Z",
ilpPacket,
condition
}

// Lets send the FSPIOP POST /transfers request
const res = http.post(`${__ENV.K6_SCRIPT_FSPIOP_TRANSFERS_ENDPOINT_URL}/transfers`, JSON.stringify(body), params);
check(res, { 'TRANSFERS_FSPIOP_POST_TRANSFERS_RESPONSE_IS_202' : (r) => r.status == 202 });

});
}

0 comments on commit d85bd9f

Please sign in to comment.