refactor: 更新WebSocket相关测试和location_broadcast模块

- 更新location_broadcast网关以支持原生WebSocket
- 修改WebSocket认证守卫和中间件
- 更新相关的测试文件和规范
- 添加WebSocket测试工具
- 完善Zulip服务的测试覆盖

技术改进:
- 统一WebSocket实现架构
- 优化性能监控和限流中间件
- 更新测试用例以适配新的WebSocket实现
This commit is contained in:
moyin
2026-01-09 17:02:43 +08:00
parent e9dc887c59
commit cbf4120ddd
13 changed files with 752 additions and 524 deletions

View File

@@ -13,7 +13,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as fc from 'fast-check';
import { SessionManagerService, GameSession, Position } from './session_manager.service';
import { IZulipConfigService } from '../../../core/zulip_core/interfaces/zulip_core.interfaces';
import { IZulipConfigService } from '../../../core/zulip_core/zulip_core.interfaces';
import { AppLoggerService } from '../../../core/utils/logger/logger.service';
import { IRedisService } from '../../../core/redis/redis.interface';
@@ -154,6 +154,9 @@ describe('SessionManagerService', () => {
// 清理内存存储
memoryStore.clear();
memorySets.clear();
// 等待任何正在进行的异步操作完成
await new Promise(resolve => setImmediate(resolve));
});
it('should be defined', () => {
@@ -399,9 +402,9 @@ describe('SessionManagerService', () => {
expect(retrievedSession?.zulipQueueId).toBe(createdSession.zulipQueueId);
}
),
{ numRuns: 100 }
{ numRuns: 50, timeout: 5000 } // 添加超时控制
);
}, 60000);
}, 30000);
/**
* 属性: 对于任何位置更新,会话应该正确反映新位置
@@ -449,9 +452,9 @@ describe('SessionManagerService', () => {
expect(session?.position.y).toBe(y);
}
),
{ numRuns: 100 }
{ numRuns: 50, timeout: 5000 } // 添加超时控制
);
}, 60000);
}, 30000);
/**
* 属性: 对于任何地图切换,玩家应该从旧地图移除并添加到新地图
@@ -499,9 +502,9 @@ describe('SessionManagerService', () => {
}
}
),
{ numRuns: 100 }
{ numRuns: 50, timeout: 5000 } // 添加超时控制
);
}, 60000);
}, 30000);
/**
* 属性: 对于任何会话销毁,所有相关数据应该被清理
@@ -551,9 +554,9 @@ describe('SessionManagerService', () => {
expect(mapPlayers).not.toContain(socketId.trim());
}
),
{ numRuns: 100 }
{ numRuns: 50, timeout: 5000 } // 添加超时控制
);
}, 60000);
}, 30000);
/**
* 属性: 创建-更新-销毁的完整生命周期应该正确管理会话状态
@@ -613,8 +616,8 @@ describe('SessionManagerService', () => {
expect(finalSession).toBeNull();
}
),
{ numRuns: 100 }
{ numRuns: 50, timeout: 5000 } // 添加超时控制
);
}, 60000);
}, 30000);
});
});