framework

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package framework provides concurrent load testing utilities

Package framework provides performance metrics collection and analysis utilities

Package framework provides utilities for performance testing across the Midsommar system

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildLLMRequest

func BuildLLMRequest(model string, messages []map[string]string) []byte

BuildLLMRequest creates a test LLM request

func BuildStreamingLLMRequest

func BuildStreamingLLMRequest(model string, messages []map[string]string) []byte

BuildStreamingLLMRequest creates a test streaming LLM request

Types

type BenchmarkDB

type BenchmarkDB struct {
	DB          *gorm.DB
	QueryLogger *QueryCountLogger
	// contains filtered or unexported fields
}

BenchmarkDB provides a test database with query monitoring for benchmarks

func NewBenchmarkDB

func NewBenchmarkDB(t *testing.B) *BenchmarkDB

NewBenchmarkDB creates a new test database with performance monitoring

func (*BenchmarkDB) GetDB

func (bdb *BenchmarkDB) GetDB() *gorm.DB

GetDB returns the database instance for testing

func (*BenchmarkDB) ResetQueryStats

func (bdb *BenchmarkDB) ResetQueryStats()

ResetQueryStats resets the query counter for a new benchmark run

func (*BenchmarkDB) SetTestDataSize

func (bdb *BenchmarkDB) SetTestDataSize(size int) *BenchmarkDB

SetTestDataSize configures the amount of test data to create

func (*BenchmarkDB) SetupTestData

func (bdb *BenchmarkDB) SetupTestData(t *testing.B)

SetupTestData creates test data for performance benchmarks (idempotent)

type ConcurrentMetrics

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

ConcurrentMetrics collects metrics from concurrent operations

func NewConcurrentMetrics

func NewConcurrentMetrics(workers int) *ConcurrentMetrics

NewConcurrentMetrics creates a new concurrent metrics collector

func (*ConcurrentMetrics) Aggregate

func (cm *ConcurrentMetrics) Aggregate() *PerformanceMetrics

Aggregate combines metrics from all workers

func (*ConcurrentMetrics) GetWorkerMetrics

func (cm *ConcurrentMetrics) GetWorkerMetrics(workerID int) *PerformanceMetrics

GetWorkerMetrics returns metrics for a specific worker

type ConcurrentTester

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

ConcurrentTester manages concurrent load testing scenarios

func NewConcurrentTester

func NewConcurrentTester(workers int) *ConcurrentTester

NewConcurrentTester creates a new concurrent tester

func (*ConcurrentTester) Run

func (ct *ConcurrentTester) Run(b *testing.B, workerFunc WorkerFunc) *PerformanceMetrics

Run executes the concurrent test with the given worker function

func (*ConcurrentTester) Stop

func (ct *ConcurrentTester) Stop()

Stop cancels the concurrent test

func (*ConcurrentTester) WithDuration

func (ct *ConcurrentTester) WithDuration(duration time.Duration) *ConcurrentTester

WithDuration sets the test duration

func (*ConcurrentTester) WithRampUp

func (ct *ConcurrentTester) WithRampUp(duration time.Duration) *ConcurrentTester

WithRampUp sets the ramp-up duration for gradual load increase

func (*ConcurrentTester) WithRequestCount

func (ct *ConcurrentTester) WithRequestCount(count int64) *ConcurrentTester

WithRequestCount sets the total number of requests to send

type ConnectionPoolTester

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

ConnectionPoolTester tests connection pool behavior under load

func NewConnectionPoolTester

func NewConnectionPoolTester(maxConnections int) *ConnectionPoolTester

NewConnectionPoolTester creates a connection pool tester

func (*ConnectionPoolTester) TestExhaustion

func (cpt *ConnectionPoolTester) TestExhaustion(b *testing.B, acquireFunc func() error, releaseFunc func()) *PerformanceMetrics

TestExhaustion tests what happens when the connection pool is exhausted

func (*ConnectionPoolTester) WithConnectionDelay

func (cpt *ConnectionPoolTester) WithConnectionDelay(delay time.Duration) *ConnectionPoolTester

WithConnectionDelay sets the simulated connection establishment delay

func (*ConnectionPoolTester) WithHoldDuration

func (cpt *ConnectionPoolTester) WithHoldDuration(duration time.Duration) *ConnectionPoolTester

WithHoldDuration sets how long each connection is held

type DatabaseMetrics

type DatabaseMetrics struct {
	QueryCount      int64
	QueryDuration   time.Duration
	ConnectionsUsed int64
	CacheHits       int64
	CacheMisses     int64
}

DatabaseMetrics tracks database-specific performance metrics

func (*DatabaseMetrics) AvgQueryDuration

