Git Product home page Git Product logo

k6modular's Introduction

Modularizing k6 scripts

To avoid confusions while working on performance tests with k6 I like to modularize them. This gives an easy way to first use modular scripts in a continuous delivery way, without doing BALTs (Big Ass Load Test) which stop or at least slow down the pipeline. Never use a BALT in a pipeline.

If you use modular scripts which call a single API or test case, you can later re use them in larger load tests. The aforementioned BALT.

Actually Carvana used something like this. Not sure exactly how they did it, but the concept is the same. If you are interested take a look here --> https://k6.io/case-study-carvana/

What I am gonna teach you here is not the ONLY way, the best practice ever to rule them all the best practices. NO. This is just my way and a suggestion.

This works similarly to how LoadRunner organizes scripts.

Process separation

If you keep all your processes and load test patterns in a single file, things can get messy pretty quick.

In this example you separate one file per each process or API. This makes it easier if you have a team working on many processes at the same time.

You then put in a different file the load test logic, just invoking all the files for each of the processes.

How to divide them

As you can see here in the example I have the whole performance test kit in a single folder: k6Execution There you will find the k6 script that controls the BALT named mainScenario.js and a folder with the isolated modular scripts named processes.

Inside of processes you will find a k6 script for each business process or in this case for each API.

Considerations for it to work

There are a few things you must be careful for this to work.

  • The modular scripts should not be running the logic inside the default function.
  • The modular script steps must be inside of an export function which you can call in the default function.
  • You can run the modular script by itself.
  • Import your scripts in the BALT scenario script.
  • Create a function for each modular script and call it inside of the function.
  • Create your scenarios in the export options and select the load patterns for each modular script inside of the scenario options.

Voila! This should give you some guides on how to run things.

I will be working a bit more on this later but comments, PR's, and issues are welcome! -Besos, Leandro

k6modular's People

Contributors

srperf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.