-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
134 additions
and
13 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
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
4 changes: 2 additions & 2 deletions
4
src/performanceTest/scripts/healthCheck.js → ...formanceTest/scripts/check/healthCheck.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { check } from "k6"; | ||
import exec from 'k6/execution'; | ||
import Request from "../lib/request.js"; | ||
import hooks from "../lib/hooks.js"; | ||
import { encode } from "../lib/jwt.js"; | ||
|
||
export const setup = hooks.setup | ||
export const handleSummary = hooks.handleSummary | ||
|
||
export default function () { | ||
const req = new Request() | ||
|
||
const token = encode(1) | ||
req.setToken(token) | ||
|
||
const res = req.access_token_info() | ||
check(res, { "status == 200": (r) => r.status == 200 }); | ||
check(res, { "res has userId key": (r) => r.json().userId > 0 }); | ||
} |
8 changes: 4 additions & 4 deletions
8
...rformanceTest/scripts/reservationCheck.js → ...nceTest/scripts/check/reservationCheck.js
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
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,33 @@ | ||
import crypto from "k6/crypto"; | ||
import encoding from "k6/encoding"; | ||
import config from "./config.js"; | ||
|
||
// from https://github.com/grafana/k6/blob/master/examples/jwt.js | ||
|
||
const algToHash = { | ||
HS256: "sha256", | ||
HS384: "sha384", | ||
HS512: "sha512" | ||
}; | ||
|
||
function sign(data, hashAlg, secret) { | ||
let hasher = crypto.createHMAC(hashAlg, secret); | ||
hasher.update(data); | ||
|
||
return hasher.digest("base64").replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, ""); | ||
} | ||
|
||
export function encode(userid) { | ||
const NOW = Math.floor(Date.now() / 1000) | ||
const algorithm = "HS256"; | ||
let header = encoding.b64encode(JSON.stringify({ alg: algorithm }), "rawurl"); | ||
let payload = { | ||
sub: `${userid}`, | ||
iss: config.JWT_ISSUER, | ||
iat: NOW, | ||
exp: NOW + (60 * 60), | ||
} | ||
payload = encoding.b64encode(JSON.stringify(payload), "rawurl", "s"); | ||
let sig = sign(header + "." + payload, algToHash[algorithm], config.JWT_RAW_SECRET); | ||
return [header, payload, sig].join("."); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { check } from "k6"; | ||
import Request from "./lib/request.js"; | ||
import { encode } from "./lib/jwt.js"; | ||
import hooks from "./lib/hooks.js"; | ||
import { isSuccess, getOneFromList, randomInt } from "./lib/helpers.js"; | ||
import exec from 'k6/execution'; | ||
|
||
export const setup = hooks.setup | ||
export const handleSummary = hooks.handleSummary | ||
|
||
export const options = { | ||
tags: { | ||
testid: `${__ENV.ENTRYPOINT}` | ||
}, | ||
ext: { | ||
loadimpact: { | ||
apm: [ | ||
{ | ||
includeTestRunId: true, | ||
} | ||
] | ||
} | ||
}, | ||
scenarios: { | ||
contacts: { | ||
executor: 'per-vu-iterations', | ||
vus: 200, | ||
iterations: 1, | ||
maxDuration: '1m', | ||
}, | ||
}, | ||
|
||
thresholds: { | ||
http_req_failed: ['rate<0.01'], // http errors should be less than 1% | ||
http_req_duration: ['p(95)<200'], // 95% of requests should be below 100ms | ||
}, | ||
}; | ||
|
||
export default function () { | ||
const req = new Request() | ||
|
||
const getAvaliableReservation = () => { | ||
let count = 0 | ||
while (count < 10) { | ||
req.getEvents() | ||
count++ | ||
} | ||
const events = req.getEvents() | ||
return getOneFromList(events.json()) | ||
} | ||
|
||
req.setToken(encode(exec.vu.idInTest)) | ||
|
||
const event = getAvaliableReservation() | ||
if (event) { | ||
const res = req.createReservation({ | ||
eventId: event.id | ||
}) | ||
check(res, {"Success Reservation": isSuccess}); | ||
} | ||
} |