-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(tools+integrations): fix broken k6 guide (#39)
- Loading branch information
Adnan Rahić
authored
Mar 19, 2024
1 parent
cc02860
commit 119855e
Showing
4 changed files
with
88 additions
and
6 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 |
---|---|---|
|
@@ -16,3 +16,6 @@ cypress/downloads | |
/blob-report/ | ||
/playwright/.cache/ | ||
serverless/.env | ||
|
||
# k6 executable | ||
/k6 |
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,56 @@ | ||
import { Http, Tracetest } from "k6/x/tracetest"; | ||
import { sleep } from "k6"; | ||
|
||
export const options = { | ||
vus: 1, | ||
duration: "5s", | ||
}; | ||
|
||
const http = new Http(); | ||
const testId = "kc_MgKoVR"; | ||
const tracetest = Tracetest(); | ||
|
||
let pokemonId = 6; // charizard | ||
|
||
export default function () { | ||
const url = "http://localhost:8081/pokemon/import"; | ||
const payload = JSON.stringify({ | ||
id: pokemonId++, | ||
}); | ||
const params = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
tracetest: { | ||
testId, | ||
}, | ||
}; | ||
|
||
const response = http.post(url, payload, params); | ||
|
||
tracetest.runTest( | ||
response.trace_id, | ||
{ | ||
test_id: testId, | ||
variable_name: "TRACE_ID", | ||
should_wait: true, | ||
}, | ||
{ | ||
id: "123", | ||
url, | ||
method: "GET", | ||
} | ||
); | ||
|
||
sleep(1); | ||
} | ||
|
||
export function handleSummary() { | ||
return { | ||
stdout: tracetest.summary(), | ||
}; | ||
} | ||
|
||
export function teardown() { | ||
tracetest.validateResult(); | ||
} |
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,23 @@ | ||
type: Test | ||
spec: | ||
id: kc_MgKoVR | ||
name: K6 | ||
description: K6 | ||
trigger: | ||
type: traceid | ||
traceid: | ||
id: ${env:TRACE_ID} | ||
specs: | ||
- selector: span[tracetest.span.type="general" name="import pokemon"] | ||
name: Should have imported the pokemon | ||
assertions: | ||
- attr:tracetest.selected_spans.count = 1 | ||
- selector: |- | ||
span[tracetest.span.type="http" net.peer.name="pokeapi.co" http.method="GET"] | ||
name: Should trigger a request to the POKEAPI | ||
assertions: | ||
- attr:http.url = "https://pokeapi.co/api/v2/pokemon/6" | ||
- selector: span[tracetest.span.type="database" name="create postgres.pokemon"] | ||
name: Should insert the pokemon to the DB | ||
assertions: | ||
- attr:db.result | json_path '.name' = "charizard" |