Skip to content

Commit

Permalink
Added test for search and refactored a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
dagfinno committed Oct 2, 2024
1 parent d5a1c81 commit cc540ec
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 7 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/t3search-loadtest-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: taxreport loadtest smoketest

on:
push:
branches:
- '**'
paths:
- performance-tests/t3search/**
- .github/workflows/t3search-loadtest-push.yml

jobs:
run-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup go
uses: actions/setup-go@v5
with:
go-version: 'stable'

- name: Install xk6
run: go install go.k6.io/xk6/cmd/xk6@latest

- name: Build xk6-counter binary
working-directory: ./performance-tests/tax-report/src
run: xk6 build --with github.com/avitalique/xk6-file@latest

- name: Run k6 to generate tokens
working-directory: ./performance-tests/tax-report/src
run: ./k6 run ../../generate-tokens/src/generate-tokens.js
env:
env: ${{ secrets.YTENVIRONMENT }}
tokengenuser: ${{ secrets.TOKENGENUSER }}
tokengenuserpwd: ${{ secrets.TOKENGENPWD }}
limit: 1

- name: Setup K6
uses: grafana/setup-k6-action@v1

- name: Run local k6 test
uses: grafana/run-k6-action@v1
with:
path: performance-tests/t3search/src/t3search.js
flags: --vus=1 --iterations=1
env:
subscription_key: ${{ secrets.SUBSCRIPTION_KEY }}


2 changes: 1 addition & 1 deletion .github/workflows/taxreport-loadtest-ondemand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Run k6 to generate tokens
working-directory: ./performance-tests/tax-report/src
run: ./k6 run generate-tokens.js
run: ./k6 run ../../generate-tokens/src/generate-tokens.js
env:
env: ${{ secrets.YTENVIRONMENT }}
tokengenuser: ${{ secrets.TOKENGENUSER }}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/taxreport-loadtest-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: Run k6 to generate tokens
working-directory: ./performance-tests/tax-report/src
run: ./k6 run generate-tokens.js
run: ./k6 run ../../generate-tokens/src/generate-tokens.js
env:
env: ${{ secrets.YTENVIRONMENT }}
tokengenuser: ${{ secrets.TOKENGENUSER }}
Expand All @@ -45,8 +45,6 @@ jobs:
path: performance-tests/tax-report/src/tax-report.js
flags: --vus=1 --iterations=1
env:
K6_WEB_DASHBOARD: true
K6_WEB_DASHBOARD_EXPORT: html-report.html
serviceowner: ${{ secrets.OWNER }}


2 changes: 1 addition & 1 deletion .github/workflows/taxreport-loadtest-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- name: Run k6 to generate tokens
working-directory: ./performance-tests/tax-report/src
run: ./k6 run generate-tokens.js
run: ./k6 run ../../generate-tokens/src/generate-tokens.js
env:
env: ${{ secrets.YTENVIRONMENT }}
tokengenuser: ${{ secrets.TOKENGENUSER }}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const environment = __ENV.env.toLowerCase();
const tokenGeneratorUserName = __ENV.tokengenuser;
const tokenGeneratorUserPwd = __ENV.tokengenuserpwd;
const limit = (__ENV.limit === undefined ? 0 : __ENV.limit);
const ttl = (__ENV.ttl === undefined ? 3600 : __ENV.ttl)

const filepath = 'data-with-tokens.csv';
const idKeys = new SharedArray('idKeys', function () {
Expand All @@ -18,7 +19,7 @@ export const options = {
vus: 1,
};

export default function(data) {
export default function() {
file.writeString(filepath, 'userId,partyId,ssn,token');
var count = 0
for (const idKey of idKeys) {
Expand All @@ -27,7 +28,7 @@ export default function(data) {
userId: idKey.userid,
partyId: idKey.partyid,
pid: idKey.ssn,
ttl: 3600*24*10,
ttl: ttl
};
var token = generateToken(tokenGeneratorUserName, tokenGeneratorUserPwd, tokenGenParams);
file.appendString(filepath, `\n${idKey.userid},${idKey.partyid},${idKey.ssn},${token}`);
Expand Down
81 changes: 81 additions & 0 deletions performance-tests/t3search/src/t3search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import http from 'k6/http';
import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
import { SharedArray } from 'k6/data';
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.2/index.js';
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";

const idKeys = new SharedArray('idKeys', function () {
return papaparse.parse(open('data-with-tokens.csv'), { header: true }).data;
});

const subscription_key = __ENV.subscription_key;

export const options = {
discardResponseBodies: true,
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'p(99.5)', 'p(99.9)', 'count'],
thresholds: {
http_req_failed: ['rate<0.01'],
},

};

export function setup() {
var data = {
searchUrlYt: `https://platform.yt01.altinn.cloud/storage/api/v1/sbl/instances/search`,
idKeys: []
};

for (const idKey of idKeys) {
data.idKeys.push({
partyId: idKey.partyId,
userId: idKey.userId,
ssn: idKey.ssn,
token: idKey.token
});
if ((options.vus === undefined || options.vus === 1) && (options.iterations === undefined || options.iterations === 1)) {
break;
}
};
return data;
}

export default function(data) {
if ((options.vus === undefined || options.vus === 1) && (options.iterations === undefined || options.iterations === 1)) {
search(data, data.idKeys[0]);
}
else {
while (true) { search(data, randomItem(data.idKeys)); }
}
}

export function search(data, id) {
var query =
{
Language: 'nb',
InstanceOwnerPartyIdList: [ id.partyId ],
FromCreated: new Date(2018, 12, 12),
ToCreated: new Date(2099, 1, 1),
IncludeActive: false,
IncludeArchived: true
};

var params = {
headers: {
Authorization: 'Bearer ' + id.token,
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': subscription_key
},
}

var request_body = JSON.stringify(query)
http.post(data.searchUrlYt, request_body, params);
}

export function handleSummary(data) {
return {
'stdout': textSummary(data, { indent: ' ', enableColors: true }),
'stdout.txt': textSummary(data, { indent: ' ', enableColors: true }),
"summary.html": htmlReport(data),
};
}

0 comments on commit cc540ec

Please sign in to comment.