func (dm *DatabaseMetrics) AvgQueryDuration() time.Duration

AvgQueryDuration returns average query duration

func (*DatabaseMetrics) CacheHitRate

func (dm *DatabaseMetrics) CacheHitRate() float64

CacheHitRate returns cache hit percentage

func (*DatabaseMetrics) RecordCacheHit

func (dm *DatabaseMetrics) RecordCacheHit()

RecordCacheHit increments cache hit counter

func (*DatabaseMetrics) RecordCacheMiss

func (dm *DatabaseMetrics) RecordCacheMiss()

RecordCacheMiss increments cache miss counter

func (*DatabaseMetrics) RecordConnection

func (dm *DatabaseMetrics) RecordConnection()

RecordConnection increments connection usage

func (*DatabaseMetrics) RecordQuery

func (dm *DatabaseMetrics) RecordQuery(duration time.Duration)

RecordQuery adds a database query measurement

type LatencyBucket

type LatencyBucket struct {
	Min   time.Duration
	Max   time.Duration
	Count int
}

LatencyBucket represents a range of latencies and their count

type LatencyHistogram

type LatencyHistogram struct {
	Buckets []LatencyBucket
}

LatencyHistogram creates a histogram of latency distribution

type LoadPattern

type LoadPattern int

LoadPattern defines different load testing patterns

const (
	ConstantLoad LoadPattern = iota
	SpikeLoad
	StepLoad
	SineWaveLoad
)

type LoadTester

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

LoadTester provides advanced load testing patterns

func NewLoadTester

func NewLoadTester(pattern LoadPattern) *LoadTester

NewLoadTester creates a new load tester with pattern

func (*LoadTester) Execute

func (lt *LoadTester) Execute(b *testing.B, workerFunc WorkerFunc) *PerformanceMetrics

Execute runs the load test with the specified pattern

func (*LoadTester) WithBaseRPS

func (lt *LoadTester) WithBaseRPS(rps float64) *LoadTester

WithBaseRPS sets the baseline requests per second

func (*LoadTester) WithDuration

func (lt *LoadTester) WithDuration(duration time.Duration) *LoadTester

WithDuration sets the test duration

func (*LoadTester) WithMaxRPS

func (lt *LoadTester) WithMaxRPS(rps float64) *LoadTester

WithMaxRPS sets the maximum requests per second

func (*LoadTester) WithStepConfig

func (lt *LoadTester) WithStepConfig(stepSize float64, stepDuration time.Duration) *LoadTester

WithStepConfig sets step load configuration

type MemoryLeakTester

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

MemoryLeakTester helps detect memory leaks during load testing

func NewMemoryLeakTester

func NewMemoryLeakTester() *MemoryLeakTester

NewMemoryLeakTester creates a memory leak tester

func (*MemoryLeakTester) GetMemoryTrend

func (mlt *MemoryLeakTester) GetMemoryTrend() []MemorySample

GetMemoryTrend returns the memory usage trend

func (*MemoryLeakTester) StartMonitoring

func (mlt *MemoryLeakTester) StartMonitoring()

StartMonitoring begins memory monitoring

func (*MemoryLeakTester) StopMonitoring

func (mlt *MemoryLeakTester) StopMonitoring() (bool, string)

StopMonitoring stops memory monitoring and returns results

type MemoryProfiler

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

MemoryProfiler helps track memory usage patterns during benchmarks

func NewMemoryProfiler

func NewMemoryProfiler() *MemoryProfiler

NewMemoryProfiler creates a new memory profiler

func (*MemoryProfiler) DetectMemoryLeak

func (mp *MemoryProfiler) DetectMemoryLeak() (bool, string)

DetectMemoryLeak analyzes samples for potential memory leaks

func (*MemoryProfiler) GetMemoryTrend

func (mp *MemoryProfiler) GetMemoryTrend() []MemorySample

GetMemoryTrend returns memory usage trend over time

func (*MemoryProfiler) Sample

func (mp *MemoryProfiler) Sample()

Sample records current memory statistics

type MemorySample

type MemorySample struct {
	Timestamp  time.Time
	Alloc      uint64
	TotalAlloc uint64
	Sys        uint64
	NumGC      uint32
}

MemorySample represents a point-in-time memory measurement

type MockLLMServer

type MockLLMServer struct {
	Requests []MockRequest
	// contains filtered or unexported fields
}

MockLLMServer provides a mock LLM provider for testing

func NewMockLLMServer

func NewMockLLMServer() *MockLLMServer

NewMockLLMServer creates a mock LLM provider server

func (*MockLLMServer) Close

func (m *MockLLMServer) Close()

Close shuts down the mock server

func (*MockLLMServer) GetRequestStats

