Skip to content

Commit

Permalink
documentation performed by github copilot
Browse files Browse the repository at this point in the history
  • Loading branch information
dagfinno committed Nov 5, 2024
1 parent 088fc3c commit 5d13c27
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 14 deletions.
14 changes: 14 additions & 0 deletions tests/k6/tests/graphql/performance/graphql-search.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
/**
* The performance test for GraphQL search.
* Run: k6 run tests/k6/tests/graphql/performance/graphql-search.js --vus 1 --iterations 1 -e env=yt01
*/

import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
import { endUsersWithTokens as endUsers } from '../../performancetest_common/readTestdata.js';
import { graphqlSearch } from "../../performancetest_common/simpleSearch.js";

/**
* The options object for configuring the performance test for GraphQL search.
*
* @property {string[]} summaryTrendStats - The summary trend statistics to include in the test results.
* @property {object} thresholds - The thresholds for the test metrics.
*/
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'],['graphql search'])
};

/**
* The default function for the performance test for GraphQL search.
*/
export default function() {
if (!endUsers || endUsers.length === 0) {
throw new Error('No end users loaded for testing');
Expand Down
16 changes: 12 additions & 4 deletions tests/k6/tests/performancetest_common/createDialog.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Common functions for creating dialogs.
*/
import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
import { describe } from "../../common/describe.js";
import { postSO, purgeSO } from "../../common/request.js";
Expand All @@ -6,11 +9,10 @@ import dialogToInsert from "../performancetest_data/01-create-dialog.js";

/**
* Creates a dialog.
*
* @param {Object} serviceOwner - The service owner.
* @param {Object} endUser - The end user.
*
* @param {Object} serviceOwner - The service owner object.
* @param {Object} endUser - The end user object.
*/

export function createDialog(serviceOwner, endUser) {
var paramsWithToken = {
headers: {
Expand All @@ -27,6 +29,12 @@ export function createDialog(serviceOwner, endUser) {

}

/**
* Creates a dialog and removes it.
*
* @param {Object} serviceOwner - The service owner object.
* @param {Object} endUser - The end user object.
*/
export function createAndRemoveDialog(serviceOwner, endUser) {
var paramsWithToken = {
headers: {
Expand Down
2 changes: 0 additions & 2 deletions tests/k6/tests/performancetest_common/getDefaultThresholds.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* @returns {Object} Threshold configuration object
* @throws {Error} If inputs are invalid
*/


export function getDefaultThresholds(counters, labels) {
if (!Array.isArray(counters) || !Array.isArray(labels)) {
throw new Error('Both counters and labels must be arrays');
Expand Down
41 changes: 36 additions & 5 deletions tests/k6/tests/performancetest_common/readTestdata.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
/**
* This file contains the implementation of reading test data from CSV files.
* The test data includes service owners, end users, and end users with tokens.
* The data is read using the PapaParse library and stored in SharedArray variables.
*
* @module readTestdata
*/

import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';
import { SharedArray } from "k6/data";

const filenameServiceowners = '../performancetest_data/.serviceowners-with-tokens.csv';
export const serviceOwners = new SharedArray('serviceOwners', function () {
return papaparse.parse(open(filenameServiceowners), { header: true, skipEmptyLines: true }).data;
});

if (!__ENV.API_ENVIRONMENT) {
throw new Error('API_ENVIRONMENT must be set');
}
const filenameEndusers = `../performancetest_data/endusers-${__ENV.API_ENVIRONMENT}.csv`;
const filenameEndusersWithTokens = '../performancetest_data/.endusers-with-tokens.csv';

/**
* SharedArray variable that stores the service owners data.
* The data is parsed from the CSV file specified by the filenameServiceowners variable.
*
* @name serviceOwners
* @type {SharedArray}
*/
export const serviceOwners = new SharedArray('serviceOwners', function () {
return papaparse.parse(open(filenameServiceowners), { header: true, skipEmptyLines: true }).data;
});

/**
* SharedArray variable that stores the end users data.
* The data is parsed from the CSV file specified by the filenameEndusers variable.
* The filenameEndusers variable is dynamically generated based on the value of the API_ENVIRONMENT environment variable.
*
* @name endUsers
* @type {SharedArray}
*/
export const endUsers = new SharedArray('endUsers', function () {
return papaparse.parse(open(filenameEndusers), { header: true, skipEmptyLines: true }).data;
});

const filenameEndusersWithTokens = '../performancetest_data/.endusers-with-tokens.csv';
/**
* SharedArray variable that stores the end users with tokens data.
* The data is parsed from the CSV file specified by the filenameEndusersWithTokens variable.
*
* @name endUsersWithTokens
* @type {SharedArray}
*/
export const endUsersWithTokens = new SharedArray('endUsersWithTokens', function () {
return papaparse.parse(open(filenameEndusersWithTokens), { header: true, skipEmptyLines: true }).data;
});
Expand Down
5 changes: 5 additions & 0 deletions tests/k6/tests/performancetest_common/simpleSearch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* This file contains common functions for performing simple searches
* and GraphQL searches.
*/
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
import { expect, expectStatusFor } from "../../common/testimports.js";
import { describe } from '../../common/describe.js';
Expand Down Expand Up @@ -114,6 +118,7 @@ export function graphqlSearch(enduser) {
let paramsWithToken = {
headers: {
Authorization: "Bearer " + enduser.token,
traceparent: uuidv4()
},
tags: { name: 'graphql search' }
};
Expand Down
20 changes: 19 additions & 1 deletion tests/k6/tests/scenarios/performance/create-dialog-and-search.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
/**
* Performance test for creating dialogs and searching dialogs.
* Run: k6 run tests/k6/tests/scenarios/performance/create-dialog-and-search.js -e env=yt01 -e svus=1 -e evus=1 -e duration=1m
*/
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';

import { enduserSearch } from '../../performancetest_common/simpleSearch.js';
import { createDialog } from '../../performancetest_common/createDialog.js';
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
import { serviceOwners, endUsersWithTokens } from '../../performancetest_common/readTestdata.js';


/**
* Options for performance scenarios.
*
* @typedef {Object} Options
* @property {Object} scenarios - The performance scenarios.
* @property {Object} summaryTrendStats - The summary trend statistics.
* @property {Object} thresholds - The thresholds for performance metrics.
*/

/**
* Performance options.
*
* @type {Options}
*/
export const options = {
scenarios: {
create_dialogs: {
Expand Down
6 changes: 4 additions & 2 deletions tests/k6/tests/serviceowner/performance/create-dialog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Performance test for creating a dialog
* Run: k6 run tests/k6/tests/serviceowner/performance/create-dialog.js --vus 1 --iterations 1
*/
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';

import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
import { createDialog } from '../../performancetest_common/createDialog.js';
import { serviceOwners, endUsers } from '../../performancetest_common/readTestdata.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Performance test for creating and removing a dialog
* Run: k6 run tests/k6/tests/serviceowner/performance/create-remove-dialog.js --vus 1 --iterations 1
*/
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
import { serviceOwners, endUsers } from "../../performancetest_common/readTestdata.js";
Expand Down

0 comments on commit 5d13c27

Please sign in to comment.