36 lines
2.2 KiB
Markdown
36 lines
2.2 KiB
Markdown
|
|
# Room Status Synchronization Implementation Test Results
|
|||
|
|
Date: 2026-02-06
|
|||
|
|
|
|||
|
|
## 1. Test Overview
|
|||
|
|
This document summarizes the validation tests performed for the Room Status Synchronization feature, specifically focusing on the `upsertRoomStatus` logic in `DatabaseManager`.
|
|||
|
|
|
|||
|
|
## 2. Test Cases & Results
|
|||
|
|
|
|||
|
|
### 2.1 Auto-Partitioning (自动分区)
|
|||
|
|
- **Scenario**: Incoming heartbeat data contains a `hotel_id` (e.g., 3000) for which no partition exists in `room_status.room_status_moment`.
|
|||
|
|
- **Expected Behavior**: The system should catch the "no partition of relation" error, dynamically create the partition `room_status_moment_h3000`, and retry the insertion successfully.
|
|||
|
|
- **Result**: **PASSED**.
|
|||
|
|
- Log observation: `[db] 检测到 room_status 分区缺失,尝试自动创建分区,hotelIds: 3000`
|
|||
|
|
- Log observation: `[db] 成功创建 room_status 分区: room_status_moment_h3000`
|
|||
|
|
- Data verification: Data was successfully inserted into the new partition.
|
|||
|
|
|
|||
|
|
### 2.2 In-Batch Deduplication (批次内去重)
|
|||
|
|
- **Scenario**: A single batch of heartbeat events contains multiple records for the same device (`hotel_id`, `room_id`, `device_id`) but with different `ts_ms`.
|
|||
|
|
- **Issue**: PostgreSQL `ON CONFLICT` clause raises an error/warning if the same row is proposed for update multiple times in the same statement: "ON CONFLICT DO UPDATE command cannot affect row a second time".
|
|||
|
|
- **Solution**: Implemented application-level deduplication before SQL generation. Grouped by device key and kept the record with the largest `ts_ms`.
|
|||
|
|
- **Result**: **PASSED**.
|
|||
|
|
- The warning "ON CONFLICT DO UPDATE command cannot affect row a second time" is no longer observed in the logs.
|
|||
|
|
- The database reflects the latest state (highest `ts_ms`).
|
|||
|
|
|
|||
|
|
### 2.3 System Startup & Stability
|
|||
|
|
- **Scenario**: Full system startup with the new code changes.
|
|||
|
|
- **Result**: **PASSED**.
|
|||
|
|
- Service started successfully.
|
|||
|
|
- Redis connection established.
|
|||
|
|
- Database connection established.
|
|||
|
|
- Partition maintenance task started.
|
|||
|
|
- No regression observed in existing Heartbeat History (`heartbeat.heartbeat_events`) insertion.
|
|||
|
|
|
|||
|
|
## 3. Conclusion
|
|||
|
|
The implementation of `upsertRoomStatus` is robust and handles dynamic partitioning and data duplication correctly. The system is ready for deployment.
|