-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test for search and refactored a bit
- Loading branch information
Showing
8 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
} |