Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(performance): Performance/create serviceowner search #1413

Merged
merged 9 commits into from
Nov 7, 2024
1 change: 1 addition & 0 deletions .github/workflows/dispatch-k6-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ on:
options:
- 'tests/k6/tests/serviceowner/performance/create-dialog.js'
- 'tests/k6/tests/serviceowner/performance/create-remove-dialog.js'
- 'tests/k6/tests/serviceowner/performance/serviceowner-search.js'
- 'tests/k6/tests/enduser/performance/enduser-search.js'
- 'tests/k6/tests/graphql/performance/graphql-search.js'

Expand Down
28 changes: 26 additions & 2 deletions tests/k6/tests/performancetest_common/simpleSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { randomItem, uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
import { expect, expectStatusFor } from "../../common/testimports.js";
import { describe } from '../../common/describe.js';
import { getEU, postGQ } from '../../common/request.js';
import { getEU, postGQ, getSO } from '../../common/request.js';
import { getGraphqlParty } from '../performancetest_data/graphql-search.js';


Expand All @@ -31,7 +31,7 @@ function retrieveDialogContent(response, paramsWithToken) {
}

/**
* Performs a simple search.
* Performs a enduser search.
* @param {Object} enduser - The end user.
* @returns {void}
*/
Expand Down Expand Up @@ -127,3 +127,27 @@ export function graphqlSearch(enduser) {
expect(r, 'response').to.have.validJsonBody();
});
}

/**
* Performs a serviceowner search.
* @param {P} serviceowner
* @param {*} enduser
*/
export function serviceownerSearch(serviceowner, enduser, tag_name) {
let paramsWithToken = {
headers: {
Authorization: "Bearer " + serviceowner.token,
traceparent: uuidv4()
},
tags: { name: tag_name }
}

let enduserid = encodeURIComponent(`urn:altinn:person:identifier-no:${enduser.ssn}`);
let serviceResource = encodeURIComponent(`urn:altinn:resource:${serviceowner.resource}`);
let defaultFilter = `?enduserid=${enduserid}&serviceResource=${serviceResource}`;
describe('Perform serviceowner dialog list', () => {
let r = getSO('dialogs' + defaultFilter, paramsWithToken);
expectStatusFor(r).to.equal(200);
expect(r, 'response').to.have.validJsonBody();
});
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
org,orgno,scopes,resource
digdir,991825827,digdir:dialogporten.serviceprovider,super-simple-service
digdir,991825827,digdir:dialogporten.serviceprovider digdir:dialogporten.serviceprovider.search,ttd-dialogporten-performance-test-01
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const options = {
},
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'p(99.5)', 'p(99.9)', 'count'],
thresholds: getDefaultThresholds(['http_req_duration', 'http_reqs'],[
'simple search',
'enduser search',
'create dialog',
'get dialog',
'get dialog activities',
Expand Down
4 changes: 2 additions & 2 deletions tests/k6/tests/scripts/generate_tokens.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ if [ "$tokens" = "both" ] || [ "$tokens" = "enterprise" ]; then
echo "org,orgno,scopes,resource,token" > $serviceowner_tokenfile
while IFS=, read -r org orgno scopes resource
do
url="https://altinn-testtools-token-generator.azurewebsites.net/api/GetEnterpriseToken?org=$org&env=$env&scopes=$scopes&orgno=$orgno&ttl=3600"
token=$(curl -s -f $url -u "$tokengenuser:$tokengenpasswd" )
url="https://altinn-testtools-token-generator.azurewebsites.net/api/GetEnterpriseToken?org=$org&env=$env&orgno=$orgno&ttl=3600"
token=$(curl -s -f --get --data-urlencode "scopes=$scopes" $url -u "$tokengenuser:$tokengenpasswd" )
if [ $? -ne 0 ]; then
echo "Error: Failed to generate enterprise token for: $env, $org, $orgno, $scopes "
continue
Expand Down
34 changes: 34 additions & 0 deletions tests/k6/tests/serviceowner/performance/serviceowner-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
import { serviceownerSearch } from '../../performancetest_common/simpleSearch.js'
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
import { serviceOwners ,endUsersWithTokens } from '../../performancetest_common/readTestdata.js';
dagfinno marked this conversation as resolved.
Show resolved Hide resolved

const tag_name = 'serviceowner search';

export let options = {
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'p(99.5)', 'p(99.9)', 'count'],
thresholds: getDefaultThresholds(['http_req_duration', 'http_reqs'],[tag_name])
};

/**
* Perform a service owner search.
* In single user mode, the first service owner and end user with token is used. Only one iteration is performed.
* In multi user mode, a random service owner and end user with token is used.
*/
export default function() {
if (!endUsersWithTokens || endUsersWithTokens.length === 0) {
throw new Error('No end users loaded for testing');
}
if (!serviceOwners || serviceOwners.length === 0) {
throw new Error('No service owners loaded for testing');
}

const isSingleUserMode = (options.vus ?? 1) === 1 && (options.iterations ?? 1) === 1 && (options.duration ?? 0) === 0;
if (isSingleUserMode) {
serviceownerSearch(serviceOwners[0], endUsersWithTokens[0], tag_name);
}
else {
serviceownerSearch(randomItem(serviceOwners), randomItem(endUsersWithTokens), tag_name);
}
}

Loading