func (m *MockLLMServer) GetRequestStats() RequestStats

GetRequestStats returns statistics about received requests

func (*MockLLMServer) URL

func (m *MockLLMServer) URL() string

URL returns the mock server URL

type MockRequest

type MockRequest struct {
	Method       string
	Path         string
	Headers      http.Header
	Body         []byte
	Timestamp    time.Time
	ResponseTime time.Duration
}

MockRequest captures request details for analysis

type PerformanceMetrics

type PerformanceMetrics struct {
	// Latency metrics
	Latencies []time.Duration
	P50       time.Duration
	P95       time.Duration
	P99       time.Duration
	Average   time.Duration
	Min       time.Duration
	Max       time.Duration

	// Throughput metrics
	TotalRequests   int64
	SuccessRequests int64
	ErrorRequests   int64
	RequestsPerSec  float64
	TestDuration    time.Duration

	// Resource metrics
	MemAllocBefore   uint64
	MemAllocAfter    uint64
	MemAllocDelta    uint64
	GoroutinesBefore int
	GoroutinesAfter  int
	GoroutinesDelta  int

	// Custom metrics
	CustomMetrics map[string]float64
	// contains filtered or unexported fields
}

PerformanceMetrics captures comprehensive performance data

func NewPerformanceMetrics

func NewPerformanceMetrics() *PerformanceMetrics

NewPerformanceMetrics creates a new metrics collector

func (*PerformanceMetrics) CreateLatencyHistogram

func (pm *PerformanceMetrics) CreateLatencyHistogram() LatencyHistogram

CreateLatencyHistogram generates a histogram from latency data

func (*PerformanceMetrics) EndMeasurement

func (pm *PerformanceMetrics) EndMeasurement(duration time.Duration)

EndMeasurement records final system state and calculates metrics

func (*PerformanceMetrics) RecordCustomMetric

func (pm *PerformanceMetrics) RecordCustomMetric(name string, value float64)

RecordCustomMetric adds a custom metric value

func (*PerformanceMetrics) RecordError

func (pm *PerformanceMetrics) RecordError()

RecordError increments error request counter

func (*PerformanceMetrics) RecordLatency

func (pm *PerformanceMetrics) RecordLatency(duration time.Duration)

RecordLatency adds a latency measurement

func (*PerformanceMetrics) RecordSuccess

func (pm *PerformanceMetrics) RecordSuccess()

RecordSuccess increments successful request counter

func (*PerformanceMetrics) ReportToB

func (pm *PerformanceMetrics) ReportToB(b *testing.B)

ReportToB reports metrics to the testing framework

func (*PerformanceMetrics) StartMeasurement

func (pm *PerformanceMetrics) StartMeasurement()

StartMeasurement records initial system state

func (*PerformanceMetrics) String

func (pm *PerformanceMetrics) String() string

String provides a human-readable summary of the metrics

type QueryCountLogger

type QueryCountLogger struct {
	QueryCount int
	Queries    []string
	// contains filtered or unexported fields
}

QueryCountLogger captures database queries for performance analysis

func (*QueryCountLogger) Error

func (l *QueryCountLogger) Error(ctx context.Context, msg string, data ...interface{})

func (*QueryCountLogger) GetStats

func (l *QueryCountLogger) GetStats() (count int, queries []string)

GetStats returns current query statistics

func (*QueryCountLogger) Info

func (l *QueryCountLogger) Info(ctx context.Context, msg string, data ...interface{})

func (*QueryCountLogger) LogMode

func (l *QueryCountLogger) LogMode(level logger.LogLevel) logger.Interface

func (*QueryCountLogger) Reset

func (l *QueryCountLogger) Reset()

Reset clears the query counter and logs

func (*QueryCountLogger) Trace

func (l *QueryCountLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*QueryCountLogger) Warn

func (l *QueryCountLogger) Warn(ctx context.Context, msg string, data ...interface{})

type RateLimiter

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

RateLimiter provides request rate limiting for load tests

func NewRateLimiter

func NewRateLimiter(rps float64) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Close

func (rl *RateLimiter) Close()

Close stops the rate limiter

func (*RateLimiter) Wait

func (rl *RateLimiter) Wait(ctx context.Context) error

Wait blocks until a token is available

type RequestStats

type RequestStats struct {
	TotalRequests   int
	AvgResponseTime time.Duration
	MinResponseTime time.Duration
	MaxResponseTime time.Duration
}

RequestStats contains statistics about mock server requests

type WorkerFunc

type WorkerFunc func(ctx context.Context, workerID int, metrics *PerformanceMetrics) error

WorkerFunc defines the function each worker will execute

Jump to

Keyboard shortcuts

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