k6utils

package module
v0.0.0-...-3ecfdfb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

k6utils

A bunch of random functions for k6 performance testing that I found missing, but useful in our work.

Compile for development

xk6 build v0.50.0 \
  --with github.com/b4dc0d3rs/k6-utils=.

./k6 run k6utils.js

Use

Just import:

import k6utils from 'k6/x/k6utils';

sleepMilliseconds

k6utils.sleepMilliseconds(666);

CSV operator

A native CSV operator that loads all CSV records to a map in memory. Empty lines are skipped. Header in the CSV file is mandatory for mapping purposes.

const data = k6utils.load('data.csv', ',');
data[0].csvColumnName;
CSV random record

Returns random record from the CSV map. Load

const allRows = k6utils.load('data.csv', ',');

// a row can be returned many times
const oneRandomRow = k6utils.takeRandomRow();

const row5 = k6utils.takeRowByIndex(4)

// this method removes polled row from in-memory cache
// each row is returned only once. The item is removed from in-memory cache before returning.
const uniqueRandomRow = k6utils.pollRandomRow();
Expiring cache

There is one global in-memory cache that evicts KV set after pre-configured number of seconds since insertion passed.

// configure it in setup method
k6utils.createCacheWithExpiryInSeconds(1)

// insert anything anytime
k6utils.putToCache('key', 'value')

// get anywhere anytime, even in a different method
k6utils.getFromCache('key')

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type K6Utils

type K6Utils struct {
	// contains filtered or unexported fields
}

func (*K6Utils) CreateCacheWithExpiryInSeconds

func (k6utils *K6Utils) CreateCacheWithExpiryInSeconds(durationInSeconds int)

func (*K6Utils) GetFromCache

func (k6utils *K6Utils) GetFromCache(key string) interface{}

func (*K6Utils) Load

func (k6utils *K6Utils) Load(filePath string, separator []byte) (interface{}, error)

func (*K6Utils) PollRandomRow

func (k6utils *K6Utils) PollRandomRow() (map[string]string, error)

func (*K6Utils) PutToCache

func (k6utils *K6Utils) PutToCache(key string, value string)

func (*K6Utils) RemoveFromCache

func (k6utils *K6Utils) RemoveFromCache(key string)

func (*K6Utils) SleepMilliseconds

func (c *K6Utils) SleepMilliseconds(sleepMilliseconds int)

func (*K6Utils) TakeRandomRow

func (k6utils *K6Utils) TakeRandomRow() (map[string]string, error)

func (*K6Utils) TakeRowByIndex

func (k6utils *K6Utils) TakeRowByIndex(index int) (map[string]string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL