Skip to content

Commit

Permalink
session_test: added test for request timeouts
Browse files Browse the repository at this point in the history
As tokio timeout supports minimal granularity of 1 ms, the test can
be only reliable on remote Scyllas, as local ones respond faster.
Therefore, the rest is marked as ignored.
As all ignored tests were run in Authenticate CI workflow, it was made
specific to avoid running the new request timeouts test.
  • Loading branch information
wprzytula committed Aug 23, 2022
1 parent f80c74e commit 01fe25f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/authenticate_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Run tests
run: cargo test --verbose -- --ignored
run: cargo test --verbose authenticate_superuser -- --ignored
1 change: 1 addition & 0 deletions scylla/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ smallvec = "1.8.0"
[dev-dependencies]
criterion = "0.3"
tracing-subscriber = "0.3.14"
assert_matches = "1.5.0"

[[bench]]
name = "benchmark"
Expand Down
69 changes: 69 additions & 0 deletions scylla/src/transport/session_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::transport::topology::{CollectionType, ColumnKind, CqlType, NativeType
use crate::CachingSession;
use crate::QueryResult;
use crate::{IntoTypedRows, Session, SessionBuilder};
use assert_matches::assert_matches;
use bytes::Bytes;
use futures::{FutureExt, StreamExt};
use itertools::Itertools;
Expand Down Expand Up @@ -1181,6 +1182,74 @@ async fn test_timestamp() {
assert_eq!(results, expected_results);
}

#[ignore = "works on remote Scylla instances only (local ones are too fast)"]
#[tokio::test]
async fn test_request_timeout() {
use std::time::Duration;
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());

{
let session = SessionBuilder::new()
.known_node(uri.as_str())
.build()
.await
.unwrap();

let mut query: Query = Query::new("SELECT * FROM system_schema.tables");
query.set_request_timeout(Some(Duration::from_millis(1)));
match session.query(query, &[]).await {
Ok(_) => panic!("the query should have failed due to a client-side timeout"),
Err(e) => assert_matches!(e, QueryError::RequestTimeout(_)),
}

let mut prepared = session
.prepare("SELECT * FROM system_schema.tables")
.await
.unwrap();

prepared.set_request_timeout(Some(Duration::from_millis(1)));
match session.execute(&prepared, &[]).await {
Ok(_) => panic!("the prepared query should have failed due to a client-side timeout"),
Err(e) => assert_matches!(e, QueryError::RequestTimeout(_)),
};
}
{
let timeouting_session = SessionBuilder::new()
.known_node(uri)
.request_timeout(Some(Duration::from_millis(1)))
.build()
.await
.unwrap();

let mut query = Query::new("SELECT * FROM system_schema.tables");

match timeouting_session.query(query.clone(), &[]).await {
Ok(_) => panic!("the query should have failed due to a client-side timeout"),
Err(e) => assert_matches!(e, QueryError::RequestTimeout(_)),
};

query.set_request_timeout(Some(Duration::from_secs(10000)));

timeouting_session.query(query, &[]).await.expect(
"the query should have not failed, because no client-side timeout was specified",
);

let mut prepared = timeouting_session
.prepare("SELECT * FROM system_schema.tables")
.await
.unwrap();

match timeouting_session.execute(&prepared, &[]).await {
Ok(_) => panic!("the prepared query should have failed due to a client-side timeout"),
Err(e) => assert_matches!(e, QueryError::RequestTimeout(_)),
};

prepared.set_request_timeout(Some(Duration::from_secs(10000)));

timeouting_session.execute(&prepared, &[]).await.expect("the prepared query should have not failed, because no client-side timeout was specified");
}
}

#[tokio::test]
async fn test_prepared_config() {
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
Expand Down

0 comments on commit 01fe25f

Please sign in to comment.