Fix: Websocket communication misunderstanding error
This commit is contained in:
parent
9967bff6dc
commit
42a8325faf
8 changed files with 1109 additions and 63 deletions
138
test_subscription_flow.py
Normal file
138
test_subscription_flow.py
Normal file
|
@ -0,0 +1,138 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify the complete subscription flow works correctly.
|
||||
|
||||
This simulates the exact flow shown in the user's RX/TX log:
|
||||
1. Initial null subscribe (should be ignored)
|
||||
2. setSubscriptionList with 4 cameras using model ID 43
|
||||
3. Verify unique model download and subscription setup
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import websockets
|
||||
import json
|
||||
import time
|
||||
|
||||
async def test_complete_flow():
|
||||
"""Test the complete subscription flow."""
|
||||
|
||||
print("🚀 Testing Complete Subscription Flow")
|
||||
print("=" * 70)
|
||||
|
||||
try:
|
||||
# Connect to the detector worker
|
||||
uri = "ws://localhost:8001" # Using staging port
|
||||
print(f"🔗 Connecting to {uri}...")
|
||||
|
||||
async with websockets.connect(uri) as websocket:
|
||||
print("✅ Connected!")
|
||||
|
||||
# Step 1: Send initial null subscribe (like CMS does)
|
||||
print(f"\n📤 Step 1: Sending initial null subscribe (should be ignored)...")
|
||||
null_subscribe = {
|
||||
"type": "subscribe",
|
||||
"payload": {
|
||||
"subscriptionIdentifier": "null",
|
||||
"rtspUrl": "",
|
||||
"modelUrl": "",
|
||||
"modelName": None,
|
||||
"modelId": None
|
||||
}
|
||||
}
|
||||
await websocket.send(json.dumps(null_subscribe))
|
||||
print("✅ Null subscribe sent")
|
||||
|
||||
# Wait a moment
|
||||
await asyncio.sleep(2)
|
||||
|
||||
# Step 2: Send real setSubscriptionList (like your log shows)
|
||||
print(f"\n📤 Step 2: Sending real setSubscriptionList with 4 cameras...")
|
||||
subscription_list = {
|
||||
"type": "setSubscriptionList",
|
||||
"subscriptions": [
|
||||
{
|
||||
"subscriptionIdentifier": "test2;webcam-local-01",
|
||||
"rtspUrl": "rtsp://10.101.1.4:8554/stream",
|
||||
"snapshotUrl": "http://10.101.1.4:8080/snapshot",
|
||||
"snapshotInterval": 2000,
|
||||
"modelUrl": "https://example.com/models/test-model-43.mpta",
|
||||
"modelId": 43,
|
||||
"modelName": "test_model"
|
||||
},
|
||||
{
|
||||
"subscriptionIdentifier": "test3;webcam-local-02",
|
||||
"rtspUrl": "rtsp://10.101.1.4:8551/stream",
|
||||
"snapshotUrl": "http://10.101.1.4:8081/snapshot",
|
||||
"snapshotInterval": 2000,
|
||||
"modelUrl": "https://example.com/models/test-model-43.mpta",
|
||||
"modelId": 43,
|
||||
"modelName": "test_model"
|
||||
},
|
||||
{
|
||||
"subscriptionIdentifier": "test4;webcam-local-03",
|
||||
"rtspUrl": "rtsp://10.101.1.4:8552/stream",
|
||||
"snapshotUrl": "http://10.101.1.4:8082/snapshot",
|
||||
"snapshotInterval": 2000,
|
||||
"modelUrl": "https://example.com/models/test-model-43.mpta",
|
||||
"modelId": 43,
|
||||
"modelName": "test_model"
|
||||
},
|
||||
{
|
||||
"subscriptionIdentifier": "test5;webcam-local-04",
|
||||
"rtspUrl": "rtsp://10.101.1.4:8553/stream",
|
||||
"snapshotUrl": "http://10.101.1.4:8083/snapshot",
|
||||
"snapshotInterval": 2000,
|
||||
"modelUrl": "https://example.com/models/test-model-43.mpta",
|
||||
"modelId": 43,
|
||||
"modelName": "test_model"
|
||||
}
|
||||
]
|
||||
}
|
||||
await websocket.send(json.dumps(subscription_list))
|
||||
print("✅ setSubscriptionList sent with 4 cameras (all using model ID 43)")
|
||||
|
||||
# Wait for processing
|
||||
print(f"\n⏳ Waiting for worker to process subscriptions...")
|
||||
await asyncio.sleep(10)
|
||||
|
||||
# Step 3: Send progression stage (like your log shows)
|
||||
print(f"\n📤 Step 3: Sending setProgressionStage...")
|
||||
progression_stage = {
|
||||
"type": "setProgressionStage",
|
||||
"payload": {
|
||||
"displayIdentifier": "test2",
|
||||
"progressionStage": "welcome"
|
||||
}
|
||||
}
|
||||
await websocket.send(json.dumps(progression_stage))
|
||||
print("✅ setProgressionStage sent")
|
||||
|
||||
# Wait for any responses
|
||||
print(f"\n📥 Listening for responses...")
|
||||
try:
|
||||
for i in range(3):
|
||||
response = await asyncio.wait_for(websocket.recv(), timeout=5.0)
|
||||
print(f"📥 Response {i+1}: {response[:100]}...")
|
||||
except asyncio.TimeoutError:
|
||||
print("⏰ No more responses (this is normal)")
|
||||
|
||||
print(f"\n✅ Complete flow test finished!")
|
||||
print(f"📋 Check worker logs for:")
|
||||
print(f" - 'IGNORING initial subscribe message' for step 1")
|
||||
print(f" - 'Unique models to download: [43]' for step 2")
|
||||
print(f" - Model download progress and success messages")
|
||||
print(f" - Subscription setup for 4 cameras")
|
||||
|
||||
except ConnectionRefusedError:
|
||||
print("❌ Connection refused. Make sure the worker is running with:")
|
||||
print(" make run-staging")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🧪 Complete Subscription Flow Test")
|
||||
print("This simulates the exact CMS backend behavior you showed in the RX/TX log")
|
||||
input("Make sure detector worker is running first, then press Enter...")
|
||||
|
||||
asyncio.run(test_complete_flow())
|
Loading…
Add table
Add a link
Reference in a new issue