tcp

package module
v0.0.0-...-6802917 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 4 Imported by: 0

README

xk6-tcp

A k6 extension for sending strings to TCP port

Build

To build a k6 binary with this plugin, first ensure you have the prerequisites:

Then:

  1. Install xk6:
go install github.com/k6io/xk6/cmd/xk6@latest
  1. Build the binary:
xk6 build master \
  --with github.com/NAlexandrov/xk6-tcp

Example

import tcp from 'k6/x/tcpx';
import { expect } from "https://jslib.k6.io/k6chaijs/4.3.4.3/index.js";


export default function () {
  // Should be done here as there will be an error when all the VUs use the same tcp connection
  const conn = tcp.connect('host:port');

  tcp.writeLn(conn, 'Say Hello', '\r\n');
  tcp.closeWrite(conn);

  let res = String.fromCharCode(...tcp.read(conn, 1024));
  expect(res).to.equal("Hello\r\n");

  tcp.close(conn);
}

TODO

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ModuleInstance

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

ModuleInstance represents an instance of the JS module.

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() k6modules.Exports

Exports implements the modules.Instance interface and returns the exported types for the JS module.

type RootModule

type RootModule struct{}

RootModule is the global module instance that will create module instances for each VU.

func New

func New() *RootModule

New returns a pointer to a new RootModule instance.

func (*RootModule) NewModuleInstance

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

NewModuleInstance implements the modules.Module interface returning a new instance for each VU.

type TCP

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

func (*TCP) Close

func (tcp *TCP) Close(conn *net.TCPConn) error

func (*TCP) CloseRead

func (tcp *TCP) CloseRead(conn *net.TCPConn) error

func (*TCP) CloseWrite

func (tcp *TCP) CloseWrite(conn *net.TCPConn) error

func (*TCP) Connect

func (tcp *TCP) Connect(tcpType string, address string) (*net.TCPConn, error)

Viable values for the tcp type are the ones in golang net.Tcp "tcp", "tcp4", "tcp6", "" => will fallback to "tcp" then

func (*TCP) Read

func (tcp *TCP) Read(conn *net.TCPConn, size int) ([]byte, error)

func (*TCP) SetDeadlineToInfinite

func (tcp *TCP) SetDeadlineToInfinite(conn *net.TCPConn) error

func (*TCP) SetKeepAlive

func (tcp *TCP) SetKeepAlive(conn *net.TCPConn, shouldSendKeepAlive bool) error

func (*TCP) Write

func (tcp *TCP) Write(conn *net.TCPConn, data []byte) error

func (*TCP) WriteBytesLn

func (tcp *TCP) WriteBytesLn(conn *net.TCPConn, data []byte, delim []byte) error

func (*TCP) WriteLn

func (tcp *TCP) WriteLn(conn *net.TCPConn, data string, delim string) error

Jump to

Keyboard shortcuts

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