load

package
v1.0.73 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadTest

type LoadTest struct {
	App *lift.App

	Name        string
	Description string
	Scenarios   []Scenario
	Config      LoadTestConfig
	// contains filtered or unexported fields
}

LoadTest represents a load testing configuration and execution

func NewLoadTest

func NewLoadTest(name string, app *lift.App, config LoadTestConfig) *LoadTest

NewLoadTest creates a new load test

func (*LoadTest) AddScenario

func (lt *LoadTest) AddScenario(scenario Scenario) *LoadTest

AddScenario adds a scenario to the load test

func (*LoadTest) PrintResults

func (lt *LoadTest) PrintResults()

PrintResults prints a summary of the results

func (*LoadTest) Run

func (lt *LoadTest) Run(ctx context.Context) (*Results, error)

Run executes the load test

type LoadTestConfig

type LoadTestConfig struct {
	// slice (24 bytes)
	Percentiles []float64
	// time.Duration fields (8 bytes each)
	Duration       time.Duration
	RampUpTime     time.Duration
	RampDownTime   time.Duration
	ThinkTime      time.Duration
	Timeout        time.Duration
	ReportInterval time.Duration
	// 8-byte aligned fields
	MaxRequests       int64
	RequestsPerSecond float64
	// 4-byte field
	Concurrent int
}

LoadTestConfig holds configuration for load testing

type Results

type Results struct {
	StartTime      time.Time                 `json:"start_time"`
	EndTime        time.Time                 `json:"end_time"`
	Percentiles    map[string]time.Duration  `json:"percentiles"`
	ScenarioStats  map[string]*ScenarioStats `json:"scenario_stats"`
	ErrorsByStatus map[int]int64             `json:"errors_by_status"`
	ErrorsByType   map[string]int64          `json:"errors_by_type"`
	TestName       string                    `json:"test_name"`
	Latencies      []time.Duration           `json:"-"`
	MeanLatency    time.Duration             `json:"mean_latency"`
	MaxLatency     time.Duration             `json:"max_latency"`
	Duration       time.Duration             `json:"duration"`
	MedianLatency  time.Duration             `json:"median_latency"`
	MinLatency     time.Duration             `json:"min_latency"`
	SuccessCount   int64                     `json:"success_count"`
	ErrorCount     int64                     `json:"error_count"`
	TotalRequests  int64                     `json:"total_requests"`
	BytesRead      int64                     `json:"bytes_read"`
	BytesWritten   int64                     `json:"bytes_written"`
	RequestsPerSec float64                   `json:"requests_per_sec"`
	Throughput     float64                   `json:"throughput_mbps"`
}

Results contains the aggregated results of a load test

type Scenario

type Scenario struct {
	Setup       func() (any, error)
	Execute     func(context.Context, *lift.App, any) (*ScenarioResult, error)
	Validate    func(*ScenarioResult) error
	Cleanup     func(any) error
	Name        string
	Description string
	Weight      int
}

Scenario represents a test scenario with weight

func HTTPGetScenario

func HTTPGetScenario(name, _ string) Scenario

HTTPGetScenario creates a simple HTTP GET scenario

func HTTPPostScenario

func HTTPPostScenario(name, _ string, payload any) Scenario

HTTPPostScenario creates a simple HTTP POST scenario

func RateLimitTestScenario

func RateLimitTestScenario(name, _ string, expectedLimit int) Scenario

RateLimitTestScenario creates a scenario for testing rate limits

type ScenarioResult

type ScenarioResult struct {
	Error        error
	Headers      map[string]string
	Metadata     map[string]any
	Body         []byte
	StatusCode   int
	ResponseTime time.Duration
	BytesRead    int64
	BytesWritten int64
}

ScenarioResult contains the result of executing a scenario

type ScenarioStats

type ScenarioStats struct {
	ErrorsByType   map[string]int64 `json:"errors_by_type"`
	ErrorsByStatus map[int]int64    `json:"errors_by_status"`
	Name           string           `json:"name"`
	Count          int64            `json:"count"`
	SuccessCount   int64            `json:"success_count"`
	ErrorCount     int64            `json:"error_count"`
	MeanLatency    time.Duration    `json:"mean_latency"`
	MinLatency     time.Duration    `json:"min_latency"`
	MaxLatency     time.Duration    `json:"max_latency"`
	// contains filtered or unexported fields
}

ScenarioStats contains statistics for a specific scenario

Jump to

Keyboard shortcuts

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