1

I am trying to connect multiple test clients to one server / filter. I tried:

#[tokio::test]
async fn test_ws() {
    let mut client1 = warp::test::ws()
        .path("/api/ws/test")
        .handshake(get_server())
        .await
        .expect("handshake");
    let mut client2 = warp::test::ws()
        .path("/api/ws/test")
        .handshake(get_server())
        .await
        .expect("handshake");

The get_server functions returns a BoxedFilter that i want to test. I tried storing it and borrowing it but that didn’t work. This currently creates a new test server for each client. I want the clients to connect to the same test server.

kmdreko
  • 42,554
  • 6
  • 57
  • 106
Ceres
  • 2,498
  • 1
  • 10
  • 28

1 Answers1

0

Any warp Filter should implement Clone, which includes BoxedFilter. So you should create the "server" once and clone it for each test client:

#[tokio::test]
async fn test_ws() {
    let server = get_server();

    let mut client1 = warp::test::ws()
        .path("/api/ws/test")
        .handshake(server.clone())
        .await
        .expect("handshake");

    let mut client2 = warp::test::ws()
        .path("/api/ws/test")
        .handshake(server.clone())
        .await
        .expect("handshake");

    // ... test away!
}
kmdreko
  • 42,554
  • 6
  • 57
  • 106