File: timeout.rs

package info (click to toggle)
rust-wiremock 0.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 424 kB
  • sloc: makefile: 2
file content (36 lines) | stat: -rw-r--r-- 857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use reqwest::Client;
use wiremock::matchers::any;
use wiremock::{Mock, MockServer, ResponseTemplate};

async fn test_body() {
    // Arrange
    let mock_server = MockServer::start().await;

    let response = ResponseTemplate::new(200).set_delay(std::time::Duration::from_secs(60));
    Mock::given(any())
        .respond_with(response)
        .mount(&mock_server)
        .await;

    // Act
    let outcome = Client::builder()
        .timeout(std::time::Duration::from_secs(1))
        .build()
        .unwrap()
        .get(&mock_server.uri())
        .send()
        .await;

    // Assert
    assert!(outcome.is_err());
}

#[actix_rt::test]
async fn request_times_out_if_the_server_takes_too_long_with_actix() {
    test_body().await
}

#[tokio::test]
async fn request_times_out_if_the_server_takes_too_long_with_tokio() {
    test_body().await
}