Skip to content

Commit 01fe25f

Browse files
committed
session_test: added test for request timeouts
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.
1 parent f80c74e commit 01fe25f

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

.github/workflows/authenticate_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
steps:
2525
- uses: actions/checkout@v2
2626
- name: Run tests
27-
run: cargo test --verbose -- --ignored
27+
run: cargo test --verbose authenticate_superuser -- --ignored

scylla/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ smallvec = "1.8.0"
4747
[dev-dependencies]
4848
criterion = "0.3"
4949
tracing-subscriber = "0.3.14"
50+
assert_matches = "1.5.0"
5051

5152
[[bench]]
5253
name = "benchmark"

scylla/src/transport/session_test.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::transport::topology::{CollectionType, ColumnKind, CqlType, NativeType
1414
use crate::CachingSession;
1515
use crate::QueryResult;
1616
use crate::{IntoTypedRows, Session, SessionBuilder};
17+
use assert_matches::assert_matches;
1718
use bytes::Bytes;
1819
use futures::{FutureExt, StreamExt};
1920
use itertools::Itertools;
@@ -1181,6 +1182,74 @@ async fn test_timestamp() {
11811182
assert_eq!(results, expected_results);
11821183
}
11831184

1185+
#[ignore = "works on remote Scylla instances only (local ones are too fast)"]
1186+
#[tokio::test]
1187+
async fn test_request_timeout() {
1188+
use std::time::Duration;
1189+
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
1190+
1191+
{
1192+
let session = SessionBuilder::new()
1193+
.known_node(uri.as_str())
1194+
.build()
1195+
.await
1196+
.unwrap();
1197+
1198+
let mut query: Query = Query::new("SELECT * FROM system_schema.tables");
1199+
query.set_request_timeout(Some(Duration::from_millis(1)));
1200+
match session.query(query, &[]).await {
1201+
Ok(_) => panic!("the query should have failed due to a client-side timeout"),
1202+
Err(e) => assert_matches!(e, QueryError::RequestTimeout(_)),
1203+
}
1204+
1205+
let mut prepared = session
1206+
.prepare("SELECT * FROM system_schema.tables")
1207+
.await
1208+
.unwrap();
1209+
1210+
prepared.set_request_timeout(Some(Duration::from_millis(1)));
1211+
match session.execute(&prepared, &[]).await {
1212+
Ok(_) => panic!("the prepared query should have failed due to a client-side timeout"),
1213+
Err(e) => assert_matches!(e, QueryError::RequestTimeout(_)),
1214+
};
1215+
}
1216+
{
1217+
let timeouting_session = SessionBuilder::new()
1218+
.known_node(uri)
1219+
.request_timeout(Some(Duration::from_millis(1)))
1220+
.build()
1221+
.await
1222+
.unwrap();
1223+
1224+
let mut query = Query::new("SELECT * FROM system_schema.tables");
1225+
1226+
match timeouting_session.query(query.clone(), &[]).await {
1227+
Ok(_) => panic!("the query should have failed due to a client-side timeout"),
1228+
Err(e) => assert_matches!(e, QueryError::RequestTimeout(_)),
1229+
};
1230+
1231+
query.set_request_timeout(Some(Duration::from_secs(10000)));
1232+
1233+
timeouting_session.query(query, &[]).await.expect(
1234+
"the query should have not failed, because no client-side timeout was specified",
1235+
);
1236+
1237+
let mut prepared = timeouting_session
1238+
.prepare("SELECT * FROM system_schema.tables")
1239+
.await
1240+
.unwrap();
1241+
1242+
match timeouting_session.execute(&prepared, &[]).await {
1243+
Ok(_) => panic!("the prepared query should have failed due to a client-side timeout"),
1244+
Err(e) => assert_matches!(e, QueryError::RequestTimeout(_)),
1245+
};
1246+
1247+
prepared.set_request_timeout(Some(Duration::from_secs(10000)));
1248+
1249+
timeouting_session.execute(&prepared, &[]).await.expect("the prepared query should have not failed, because no client-side timeout was specified");
1250+
}
1251+
}
1252+
11841253
#[tokio::test]
11851254
async fn test_prepared_config() {
11861255
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());

0 commit comments

Comments
 (0)