UNPKG

lightweight-browser-load-tester

Version:

A lightweight load testing tool using real browsers for streaming applications with DRM support

216 lines 5.3 kB
import { EventEmitter } from 'events'; import { RequestInterceptor } from '../interceptors/request-interceptor'; import { TestConfiguration, TestResults, ErrorLog, ManagedBrowserInstance } from '../types'; /** * Test session represents a single user session */ export interface TestSession { id: string; browserInstance: ManagedBrowserInstance; interceptor: RequestInterceptor; startTime: Date; endTime?: Date; status: 'starting' | 'running' | 'stopping' | 'completed' | 'failed'; errors: ErrorLog[]; } /** * Real-time test monitoring data */ export interface TestMonitoringData { activeSessions: number; completedSessions: number; failedSessions: number; totalRequests: number; successfulRequests: number; failedRequests: number; averageResponseTime: number; currentRps: number; elapsedTime: number; remainingTime: number; memoryUsage: number; cpuUsage: number; resourceUtilization: ResourceUtilizationData; } /** * Resource utilization and performance data */ export interface ResourceUtilizationData { memoryUtilization: number; cpuUtilization: number; instancesNearMemoryLimit: number; instancesNearCpuLimit: number; totalInstances: number; activeInstances: number; resourceAlerts: ResourceAlert[]; } /** * Resource alert information */ export interface ResourceAlert { type: 'memory' | 'cpu' | 'instance_limit' | 'performance'; severity: 'warning' | 'critical'; message: string; timestamp: Date; instanceId?: string; value?: number; limit?: number; } /** * Test execution events */ export interface TestRunnerEvents { 'test-started': { testId: string; config: TestConfiguration; }; 'test-completed': { testId: string; results: TestResults; }; 'test-failed': { testId: string; error: Error; }; 'session-started': { sessionId: string; testId: string; }; 'session-completed': { sessionId: string; testId: string; }; 'session-failed': { sessionId: string; testId: string; error: Error; }; 'monitoring-update': { testId: string; data: TestMonitoringData; }; 'ramp-up-completed': { testId: string; }; } /** * TestRunner orchestrates browser instances and executes load tests */ export declare class TestRunner extends EventEmitter { private testId; private config; private browserPool; private sessions; private isRunning; private startTime?; private endTime?; private monitoringInterval?; private rampUpInterval?; private testTimeout?; private shutdownPromise?; constructor(config: TestConfiguration); /** * Start the load test */ startTest(): Promise<void>; /** * Stop the load test gracefully */ stopTest(): Promise<TestResults>; /** * Get current test monitoring data */ getMonitoringData(): TestMonitoringData; /** * Get detailed resource utilization data with alerts */ private getResourceUtilizationData; /** * Generate resource alerts based on current usage */ private generateResourceAlerts; /** * Force cleanup of idle browser instances to free resources */ cleanupIdleInstances(maxIdleTime?: number): Promise<number>; /** * Get detailed resource usage statistics */ getResourceUsageStats(): { totalInstances: number; activeInstances: number; totalMemoryUsage: number; averageMemoryUsage: number; totalCpuUsage: number; averageCpuUsage: number; memoryUtilization: number; cpuUtilization: number; instancesNearMemoryLimit: number; instancesNearCpuLimit: number; resourceLimits: import("../types").ResourceLimits; }; /** * Get test ID */ getTestId(): string; /** * Check if test is currently running */ isTestRunning(): boolean; /** * Set up browser pool event listeners */ private setupBrowserPoolEvents; /** * Start the ramp-up process */ private startRampUp; /** * Start a single test session */ private startSession; /** * Schedule session completion based on test duration */ private scheduleSessionCompletion; /** * Complete a test session */ private completeSession; /** * Handle browser disconnect events */ private handleBrowserDisconnect; /** * Start monitoring and emit periodic updates */ private startMonitoring; /** * Set up test timeout */ private setupTestTimeout; /** * Perform shutdown cleanup */ private performShutdown; /** * Generate test results */ private generateResults; /** * Get all network metrics from all sessions */ private getAllNetworkMetrics; /** * Get all errors from all sessions */ private getAllErrors; /** * Generate DRM-specific metrics */ private generateDRMMetrics; /** * Log error with context */ private logError; } //# sourceMappingURL=test-runner.d.ts.map