feat: 实现 G5 room_status 状态更新时跳过空 IP,增加 IP 归一化逻辑,更新相关测试
This commit is contained in:
@@ -25,6 +25,7 @@ describe('StatusBatchProcessor', () => {
|
||||
room_id: '8001',
|
||||
device_id: 'dev_001',
|
||||
ts_ms: 1700000000000,
|
||||
ip: '10.1.2.3',
|
||||
sys_lock_status: null,
|
||||
dev_loops: null,
|
||||
faulty_device_count: null,
|
||||
@@ -105,6 +106,29 @@ describe('StatusBatchProcessor', () => {
|
||||
expect(processor.buffer.size).toBe(2);
|
||||
});
|
||||
|
||||
it('should skip empty ip for g5 target', () => {
|
||||
processor = new StatusBatchProcessor(mockManager, {
|
||||
flushInterval: 50000,
|
||||
maxBufferSize: 100,
|
||||
targetName: 'g5:room_status.room_status_moment_g5'
|
||||
});
|
||||
|
||||
processor.add(makeUpdate({ ip: null }));
|
||||
|
||||
expect(processor.buffer.size).toBe(0);
|
||||
expect(mockManager.upsertBatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should preserve ip when flushing rows', async () => {
|
||||
processor.add(makeUpdate({ ip: '10.9.8.7' }));
|
||||
|
||||
await processor.flush();
|
||||
|
||||
expect(mockManager.upsertBatch).toHaveBeenCalledTimes(1);
|
||||
const rows = mockManager.upsertBatch.mock.calls[0][0];
|
||||
expect(rows[0].ip).toBe('10.9.8.7');
|
||||
});
|
||||
|
||||
it('should clear buffer after flush', async () => {
|
||||
processor.add(makeUpdate());
|
||||
expect(processor.buffer.size).toBe(1);
|
||||
|
||||
@@ -45,6 +45,27 @@ describe('StatusExtractor', () => {
|
||||
expect(result.device_id).toBe('dev_001');
|
||||
});
|
||||
|
||||
it('should normalize empty ip to null', () => {
|
||||
const result = extractStatusUpdate({
|
||||
...base,
|
||||
ip: ' ',
|
||||
sys_lock_status: 1
|
||||
});
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result.ip).toBeNull();
|
||||
});
|
||||
|
||||
it('should preserve non-empty ip', () => {
|
||||
const result = extractStatusUpdate({
|
||||
...base,
|
||||
ip: '10.1.2.3',
|
||||
sys_lock_status: 1
|
||||
});
|
||||
|
||||
expect(result.ip).toBe('10.1.2.3');
|
||||
});
|
||||
|
||||
it('should build dev_loops from device_list with 9-digit padded keys', () => {
|
||||
const result = extractStatusUpdate({
|
||||
...base,
|
||||
|
||||
Reference in New Issue
Block a user