[Tunnelbroker] always persist WebSocket messages in database
Summary:
- We need to make sure that each message is delivered to client.
- We need to persist it immediately after receiving
- Message will be removed after confirmation from client
Depends on D9314
Test Plan:
- Restart RabbitMQ
- Restart localstack
- Run this code:
#[tokio::test] async fn send_websocket() { let device_info = create_device(None).await; let mut socket = create_socket(&device_info).await; let request = WebsocketMessageToDevice { device_id: device_info.device_id.to_string(), payload: "message from test".to_string(), }; let serialized_request = serde_json::to_string(&request) .expect("Failed to serialize connection request"); println!("request: {}", serialized_request); socket .send(Message::Text(serialized_request)) .await .expect("Failed to send message"); }
- Open RabbitMQ management console, there should be one dropped message (there is no device with test_persist ID)
- Open DynamoDB console, message should be persisted:
- Additionally, check TB logs for:
2023-09-28T12:52:08.492774Z DEBUG tunnelbroker::websockets::session: Received message for ZXx1ADCFxFm6P+UmVhX0A1tuqUoBU7lYjig/gMzSEJI 2023-09-28T12:52:08.492789Z DEBUG tunnelbroker::database: Persisting message to device: ZXx1ADCFxFm6P+UmVhX0A1tuqUoBU7lYjig/gMzSEJI
- Run:
cd services/commtest && cargo test --test tunnelbroker_persist_tests -- --nocapture
Reviewers: michal, bartek, varun, jon
Reviewed By: bartek
Subscribers: ashoat, tomek
Differential Revision: https://phab.comm.dev/D9316