Skip to content

Commit

Permalink
Add stress and spike tests for rampingArrivalRate
Browse files Browse the repository at this point in the history
  • Loading branch information
MushtabaA committed Mar 16, 2024
1 parent 39ea576 commit ce957f7
Show file tree
Hide file tree
Showing 4 changed files with 740 additions and 11 deletions.
148 changes: 148 additions & 0 deletions scripts/rampingArrivalRate/spikeTests/scenario1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import http from 'k6/http';
import { group, sleep } from 'k6';

const BASE_URL = `http://${__ENV.HOST || 'localhost'}:8080/tools.descartes.teastore.webui`;

const groupResponseTimes = {};

export const options = {
discardResponseBodies: true,
scenarios: {
stressTest: {
executor: 'ramping-arrival-rate',

// Start `startRate` iterations per second
timeUnit: '1s',

// Pre-allocate necessary VUs.
preAllocatedVUs: 100,

stages: [

{ target: 10, duration: '40s' },

{ target: 80, duration: '20s' },

{ target: 10, duration: '40s' },

{ target: 100, duration: '20s' },

{ target: 10, duration: '20s' },
],
},
},
};

export default function () {
group('TeaStore Homepage', () => {
getTeaStoreHomepage();
});
group('TeaStore Login', () => {
getLogin();
});

group('TeaStore Login Action', () => {
const loginActionPayload = {
"referer": "http://10.1.9.58:8080/tools.descartes.teastore.webui/",
"username": "user",
"password": "password",
"signin": "Sign in",
};

postLoginAction(loginActionPayload);
});

group('TeaStore Login', () => {
getLogin();
});

group('TeaStore Login Action', () => {
const loginActionPayload = {
"referer": "http://10.1.9.58:8080/tools.descartes.teastore.webui/",
"username": "user2",
"password": "password",
"signin": "Sign in",
};

postLoginAction(loginActionPayload);
});
group('TeaStore Homepage', () => {
getTeaStoreHomepage();
});
group('TeaStore Herbal Tea Browse', () => {
getTeaStoreProductBrowse("4");
});
group('TeaStore Rooibos Tea Browse', () => {
getTeaStoreProductBrowse("5");
});
group('TeaStore White Tea Browse', () => {
getTeaStoreProductBrowse("6");
});
group('TeaStore View Profile', () => {
const start = new Date();
http.get(`${BASE_URL}/profile`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore View Profile'] = (groupResponseTimes['TeaStore View Profile'] || 0) + duration;
sleep(1);
});
group('TeaStore Login Action', () => {
const loginActionPayload = {
"logout": "",
};

postLoginAction(loginActionPayload);
});
group('TeaStore Homepage', () => {
getTeaStoreHomepage();
});
}

export function handleSummary() {
console.log("\nResponse times by group:");
for (const groupName in groupResponseTimes) {
console.log(` ${groupName}: ${groupResponseTimes[groupName]} ms`);
}
}


// ! Helper Functions for the Login Action
const getTeaStoreHomepage = () => {
const start = new Date();
http.get(`${BASE_URL}/`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Homepage'] = (groupResponseTimes['TeaStore Homepage'] || 0) + duration;
}

const postLoginAction = (payload) => {
const start = new Date();

http.post(`${BASE_URL}/loginAction`, payload, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}
);

const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore CRUD Login'] = (groupResponseTimes['TeaStore CRUD Login'] || 0) + duration;
// sleep(1); Instant
}

const getLogin = () => {
const start = new Date();
http.get(`${BASE_URL}/login`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Login'] = (groupResponseTimes['TeaStore Login'] || 0) + duration;
sleep(1);
}

const getTeaStoreProductBrowse = (categoryNumber) => {
const start = new Date();
http.get(`${BASE_URL}/category?category=${categoryNumber}&page=1`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Product Browse'] = (groupResponseTimes['TeaStore Product Browse'] || 0) + duration;
sleep(1);
}
238 changes: 238 additions & 0 deletions scripts/rampingArrivalRate/spikeTests/scenario2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
import http from 'k6/http';
import { group, sleep } from 'k6';

const BASE_URL = `http://${__ENV.HOST || 'localhost'}:8080/tools.descartes.teastore.webui`;

const groupResponseTimes = {};

export const options = {
discardResponseBodies: true,
scenarios: {
stressTest: {
executor: 'ramping-arrival-rate',

// Start `startRate` iterations per second
timeUnit: '1s',

// Pre-allocate necessary VUs.
preAllocatedVUs: 100,

stages: [

{ target: 10, duration: '40s' },

{ target: 80, duration: '20s' },

{ target: 10, duration: '40s' },

{ target: 100, duration: '20s' },

{ target: 10, duration: '20s' },
],
},
},
};

export default function () {

group('TeaStore Login', () => {
const start = new Date();
http.get(`${BASE_URL}/login`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Login'] = (groupResponseTimes['TeaStore Login'] || 0) + duration;
// sleep(1); Instant
});

group('TeaStore Login User', () => {
const start = new Date();

const loginActionPayload = {
"referer": "http://10.1.9.58:8080/tools.descartes.teastore.webui/",
"username": "user2",
"password": "password",
"signin": "Sign in"
};

http.post(`${BASE_URL}/loginAction`, loginActionPayload, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}
);

const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Login User'] = (groupResponseTimes['TeaStore Login User'] || 0) + duration;
// sleep(1); Instant
});

group('TeaStore Homepage', () => {
const start = new Date();
http.get(`${BASE_URL}/`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Homepage'] = (groupResponseTimes['TeaStore Homepage'] || 0) + duration;
sleep(1);
});

group('TeaStore Black Tea Page', () => {
const start = new Date();
http.get(`${BASE_URL}/category?category=2&page=1`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Black Tea Page'] = (groupResponseTimes['TeaStore Black Tea Page'] || 0) + duration;
sleep(1);
});

group('TeaStore Green Tea Page', () => {
const start = new Date();
http.get(`${BASE_URL}/category?category=3&page=1`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Green Tea Page'] = (groupResponseTimes['TeaStore Green Tea Page'] || 0) + duration;
sleep(1);
});

group('TeaStore Add to Cart', () => {
const cartActionPayload = {
"productid": 107,
"addToCart": "Add to Cart"
};

postCartAction(cartActionPayload);
});

group('TeaStore Cart', () => {
getCart();
});

group('TeaStore Black Tea Page', () => {
const start = new Date();
http.get(`${BASE_URL}/category?category=2&page=1`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Black Tea Page'] = (groupResponseTimes['TeaStore Black Tea Page'] || 0) + duration;
sleep(1);
});

group('TeaStore Add to Cart', () => {
const cartActionPayload = {
"productid": 7,
"addToCart": "Add to Cart"
};

postCartAction(cartActionPayload);
});

group('TeaStore Cart', () => {
getCart();
});

group('TeaStore Update Cart', () => {
const updateCartActionPayload = {
"productid": 107,
"orderitem_107": 1,
"productid": 7,
"orderitem_7": 2,
"updateCartQuantities": "Update Cart"
};

postCartAction(updateCartActionPayload);
});

group('TeaStore Cart', () => {
getCart();
});

group('TeaStore Remove Cart', () => {
const removeCartActionPayload = {
"productid": 107,
"orderitem_107": 1,
"removeProduct_107": "",
"productid": 7,
"orderitem_7": 2
};

postCartAction(removeCartActionPayload);
});

group('TeaStore Cart', () => {
getCart();
});

group('TeaStore Payment', () => {
const paymentActionPayload = {
"firstname": "Jon",
"lastname": "Snow",
"address1": "Winterfell",
"address2": "11111 The North, Westeros",
"cardtype": "volvo",
"cardnumber": "314159265359",
"expirydate": "12/2025",
"confirm": "Confirm"
};

postCartAction(paymentActionPayload);
});


group('TeaStore Order', () => {
const start = new Date();
http.get(`${BASE_URL}/order`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Order'] = (groupResponseTimes['TeaStore Order'] || 0) + duration;
sleep(1);
});

group('TeaStore Proceed to Checkout', () => {
const checkoutActionPayload = {
"productid": 7,
"orderitem_7": 2,
"proceedtoCheckout": "Proceed to Checkout"
};

postCartAction(checkoutActionPayload);
});


group('TeaStore Homepage', () => {
const start = new Date();
http.get(`${BASE_URL}/`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Homepage'] = (groupResponseTimes['TeaStore Homepage'] || 0) + duration;
sleep(1);
});
}

export function handleSummary(data) {
console.log("\nResponse times by group:");
for (const groupName in groupResponseTimes) {
console.log(` ${groupName}: ${groupResponseTimes[groupName]} ms`);
}
}


// ! Helper Functions
const postCartAction = (payload) => {
const start = new Date();

http.post(`${BASE_URL}/cartAction`, payload, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}
);

const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore CRUD Cart'] = (groupResponseTimes['TeaStore CRUD Cart'] || 0) + duration;
// sleep(1); Instant
}

const getCart = () => {
const start = new Date();
http.get(`${BASE_URL}/cart`);
const end = new Date();
const duration = end - start;
groupResponseTimes['TeaStore Cart'] = (groupResponseTimes['TeaStore Cart'] || 0) + duration;
sleep(1);
}
Loading

0 comments on commit ce957f7

Please sign in to comment.