async

package module
v0.0.0-...-7a4a2c8 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 11 Imported by: 0

README

xk6-async

A k6 extension that provides async-compatible group() and check() functions.

Build

xk6 build --with github.com/agostone/xk6-async

Usage

group
import { group } from 'k6/x/async';
import http from 'k6/http';

export default async function () {
  await group('My Async Group', async () => {
    const response = await http.asyncRequest('GET', 'https://test.k6.io');
    console.log('Response status:', response.status);
  });
}
check
import { check } from 'k6/x/async';
import http from 'k6/http';

export default async function () {
  const response = await http.asyncRequest('GET', 'https://test.k6.io');
  
  await check(response, {
    'status is 200': (r) => r.status === 200,
    'async validation': async (r) => {
      // Perform async validation
      return r.status < 400;
    }
  });
}

Features

group
  • ✅ Supports async functions
  • ✅ Correctly measures group duration including async operations
  • ✅ Properly manages group tags across async boundaries
  • ✅ Emits group_duration metrics
  • ✅ Works with both sync and async callbacks
check
  • ✅ Supports async functions in checks
  • ✅ Handles mixed sync and async checks
  • ✅ Emits checks metrics after async operations complete
  • ✅ Works with custom tags
  • ✅ Compatible with all check features from built-in check()

Difference from built-in functions

group vs group()

The built-in group() function doesn't support async functions. This extension provides an async-compatible group() which:

  • Accepts async functions as callbacks
  • Waits for Promises to resolve before emitting metrics
  • Ensures group tags are correctly restored after async operations complete
check vs check()

The built-in check() function doesn't support async functions. This extension provides an async-compatible check() which:

  • Accepts async functions in check definitions
  • Waits for all Promises to resolve before emitting check metrics
  • Supports mixed sync and async checks in the same call

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Async

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

func (*Async) Check

func (a *Async) Check(arg0, checks sobek.Value, extras ...sobek.Value) (sobek.Value, error)

func (*Async) Exports

func (a *Async) Exports() modules.Exports

func (*Async) Group

func (a *Async) Group(name string, val sobek.Value) (sobek.Value, error)

type RootModule

type RootModule struct{}

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance

Jump to

Keyboard shortcuts

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