-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from phymbert/hp/headers-support
fix request headers not passed
- Loading branch information
Showing
6 changed files
with
97 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
import sse from "k6/x/sse"; | ||
import {check} from "k6"; | ||
import sse from "k6/x/sse" | ||
import {check} from "k6" | ||
|
||
export default function () { | ||
var url = "https://echo.websocket.org/.sse"; | ||
var params = {"tags": {"my_tag": "hello"}}; | ||
const url = "https://echo.websocket.org/.sse" | ||
const params = { | ||
method: 'GET', | ||
headers: { | ||
"Authorization": "Bearer XXXX" | ||
}, | ||
tags: {"my_k6s_tag": "hello sse"} | ||
} | ||
|
||
var response = sse.open(url, params, function (client) { | ||
client.on('open', function open() { | ||
console.log('connected'); | ||
}); | ||
const response = sse.open(url, params, function (client) { | ||
client.on('open', function open() { | ||
console.log('connected') | ||
}) | ||
|
||
client.on('event', function (event) { | ||
console.log(`event id=${event.id}, name=${event.name}, data=${event.data}`); | ||
if (parseInt(event.id) === 10) { | ||
client.close(); | ||
} | ||
}); | ||
client.on('event', function (event) { | ||
console.log(`event id=${event.id}, name=${event.name}, data=${event.data}`) | ||
if (parseInt(event.id) === 4) { | ||
client.close() | ||
} | ||
}) | ||
|
||
client.on('error', function (e) { | ||
console.log('An unexpected error occurred: ', e.error()); | ||
}); | ||
}); | ||
client.on('error', function (e) { | ||
console.log('An unexpected error occurred: ', e.error()) | ||
}) | ||
}) | ||
|
||
check(response, {"status is 200": (r) => r && r.status === 200}); | ||
}; | ||
check(response, {"status is 200": (r) => r && r.status === 200}) | ||
} |
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,25 @@ | ||
import sse from "k6/x/sse"; | ||
import {check} from "k6"; | ||
|
||
export default function () { | ||
const url = "https://echo.websocket.org/.sse"; | ||
const params = { | ||
method: 'POST', | ||
body: '{"ping": true}', | ||
headers: { | ||
"content-type": "application/json", | ||
"Authorization": "Bearer XXXX" | ||
} | ||
} | ||
|
||
const response = sse.open(url, params, function (client) { | ||
client.on('event', function (event) { | ||
console.log(`event id=${event.id}, name=${event.name}, data=${event.data}`); | ||
if (parseInt(event.id) === 2) { | ||
client.close() | ||
} | ||
}) | ||
}) | ||
|
||
check(response, {"status is 200": (r) => r && r.status === 200}) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#!/bin/bash | ||
|
||
xk6 build --with github.com/phymbert/xk6-sse=. && ./k6 run --vus 5 --duration 10s examples/sse.js | ||
set -eux | ||
|
||
xk6 build --with github.com/phymbert/xk6-sse=. | ||
for script in examples/* | ||
do | ||
./k6 run --vus 5 --duration 10s "${script}" | ||
done |