UNPKG

innomind-vita

Version:

InnoMind Vita - AI-Powered Industrial Software Platform

98 lines (78 loc) 2.78 kB
import { Agent } from '@innomind-vita/core'; describe('Agent Performance', () => { let agent: Agent; beforeEach(() => { agent = new Agent({ id: 'perf-test-agent', name: '性能测试智能体', maxProcessTime: 1000 }); }); describe('响应时间', () => { it('应该在指定时间内响应', async () => { const startTime = Date.now(); await agent.process({ type: 'command', content: '性能测试' }); const duration = Date.now() - startTime; expect(duration).toBeLessThan(1000); }); it('应该能处理连续请求', async () => { const requests = 5; const times: number[] = []; for (let i = 0; i < requests; i++) { const startTime = Date.now(); await agent.process({ type: 'command', content: `连续请求 ${i + 1}` }); times.push(Date.now() - startTime); } // 验证所有请求的响应时间 times.forEach(time => { expect(time).toBeLessThan(1000); }); // 验证平均响应时间 const avgTime = times.reduce((a, b) => a + b) / times.length; expect(avgTime).toBeLessThan(500); }); }); describe('内存使用', () => { it('应该在处理大量请求后保持稳定的内存使用', async () => { const initialMemory = process.memoryUsage().heapUsed; const requests = 100; for (let i = 0; i < requests; i++) { await agent.process({ type: 'command', content: `内存测试请求 ${i + 1}` }); } const finalMemory = process.memoryUsage().heapUsed; const memoryIncrease = finalMemory - initialMemory; // 内存增长不应超过 10MB expect(memoryIncrease).toBeLessThan(10 * 1024 * 1024); }); }); describe('并发性能', () => { it('应该能高效处理排队的请求', async () => { const startTime = Date.now(); const requests = 10; // 创建多个并发请求 const promises = Array(requests).fill(null).map((_, index) => agent.process({ type: 'command', content: `并发请求 ${index + 1}` }) ); const responses = await Promise.all(promises); const totalTime = Date.now() - startTime; // 验证总处理时间 expect(totalTime).toBeLessThan(requests * 1000); // 验证响应顺序 const successResponse = responses.find(r => r.type === 'response'); expect(successResponse).toBeDefined(); expect(responses.filter(r => r.type === 'error').length).toBe(requests - 1); }); }); });