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

Test(files)/add performance tests #19

Merged
merged 22 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
72759a4
test: add performance tests for files
JLSRKonk Feb 20, 2023
e4e7ec1
test: add powershell script to run all performance tests
JLSRKonk Feb 20, 2023
71106c1
test: add multiple test sizes
JLSRKonk Feb 20, 2023
8ab93aa
test: change multiple test sizes implementation
JLSRKonk Feb 21, 2023
28da4e5
test: implement review changes
JLSRKonk Feb 22, 2023
4f5dc50
test: fix shell script pathing
JLSRKonk Feb 22, 2023
6df8b3c
Merge branch 'main' into test(files)/performance-tests
JLSRKonk Feb 22, 2023
dd93a5b
test: change run-all scripts webpack call
JLSRKonk Feb 22, 2023
461553d
test: implement review changes
JLSRKonk Feb 22, 2023
52e2bc3
test: ran prettier on test files
JLSRKonk Feb 22, 2023
e744519
test: change translateSize() function name to size()
JLSRKonk Feb 23, 2023
094e3d8
test: add validation for environment variables
JLSRKonk Feb 23, 2023
5f92f26
test: strongly type setup() function
JLSRKonk Feb 23, 2023
3975823
test: strongly type remaining functions
JLSRKonk Feb 23, 2023
babb9cc
test: change parameter validation abort message
JLSRKonk Feb 24, 2023
dfc6918
test: move shared objects to utils.ts
JLSRKonk Feb 24, 2023
0463c7f
test: simplify authToken header
JLSRKonk Feb 27, 2023
7bd45fa
test: create getConfiguration() function for env values
JLSRKonk Feb 27, 2023
fdaf4ad
test: merge getConfiguration() and assertAllRequiredEnvVarsExist()
JLSRKonk Feb 27, 2023
fa7a8a5
test: fix getAuthorizationHeader() function name
JLSRKonk Feb 27, 2023
93182c0
test: refactor getConfiguration(), change USERNAME variable to USER
JLSRKonk Feb 27, 2023
741f3dd
test: fix previous commit
JLSRKonk Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

ci.conf
out.yaml

