Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*To generate a log file e.g. k6 run the-best-tests.js --log-format raw --log-output=file="./log_$(((get-date).ToUniversalTime()).ToString("yyyyMMddTHHmmssZ")).txt"
- './outfile_en_GB.txt' is a plaiin text file with one 'address' per line (auto generated with Bogus), cut down to (poorly) emulate autocomplete strings.
- 585 Favian Flats, South Joe
- 015 Hermis
- 64348 Candace Corner, North Kirstin, Nor
- 8528
- 49202 Guiseppe Ranch, Beierha
- 8270 Krista Well,
- 1028 Braden Estate, Julietfor
- 2146 Hellen Key, S
- 78838 Rau Plaza, Port Gwenburgh
- 6532 Cleo Underpass, New Frankietown, Falkland Islands (Ma
- 76290 Rutherford Ranch, Lockmanhaven
- 28463 Erdman Meadow
- 8502 Levi Islands, Keny
- 51686 Ebony Stravenue, Ru
- 493 R
- 84928 Collier
- 6971 Hettinger Light, Taylorchester,
- 69877 Furman Ke
- 65374 Ansel Union, Ulicesbo
- 305 Zaria Glen, North Tessiel
- 50725 Tara Walks, Port Kor
- 054 Jacobs Light, Georgestad,
- 891
- 17310 Macejkovic View, South M
- 21439 Dayna Port, New Avishaven, Saint Kitt
- 9258 Dillan Viaduc
- 9998 Blanda Ov
- 9021 Clotilde Estate, Providenciburgh, Solomon Isla
- 3844 Domenick Plains, Port Berylchester, Th
- 35914 Li
- 07025 Ks
- */
- import { SharedArray } from 'k6/data';
- import { scenario } from 'k6/execution';
- import { check, fail }from 'k6'
- import http from 'k6/http';
- import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js';
- import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
- const textData = new SharedArray('AddressData', function () {
- return open('./outfile_en_GB.txt').split(/\r?\n/);
- });
- export const options = {
- scenarios: {
- 'use-all-the-data': {
- executor: 'shared-iterations',
- vus: 5,
- iterations: 100,//csvData.length,
- maxDuration: '30s',
- },
- }
- };
- export default function () {
- // this is unique even in the cloud
- const address = textData[scenario.iterationInTest];
- var flipBit = randomIntBetween(0,100);
- var urlStr = "https://httpstat.us/200";
- switch (true) {
- case (flipBit < 50 ):
- urlStr ="https://httpstat.us/200";
- break;
- case (flipBit <75):
- urlStr ="https://httpstat.us/418";
- break;
- case (flipBit < 90):
- urlStr ="https://httpstat.us/503";
- break;
- case (flipBit < 100):
- urlStr ="https://httpstat.us/404";
- break;
- }
- const url = new URL(urlStr );
- url.searchParams.append('address', address);
- const res = http.get(url.toString());
- if ( !check(res, {
- 'status code MUST be 200': (res) => res.status === 200,
- })
- ) {
- console.log(`${scenario.iterationInTest}, \"${address}\", ${res.url} , ${res.status}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement