Skip to content

Commit 75ea549

Browse files
committed
scylla unit tests: introduce setup_tracing()
Before, tracing crate's prints weren't captured during tests. Those with error level used to bloat tests' output, which was especially painful in CI. OTOH, we wanted to have traces visible in failed tests in order to easier spot the cause of a failure. By using tracing_subscriber's TestWriter, tracing's prints are now captured and only shown if a test fails. This enables efficient troubleshooting especially in case of flaky tests, as those are common in CI only and hard to be reproduced locally. For all tests to easily use the captured tracing, a function setup_tracing() is introduced. This commit adds it to scylla crate unit tests. Integration tests and proxy tests are covered in next commits.
1 parent 245ae7d commit 75ea549

30 files changed

+221
-24
lines changed

scylla/src/cloud/config.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ mod deserialize {
551551
#[cfg(test)]
552552
mod tests {
553553
use crate::cloud::config::deserialize::Parameters;
554+
use crate::test_utils::setup_tracing;
554555

555556
use super::super::CloudConfig;
556557
use super::RawCloudConfig;
@@ -599,6 +600,7 @@ mod deserialize {
599600

600601
#[test]
601602
fn test_cloud_config_dc_validation_no_cert_provided() {
603+
setup_tracing();
602604
let dc_no_cert = super::Datacenter {
603605
certificateAuthorityPath: None,
604606
certificateAuthorityData: None,
@@ -609,6 +611,7 @@ mod deserialize {
609611

610612
#[test]
611613
fn test_cloud_config_dc_validation_cert_not_found() {
614+
setup_tracing();
612615
let dc_cert_nonfound = super::Datacenter {
613616
certificateAuthorityPath: Some(NO_PEM_PATH.into()),
614617
certificateAuthorityData: None,
@@ -619,6 +622,7 @@ mod deserialize {
619622

620623
#[test]
621624
fn test_cloud_config_dc_validation_invalid_cert() {
625+
setup_tracing();
622626
let dc_invalid_cert = super::Datacenter {
623627
certificateAuthorityData: Some("INVALID CERFITICATE".into()),
624628
..dc_valid()
@@ -628,6 +632,7 @@ mod deserialize {
628632

629633
#[test]
630634
fn test_cloud_config_dc_validation_cert_found_bad() {
635+
setup_tracing();
631636
let dc_cert_found_bad = super::Datacenter {
632637
certificateAuthorityPath: Some(BAD_PEM_PATH.into()),
633638
certificateAuthorityData: None,
@@ -638,6 +643,7 @@ mod deserialize {
638643

639644
#[test]
640645
fn test_cloud_config_dc_validation_cert_found_good() {
646+
setup_tracing();
641647
let dc_cert_found_good = super::Datacenter {
642648
certificateAuthorityPath: Some(GOOD_PEM_PATH.into()),
643649
certificateAuthorityData: None,
@@ -648,6 +654,7 @@ mod deserialize {
648654

649655
#[test]
650656
fn test_cloud_config_dc_validation_domain_empty() {
657+
setup_tracing();
651658
let dc_bad_domain_empty = super::Datacenter {
652659
nodeDomain: "".into(),
653660
..dc_valid()
@@ -657,6 +664,7 @@ mod deserialize {
657664

658665
#[test]
659666
fn test_cloud_config_dc_validation_domain_trailing_minus() {
667+
setup_tracing();
660668
let dc_bad_domain_trailing_minus = super::Datacenter {
661669
nodeDomain: "cql.scylla-.com".into(),
662670
..dc_valid()
@@ -666,6 +674,7 @@ mod deserialize {
666674

667675
#[test]
668676
fn test_cloud_config_dc_validation_domain_interior_minus() {
677+
setup_tracing();
669678
let dc_good_domain_interior_minus = super::Datacenter {
670679
nodeDomain: "cql.scylla-cloud.com".into(),
671680
..dc_valid()
@@ -675,6 +684,7 @@ mod deserialize {
675684

676685
#[test]
677686
fn test_cloud_config_dc_validation_domain_special_sign() {
687+
setup_tracing();
678688
let dc_bad_domain_special_sign = super::Datacenter {
679689
nodeDomain: "cql.$cylla-cloud.com".into(),
680690
..dc_valid()
@@ -684,6 +694,7 @@ mod deserialize {
684694

685695
#[test]
686696
fn test_cloud_config_dc_validation_bad_server_url() {
697+
setup_tracing();
687698
let dc_bad_server_not_url = super::Datacenter {
688699
server: "NotAUrl".into(),
689700
..dc_valid()
@@ -699,6 +710,7 @@ mod deserialize {
699710

700711
#[test]
701712
fn test_cloud_config_unsupported_api_version() {
713+
setup_tracing();
702714
let mut config = RawCloudConfig::try_from(CCM_CONFIG).unwrap();
703715
config.apiVersion = Some("1.0".into());
704716
// The mere unknown api version should not be considered an erroneous input, but a warning will be logged.
@@ -707,6 +719,7 @@ mod deserialize {
707719

708720
#[test]
709721
fn test_cloud_config_deserialisation() {
722+
setup_tracing();
710723
{
711724
// CCM standard config
712725
let config = RawCloudConfig::try_from(CCM_CONFIG).unwrap();
@@ -786,6 +799,7 @@ mod deserialize {
786799

787800
#[test]
788801
fn test_cloud_config_validation() {
802+
setup_tracing();
789803
{
790804
// CCM standard config
791805
let config = RawCloudConfig::try_from(CCM_CONFIG).unwrap();

scylla/src/history.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ mod tests {
456456
};
457457

458458
use crate::{
459-
query::Query, retry_policy::RetryDecision, utils::test_utils::unique_keyspace_name,
459+
query::Query, retry_policy::RetryDecision, test_utils::setup_tracing,
460+
utils::test_utils::unique_keyspace_name,
460461
};
461462

462463
use super::{
@@ -589,6 +590,7 @@ mod tests {
589590

590591
#[test]
591592
fn empty_history() {
593+
setup_tracing();
592594
let history_collector = HistoryCollector::new();
593595
let history: StructuredHistory = history_collector.clone_structured_history();
594596

@@ -601,6 +603,7 @@ mod tests {
601603

602604
#[test]
603605
fn empty_query() {
606+
setup_tracing();
604607
let history_collector = HistoryCollector::new();
605608

606609
let _query_id: QueryId = history_collector.log_query_start();
@@ -625,6 +628,7 @@ mod tests {
625628

626629
#[test]
627630
fn one_attempt() {
631+
setup_tracing();
628632
let history_collector = HistoryCollector::new();
629633

630634
let query_id: QueryId = history_collector.log_query_start();
@@ -659,6 +663,7 @@ mod tests {
659663

660664
#[test]
661665
fn two_error_atempts() {
666+
setup_tracing();
662667
let history_collector = HistoryCollector::new();
663668

664669
let query_id: QueryId = history_collector.log_query_start();
@@ -709,6 +714,7 @@ mod tests {
709714

710715
#[test]
711716
fn empty_fibers() {
717+
setup_tracing();
712718
let history_collector = HistoryCollector::new();
713719

714720
let query_id: QueryId = history_collector.log_query_start();
@@ -750,6 +756,7 @@ mod tests {
750756

751757
#[test]
752758
fn complex() {
759+
setup_tracing();
753760
let history_collector = HistoryCollector::new();
754761

755762
let query_id: QueryId = history_collector.log_query_start();
@@ -854,6 +861,7 @@ mod tests {
854861

855862
#[test]
856863
fn multiple_queries() {
864+
setup_tracing();
857865
let history_collector = HistoryCollector::new();
858866

859867
let query1_id: QueryId = history_collector.log_query_start();
@@ -908,6 +916,7 @@ mod tests {
908916

909917
#[tokio::test]
910918
async fn successful_query_history() {
919+
setup_tracing();
911920
let session = create_new_session_builder().build().await.unwrap();
912921

913922
let mut query = Query::new("SELECT * FROM system.local");
@@ -974,6 +983,7 @@ mod tests {
974983

975984
#[tokio::test]
976985
async fn failed_query_history() {
986+
setup_tracing();
977987
let session = create_new_session_builder().build().await.unwrap();
978988

979989
let mut query = Query::new("This isnt even CQL");
@@ -1010,6 +1020,7 @@ mod tests {
10101020

10111021
#[tokio::test]
10121022
async fn iterator_query_history() {
1023+
setup_tracing();
10131024
let session = create_new_session_builder().build().await.unwrap();
10141025
let ks = unique_keyspace_name();
10151026
session

scylla/src/routing.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,15 @@ impl<'a> TryFrom<&'a HashMap<String, Vec<String>>> for ShardInfo {
135135

136136
#[cfg(test)]
137137
mod tests {
138+
use crate::test_utils::setup_tracing;
139+
138140
use super::Token;
139141
use super::{ShardCount, Sharder};
140142
use std::collections::HashSet;
141143

142144
#[test]
143145
fn test_shard_of() {
146+
setup_tracing();
144147
/* Test values taken from the gocql driver. */
145148
let sharder = Sharder::new(ShardCount::new(4).unwrap(), 12);
146149
assert_eq!(
@@ -159,6 +162,7 @@ mod tests {
159162

160163
#[test]
161164
fn test_iter_source_ports_for_shard() {
165+
setup_tracing();
162166
let nr_shards = 4;
163167
let max_port_num = 65535;
164168
let min_port_num = (49152 + nr_shards - 1) / nr_shards * nr_shards;

scylla/src/statement/prepared_statement.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ mod tests {
534534
types::serialize::row::SerializedValues,
535535
};
536536

537-
use crate::prepared_statement::PartitionKey;
537+
use crate::{prepared_statement::PartitionKey, test_utils::setup_tracing};
538538

539539
fn make_meta(
540540
cols: impl IntoIterator<Item = ColumnType>,
@@ -572,6 +572,7 @@ mod tests {
572572

573573
#[test]
574574
fn test_partition_key_multiple_columns_shuffled() {
575+
setup_tracing();
575576
let meta = make_meta(
576577
[
577578
ColumnType::TinyInt,

scylla/src/transport/authenticate_test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::authentication::{AuthError, AuthenticatorProvider, AuthenticatorSession};
2+
use crate::test_utils::setup_tracing;
23
use crate::utils::test_utils::unique_keyspace_name;
34
use async_trait::async_trait;
45
use bytes::{BufMut, BytesMut};
@@ -7,6 +8,7 @@ use std::sync::Arc;
78
#[tokio::test]
89
#[ignore]
910
async fn authenticate_superuser() {
11+
setup_tracing();
1012
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
1113

1214
println!("Connecting to {} with cassandra superuser ...", uri);
@@ -62,6 +64,7 @@ impl AuthenticatorProvider for CustomAuthenticatorProvider {
6264
#[tokio::test]
6365
#[ignore]
6466
async fn custom_authentication() {
67+
setup_tracing();
6568
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
6669

6770
println!("Connecting to {} with cassandra superuser ...", uri);

scylla/src/transport/caching_session.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ where
218218
#[cfg(test)]
219219
mod tests {
220220
use crate::query::Query;
221-
use crate::test_utils::create_new_session_builder;
221+
use crate::test_utils::{create_new_session_builder, setup_tracing};
222222
use crate::transport::partitioner::PartitionerName;
223223
use crate::utils::test_utils::unique_keyspace_name;
224224
use crate::{
@@ -281,6 +281,7 @@ mod tests {
281281
/// to the cache and a random query is removed
282282
#[tokio::test]
283283
async fn test_full() {
284+
setup_tracing();
284285
let session = create_caching_session().await;
285286

286287
let first_query = "select * from test_table";
@@ -315,6 +316,7 @@ mod tests {
315316
/// Checks that the same prepared statement is reused when executing the same query twice
316317
#[tokio::test]
317318
async fn test_execute_cached() {
319+
setup_tracing();
318320
let session = create_caching_session().await;
319321
let result = session
320322
.execute("select * from test_table", &[])
@@ -336,6 +338,7 @@ mod tests {
336338
/// Checks that caching works with execute_iter
337339
#[tokio::test]
338340
async fn test_execute_iter_cached() {
341+
setup_tracing();
339342
let session = create_caching_session().await;
340343

341344
assert!(session.cache.is_empty());
@@ -354,6 +357,7 @@ mod tests {
354357
/// Checks that caching works with execute_paged
355358
#[tokio::test]
356359
async fn test_execute_paged_cached() {
360+
setup_tracing();
357361
let session = create_caching_session().await;
358362

359363
assert!(session.cache.is_empty());
@@ -392,6 +396,7 @@ mod tests {
392396
/// This test checks that we can construct a CachingSession with custom HashBuilder implementations
393397
#[tokio::test]
394398
async fn test_custom_hasher() {
399+
setup_tracing();
395400
#[derive(Default, Clone)]
396401
struct CustomBuildHasher;
397402
impl std::hash::BuildHasher for CustomBuildHasher {
@@ -423,6 +428,7 @@ mod tests {
423428

424429
#[tokio::test]
425430
async fn test_batch() {
431+
setup_tracing();
426432
let session: CachingSession = create_caching_session().await;
427433

428434
session
@@ -545,6 +551,7 @@ mod tests {
545551
// Reproduces #597
546552
#[tokio::test]
547553
async fn test_parameters_caching() {
554+
setup_tracing();
548555
let session: CachingSession = CachingSession::from(new_for_test().await, 100);
549556

550557
session
@@ -592,6 +599,7 @@ mod tests {
592599
// Checks whether the PartitionerName is cached properly.
593600
#[tokio::test]
594601
async fn test_partitioner_name_caching() {
602+
setup_tracing();
595603
if option_env!("CDC") == Some("disabled") {
596604
return;
597605
}

scylla/src/transport/connection.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,7 @@ mod tests {
18771877

18781878
use super::ConnectionConfig;
18791879
use crate::query::Query;
1880+
use crate::test_utils::setup_tracing;
18801881
use crate::transport::connection::open_connection;
18811882
use crate::transport::node::ResolvedContactPoint;
18821883
use crate::transport::topology::UntranslatedEndpoint;
@@ -1910,6 +1911,7 @@ mod tests {
19101911
#[tokio::test]
19111912
#[cfg(not(scylla_cloud_tests))]
19121913
async fn connection_query_iter_test() {
1914+
setup_tracing();
19131915
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
19141916
let addr: SocketAddr = resolve_hostname(&uri).await;
19151917

@@ -2009,6 +2011,7 @@ mod tests {
20092011
#[tokio::test]
20102012
#[cfg(not(scylla_cloud_tests))]
20112013
async fn test_coalescing() {
2014+
setup_tracing();
20122015
// It's difficult to write a reliable test that checks whether coalescing
20132016
// works like intended or not. Instead, this is a smoke test which is supposed
20142017
// to trigger the coalescing logic and check that everything works fine
@@ -2124,6 +2127,7 @@ mod tests {
21242127

21252128
#[tokio::test]
21262129
async fn test_lwt_optimisation_mark_negotiation() {
2130+
setup_tracing();
21272131
const MASK: &str = "2137";
21282132

21292133
let lwt_optimisation_entry = format!("{}={}", LWT_OPTIMIZATION_META_BIT_MASK_KEY, MASK);
@@ -2204,6 +2208,7 @@ mod tests {
22042208
#[ntest::timeout(20000)]
22052209
#[cfg(not(scylla_cloud_tests))]
22062210
async fn connection_is_closed_on_no_response_to_keepalives() {
2211+
setup_tracing();
22072212
let proxy_addr = SocketAddr::new(scylla_proxy::get_exclusive_local_address(), 9042);
22082213
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
22092214
let node_addr: SocketAddr = resolve_hostname(&uri).await;

scylla/src/transport/connection_pool.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,7 @@ async fn open_connection_to_shard_aware_port(
12621262
mod tests {
12631263
use super::open_connection_to_shard_aware_port;
12641264
use crate::routing::{ShardCount, Sharder};
1265+
use crate::test_utils::setup_tracing;
12651266
use crate::transport::connection::ConnectionConfig;
12661267
use crate::transport::node::ResolvedContactPoint;
12671268
use crate::transport::topology::UntranslatedEndpoint;
@@ -1273,6 +1274,7 @@ mod tests {
12731274
#[tokio::test]
12741275
#[cfg(not(scylla_cloud_tests))]
12751276
async fn many_connections() {
1277+
setup_tracing();
12761278
let connections_number = 512;
12771279

12781280
let connect_address: SocketAddr = std::env::var("SCYLLA_URI")

0 commit comments

Comments
 (0)