#Performance Tests
dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["@babel/env", "@babel/typescript"],
"plugins": [
"@babel/proposal-class-properties",

"@babel/proposal-object-rest-spread"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "https://jslib.k6.io/k6chaijs/4.3.4.2/index.js";
7,082 changes: 7,082 additions & 0 deletions Modules/Files/test/Files.API.Tests.Performance.EndToEnd/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "performance-test-files",
"license": "MIT",
"devDependencies": {
"@babel/core": "7.13.16",
"@babel/plugin-proposal-class-properties": "7.13.0",
"@babel/plugin-proposal-object-rest-spread": "7.13.8",
"@babel/preset-env": "7.13.15",
"@babel/preset-typescript": "7.13.0",
"@types/k6": "~0.41.0",
"@types/webpack": "5.28.0",
"babel-loader": "8.2.2",
"clean-webpack-plugin": "4.0.0-alpha.0",
"copy-webpack-plugin": "^9.0.1",
"k6-expect": "^0.0.15",
"prettier": "2.8.4",
"typescript": "4.2.4",
"webpack": "^5.75.0",
"webpack-cli": "4.6.0",
"webpack-glob-entries": "^1.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"endOfLine": "lf",
"printWidth": 120,
"tabWidth": 4,
"trailingComma": "none",
"semi": true,
"overrides": [
{
"files": ["*.yaml", "*.yml"],
"options": {
"tabWidth": 2
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Param(
[parameter(Mandatory)] $baseUrl,
[parameter(Mandatory)] $user,
[parameter(Mandatory)] $password,
[parameter(Mandatory)] $size
)

Write-Host "Running files performance tests..."

npm install
npx webpack

Get-ChildItem -Path "./dist" -Filter *.test.js |

Foreach-Object {
k6 run -e HOST=$baseUrl -e USER=$user -e PASSWORD=$password -e CLIENT_SECRET=test -e SIZE=$size $_.FullName
}

Write-Host "OK"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
while getopts h:u:p:s: opt
do
case $opt in
h) BASEURL=$OPTARG ;;
u) USER=$OPTARG ;;
p) PASSWORD=$OPTARG ;;
s) SIZE=$OPTARG ;;
esac
done

echo "Running files performance tests..."

npm install
npx webpack

for file in "./dist/"*.test.js ; do
k6 run -e HOST=$BASEURL -e USER=$USER -e PASSWORD=$PASSWORD -e CLIENT_SECRET=test -e SIZE=$SIZE $file
done

echo "OK"
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import http from "k6/http";
import { Options } from "k6/options";
import {
describe,
expect,
} from "https://jslib.k6.io/k6chaijs/4.3.4.2/index.js";
import {
getAuthorizationHeader,
getConfiguration,
Size,
tomorrow,
} from "./utils";

const configuration = getConfiguration();

const apiEndpoint = configuration.Host + "/api/v1";

interface Data {
authToken: string;
fileId: string;
}

function size(): Size {
switch (configuration.Size) {
case "S":
return { vus: 1, iterations: 10 };
case "M":
return { vus: 10, iterations: 50 };
case "L":
return { vus: 50, iterations: 100 };
default:
throw new Error("Invalid 'Size' value: " + configuration.Size);
}
}

export const options: Options = {
vus: size().vus,
thresholds: {
http_req_duration: ["p(90)<160", "p(98)<190"],
},
iterations: size().iterations,
};

export function setup(): Data {
const authToken = getAuthorizationHeader(configuration);

const bodyFileContent = {
content: http.file(
"For performance testing purposes.",
"PerformanceTest.txt"
),
cipherHash: "AAAA",
expiresAt: tomorrow().toJSON().slice(0, 10),
encryptedProperties: "AAAA",
};

const fileId = http
.post(`${apiEndpoint}/Files`, bodyFileContent, {
headers: {
Authorization: authToken,
},
})
.json("result.id")!
.toString();

return {
authToken: authToken,
fileId: fileId,
};
}

export default function (data: Data): void {
describe("Download a file:", () => {
const response = http.get(`${apiEndpoint}/Files/${data.fileId}`, {
headers: {
Authorization: data.authToken,
},
});

expect(response.status, "response status").to.equal(200);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import http from "k6/http";
import { Options } from "k6/options";
import {
describe,
expect,
} from "https://jslib.k6.io/k6chaijs/4.3.4.2/index.js";
import {
getAuthorizationHeader,
getConfiguration,
Size,
tomorrow,
} from "./utils";

const configuration = getConfiguration();

const apiEndpoint = configuration.Host + "/api/v1";

interface Data {
authToken: string;
fileId: string;
}

function size(): Size {
switch (configuration.Size) {
case "S":
return { vus: 1, iterations: 10 };
case "M":
return { vus: 10, iterations: 50 };
case "L":
return { vus: 50, iterations: 100 };
default:
throw new Error("Invalid 'Size' value: " + configuration.Size);
}
}

export const options: Options = {
vus: size().vus,
thresholds: {
http_req_duration: ["p(90)<50", "p(98)<100"],
},
iterations: size().iterations,
};

export function setup(): Data {
const authToken = getAuthorizationHeader(configuration);

const bodyFileContent = {
content: http.file(
"For performance testing purposes.",
"PerformanceTest.txt"
),
cipherHash: "AAAA",
expiresAt: tomorrow().toJSON().slice(0, 10),
encryptedProperties: "AAAA",
};

const fileId = http
.post(`${apiEndpoint}/Files`, bodyFileContent, {
headers: {
Authorization: authToken,
},
})
.json("result.id")!
.toString();

return {
authToken: authToken,
fileId: fileId,
};
}

export default function (data: Data): void {
describe("Get a File metadata:", () => {
const response = http.get(`${apiEndpoint}/Files/${data.fileId}/metadata`, {
headers: {
Authorization: data.authToken,
},
});

expect(response.status, "response status").to.equal(200);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import http from "k6/http";
import { Options } from "k6/options";
import {
describe,
expect,
} from "https://jslib.k6.io/k6chaijs/4.3.4.2/index.js";
import { getAuthorizationHeader, getConfiguration, Size } from "./utils";

const configuration = getConfiguration();

const apiEndpoint = configuration.Host + "/api/v1";

interface Data {
authToken: string;
}

function size(): Size {
switch (configuration.Size) {
case "S":
return { vus: 1, iterations: 10 };
case "M":
return { vus: 10, iterations: 50 };
case "L":
return { vus: 50, iterations: 100 };
default:
throw new Error("Invalid 'Size' value: " + configuration.Size);
}
}

export const options: Options = {
vus: size().vus,
thresholds: {
http_req_duration: ["p(90)<50", "p(98)<100"],
},
iterations: size().iterations,
};

export function setup(): Data {
return { authToken: getAuthorizationHeader(configuration) };
}

export default function (data: Data): void {
describe("Get list of Files:", () => {
const response = http.get(`${apiEndpoint}/Files`, {
headers: {
Authorization: data.authToken,
},
});

expect(response.status, "response status").to.equal(200);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import http from "k6/http";
import { Options } from "k6/options";
import {
describe,
expect,
} from "https://jslib.k6.io/k6chaijs/4.3.4.2/index.js";
import {
getAuthorizationHeader,
getConfiguration,
Size,
tomorrow,
} from "./utils";

const configuration = getConfiguration();

const apiEndpoint = configuration.Host + "/api/v1";

interface Data {
authToken: string;
}

function size(): Size {
switch (configuration.Size) {
case "S":
return { vus: 1, iterations: 1 };
case "M":
return { vus: 2, iterations: 5 };
case "L":
return { vus: 3, iterations: 10 };
default:
throw new Error("Invalid 'Size' value: " + configuration.Size);
}
}

export const options: Options = {
vus: size().vus,
thresholds: {
http_req_duration: ["p(90)<160", "p(98)<190"],
},
iterations: size().iterations,
};

export function setup(): Data {
return { authToken: getAuthorizationHeader(configuration) };
}

export default function (data: Data): void {
describe("Upload a File with Authentication:", () => {
const bodyFileContent = {
content: http.file(
"For performance testing purposes.",
"PerformanceTest.txt"
),
cipherHash: "AAAA",
expiresAt: tomorrow().toJSON().slice(0, 10),
encryptedProperties: "AAAA",
};

const response = http.post(`${apiEndpoint}/Files`, bodyFileContent, {
headers: {
Authorization: data.authToken,
},
});

expect(response.status, "response status").to.equal(201);
});
}
Loading