Cloud developer testing with K6

Cloud developer testing with K6

nother important aspect of the testing is to verify that your application works also after development project ends. The base of this is done during the development of the application. If you start building proper testing scenarios during development, you can utilize that effort during maintenance period of the application.

I’m using K6 (https://k6.io/) for testing and in examples of this article.

Starting with K6

You can install open-source tool from K6 site and build your test scripts with JavaScript. I always run scripts with one user when building those. It’s lot easier to verify that everything is working as expected.

example.js

import http from 'k6/http'
import { sleep } from 'k6';

export default function () {
  http.get('https://test.k6.io');
  sleep(1);
 };        

You can now run script with following command:

k6 run .\example.js        

Load testing

Simple case

You can use load testing to know how your application works under stress (large volume of users). Using load testing, you will learn how your application works with different user volumes. It may allow you to optimize your cloud infrastructure and test how well your automatic scaling works. It also helps you to understand what the bottlenecks of the application are, so you can focus on improving those instead of focusing your efforts to parts of the application that already works.

k6 run .\example.js --vus 1 --duration 2s        

If we are using same script, we can utilize it easily in static load testing scenario by defining number of users (vus) and duration (2 seconds). As we are using K6 test service, we want to keep our load small.

Scenarios

If you want to control more granularly your scripts, you can use scenarios to define different types of the test to be run.


import http from 'k6/http'
import { sleep } from 'k6';

export const options = {
    scenarios: {
        first: {
            // name of the executor to use
            executor: 'shared-iterations',

            // common scenario configuration
            startTime: '10s',
            gracefulStop: '5s',
 
            // executor-specific configuration
            vus: 1,
            iterations: 1,
            maxDuration: '2s',
        },

       second: {
           // name of the executor to use
           executor: 'shared-iterations',

           // common scenaio configuration
           startTime: '15s',
           gracefulStop: '5s',

           // executor-specific configuration
           vus: 1,
           iterations: 1,
           maxDuration: '2s',
       },
   },
};


export default function () {
   http.get('https://test.k6.io');
   sleep(1);
};
        

Now you can execute script again with, because scenarios will control number of users and duration of the scripts. We want to keep our load small, so we are just using one user for short period of time.

k6 run .\example.js        

Scenarios are helpful if you need to run different tests simultaneously. For example, you can run constant load tests to API and simulate different use cases with another scenario. Note that "executor-specific configuration" is related to executor that you have defined. You can see all executors and their detailed information from https://k6.io/docs/using-k6/scenarios/executors/.

I will write more about using / abusing K6 in next Developer Tips. Next time I will focus on generating different tests and control behavior.

To view or add a comment, sign in

More articles by Jani Salomaa

  • Semantic Kernel ja internet

    Jotta pääsemme hieman pidemmälle agenttien maailmaan, tutkitaan tilannetta, jossa käyttäjä haluaa saada tietoa, jota…

  • Askel ”agenttien” maailmaan Semantic Kernelin avulla

    Ajatuksena on lähteä laajentamaan edellisessä kirjeessä luodun perustason chatbotin osaamista. Lähtökohtana on ymmärtää…

    1 Comment
  • Lyhyt oppimäärä Semantic Kernelin saloihin

    Koska taustani on Microsoft maailmassa, tutustuin Microsoftin Semantic Kerneliin tutustuessani vuosi sitten Azure AI…

  • Tekoälyt testissä - Mistral

    Moni on nyt hehkuttanut Mistralin LeChat palvelua ja sen nopeutta. Tästä kiinnostuneena ajattelin testata palveluiden…

  • Miten viedä tekoälyn hyödyntämistä eteenpäin organisaatiossa?

    Tämä on kysymys, jota minä ja useampi kollega miettivät usein. Helppoa se ei ole! Toisaalta ei se aivan mahdotontakaan…

  • Tiedon merkitys tekoälyprojekteissa eli miten navetasta tuli sänky

    Käytettävä tieto on hyvin oleellinen asia tekoälyprojektissa. Jos tieto tai mallin opettamiseen käytetty tieto eivät…

  • Sujuva tekoälyn käyttöönotto

    Mitä tarkoittaa tekoälyn käyttöönotto? Tällä hetkellä puhutaan paljon ChatGPT:stä, CoPilotista ja muista vastaavista…

  • Tekoäly ja avoimuus

    Meillä on ongelma Monet nykyiset tekoälyt / mallit pohjautuvat syväoppimiseen, jossa mallia on opetettu suurella…

    2 Comments
  • Generatiivisen tekoälyn perusteet

    Ymmärrys on välillä aika pahasti koetuksella. Asiat ovat monesti monimutkaisia eikä niiden suunnattomasta…

    2 Comments
  • Extending K6 scripts

    Now we can see what else you can do with K6 other than run performance tests. K6 uses JavaScript for creating test…

Others also viewed

Explore content categories