From cd254158a784d3c70010e518a5c0bcc54bfb129f Mon Sep 17 00:00:00 2001 From: Kevin Abrar Khansa <kevariable@gmail.com> Date: Sun, 29 Dec 2024 16:43:21 +0700 Subject: [PATCH] Update threshold --- k6/src/scenarios.js | 5 +++++ k6/src/supports/contact.js | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/k6/src/scenarios.js b/k6/src/scenarios.js index 81d950c..16e0f8b 100644 --- a/k6/src/scenarios.js +++ b/k6/src/scenarios.js @@ -4,6 +4,11 @@ import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js'; import { vu } from 'k6/execution' export const options = { + thresholds: { + create_contact_counter_success: ['count>190'], + create_contact_counter_err: ['count<10'] + }, + scenarios: { createContacts: { exec: 'createContacts', diff --git a/k6/src/supports/contact.js b/k6/src/supports/contact.js index e911d97..ae04cb3 100644 --- a/k6/src/supports/contact.js +++ b/k6/src/supports/contact.js @@ -1,5 +1,9 @@ import http from "k6/http"; import {check} from "k6"; +import {Counter} from "k6/metrics"; + +const createContactCounter = new Counter('create_contact_counter_success') +const createContactCounterError = new Counter('create_contact_counter_err') export const createContact = (createContactRequest, token) => { const createContact = http.post('http://app:3000/api/contacts', createContactRequest, { @@ -12,9 +16,18 @@ export const createContact = (createContactRequest, token) => { const createContactResponse = createContact.json() - check(createContact, { - 'response must be 200': createContact.status === 200, + 'response must be 200': () => { + const passed = createContact.status === 200 + + if (passed) { + createContactCounter.add(1) + } else { + createContactCounterError.add(1) + } + + return passed + }, 'response contains id': createContactResponse.data?.id !== undefined, }) } \ No newline at end of file