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

Send batched events in smoke test #29

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 18 additions & 17 deletions testcases/smoke.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import http from 'k6/http';
import { sleep } from 'k6';
import { check } from 'k6';
import exec from 'k6/execution';
import encoding from 'k6/encoding';
import { randomString, randomItem, randomIntBetween, uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js'
Expand Down Expand Up @@ -131,18 +130,15 @@ function generateJSON(schema) {
return json;
}

function generateEvents() {
function generateEvents(num = 5) {
const events = [];
let numberOfSchemas = schemas();

if (!numberOfSchemas) {
numberOfSchemas = 5
}

let listOfSchema = generateOverlappingSchemas(numberOfSchemas);

// generate event of random schema from the list
events.push(generateJSON(listOfSchema[Math.floor(Math.random() * listOfSchema.length)]))
// generate event of random schema from the list
for (let index = 0; index < num; index++) {
events.push(generateJSON(listOfSchema[Math.floor(Math.random() * listOfSchema.length)]));
}

return events
}
Expand All @@ -163,15 +159,20 @@ export default function () {
}
}

let batch_requests = JSON.stringify(generateEvents());
let events = generateEvents(5);

let response = http.post(url, batch_requests, params);
// send all events batched
let batched_request = JSON.stringify(events);
let response = http.post(url, batched_request, params);

if (
!check(response, {
'status code MUST be 200': (res) => res.status == 200,
})
) {
exec.test.abort("Failed to send event.. status != 200. Last response was: " + response.error);
if (response.status != 200) {
exec.test.abort("Failed to send event.. status != 200");
}

// send a request per event
let responses = http.batch(events.map(event => ['POST', url, JSON.stringify(event), params]))

if (responses.some(res => res.status != 200)) {
exec.test.abort("Failed to send event.. status != 200");
}
}
2 changes: 1 addition & 1 deletion testcases/smoke_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ username=$3
password=$4

log_events=50
k6_log_events=6000
k6_log_events=60000
expectedCount=$((k6_log_events + log_events))

input_file=$PWD/input.json
Expand Down