HomePhabricator
Diffusion Comm 357528de9ac3

[Tunnelbroker] always persist WebSocket messages in database

Description

[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:

  1. Restart RabbitMQ
  2. Restart localstack
  3. 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");
}
  1. Open RabbitMQ management console, there should be one dropped message (there is no device with test_persist ID)

Screenshot 2023-09-28 at 14.51.24.png (356×1 px, 70 KB)

  1. Open DynamoDB console, message should be persisted:

Screenshot 2023-09-28 at 14.53.32.png (1×5 px, 222 KB)

  1. 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
  1. 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

Details

Provenance
kamilAuthored on Sep 28 2023, 6:00 AM
Reviewer
bartek
Differential Revision
D9316: [Tunnelbroker] always persist WebSocket messages in database
Parents
rCOMMcfada1190519: [Tunnelbroker] add WebSocket version of MessageToDevice
Branches
Unknown
Tags
Unknown