Skip to content

Commit cf0b1cd

Browse files
authored
Merge pull request #959 from wprzytula/show-tracing-logs-iff-test-failed
Show tracing output only for failed tests
2 parents 245ae7d + 5cec4fa commit cf0b1cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+328
-74
lines changed

.github/workflows/authenticate_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
steps:
2929
- uses: actions/checkout@v3
3030
- name: Run tests
31-
run: cargo test --verbose authenticate_superuser -- custom_authentication --ignored
31+
run: RUST_LOG=trace cargo test --verbose authenticate_superuser -- custom_authentication --ignored

.github/workflows/cassandra.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
run: cargo build --verbose --tests --features "full-serialization"
3030
- name: Run tests on cassandra
3131
run: |
32-
CDC='disabled' SCYLLA_URI=172.42.0.2:9042 SCYLLA_URI2=172.42.0.3:9042 SCYLLA_URI3=172.42.0.4:9042 cargo test --verbose --features "full-serialization" -- --skip test_views_in_schema_info --skip test_large_batch_statements
32+
CDC='disabled' RUST_LOG=trace SCYLLA_URI=172.42.0.2:9042 SCYLLA_URI2=172.42.0.3:9042 SCYLLA_URI3=172.42.0.4:9042 cargo test --verbose --features "full-serialization" -- --skip test_views_in_schema_info --skip test_large_batch_statements
3333
- name: Stop the cluster
3434
if: ${{ always() }}
3535
run: docker compose -f test/cluster/cassandra/docker-compose.yml stop

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Run tests
5454
run: |
5555
cargo clean
56-
SCYLLA_URI=172.42.0.2:9042 SCYLLA_URI2=172.42.0.3:9042 SCYLLA_URI3=172.42.0.4:9042 cargo test --verbose --features "full-serialization"
56+
RUST_LOG=trace SCYLLA_URI=172.42.0.2:9042 SCYLLA_URI2=172.42.0.3:9042 SCYLLA_URI3=172.42.0.4:9042 cargo test --verbose --features "full-serialization"
5757
- name: Stop the cluster
5858
if: ${{ always() }}
5959
run: docker compose -f test/cluster/docker-compose.yml stop

.github/workflows/serverless.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Run cloud example
3636
run: cargo run --example cloud -- $HOME/.ccm/serverless/config_data.yaml
3737
- name: Run cloud tests
38-
run: CLOUD_CONFIG_PATH=$HOME/.ccm/serverless/config_data.yaml RUSTFLAGS="--cfg scylla_cloud_tests" cargo test --verbose
38+
run: CLOUD_CONFIG_PATH=$HOME/.ccm/serverless/config_data.yaml RUSTFLAGS="--cfg scylla_cloud_tests" RUST_LOG=trace cargo test --verbose
3939

4040
- name: Remove serverless cluster
4141
run: ccm remove serverless

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ The above commands will leave a running ScyllaDB cluster in the background.
4949
To stop it, use `make down`.\
5050
Starting a cluster without running any test is possible with `make up`.
5151

52+
### Tracing in tests
53+
54+
By default cargo captures `print!` macro's output from tests and prints them for failed tests.
55+
This is a bit problematic for us in case of `tracing` crate logs, because traces are not printed
56+
unless a subscriber is set. That's why we have a helper function for tests: `setup_tracing`.
57+
It sets up a tracing subscriber with env filter (so you can filter traces using env variables)
58+
and with a Writer that is compatible with test framework's output capturing.
59+
60+
Most of the tests already call this function, and any new tests should too.
61+
If you want to see tracing output from a failing test and it doesn't call this function,
62+
simply add the call at the beginning of the test.
63+
5264
## CI
5365

5466
Before sending a pull request, it is a good idea to run `make ci` locally (or `make dockerized-ci` if on macOS).

scylla-proxy/src/actions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use bytes::Bytes;
44
use rand::{Rng, RngCore};
55
use tokio::sync::mpsc;
66

7+
#[cfg(test)]
8+
use crate::setup_tracing;
9+
710
use crate::{
811
frame::{FrameOpcode, FrameParams, RequestFrame, RequestOpcode, ResponseFrame, ResponseOpcode},
912
TargetShard,
@@ -725,6 +728,7 @@ pub struct ResponseRule(pub Condition, pub ResponseReaction);
725728

726729
#[test]
727730
fn condition_case_insensitive_matching() {
731+
setup_tracing();
728732
let mut condition_matching =
729733
Condition::BodyContainsCaseInsensitive(Box::new(*b"cassandra'sInefficiency"));
730734
let mut condition_nonmatching =

scylla-proxy/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ pub use frame::{RequestFrame, RequestOpcode, ResponseFrame, ResponseOpcode};
1414
pub use proxy::{Node, Proxy, RunningProxy, ShardAwareness};
1515

1616
pub use proxy::get_exclusive_local_address;
17+
18+
#[cfg(test)]
19+
pub(crate) fn setup_tracing() {
20+
let _ = tracing_subscriber::fmt::fmt()
21+
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
22+
.with_writer(tracing_subscriber::fmt::TestWriter::new())
23+
.try_init();
24+
}

scylla-proxy/src/proxy.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,9 @@ pub fn get_exclusive_local_address() -> IpAddr {
12941294
mod tests {
12951295
use super::*;
12961296
use crate::frame::{read_frame, read_request_frame, FrameType};
1297-
use crate::{Condition, Reaction as _, RequestReaction, ResponseOpcode, ResponseReaction};
1297+
use crate::{
1298+
setup_tracing, Condition, Reaction as _, RequestReaction, ResponseOpcode, ResponseReaction,
1299+
};
12981300
use assert_matches::assert_matches;
12991301
use bytes::{BufMut, BytesMut};
13001302
use futures::future::{join, join3};
@@ -1308,15 +1310,6 @@ mod tests {
13081310
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
13091311
use tokio::sync::oneshot;
13101312

1311-
// This is for convenient logs from failing tests. Just call it at the beginning of a test.
1312-
#[allow(unused)]
1313-
fn init_logger() {
1314-
let _ = tracing_subscriber::fmt::fmt()
1315-
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
1316-
.without_time()
1317-
.try_init();
1318-
}
1319-
13201313
fn random_body() -> Bytes {
13211314
let body_len = (rand::random::<u32>() % 1000) as usize;
13221315
let mut body = BytesMut::zeroed(body_len);
@@ -1437,19 +1430,21 @@ mod tests {
14371430
#[tokio::test]
14381431
#[ntest::timeout(1000)]
14391432
async fn identity_shard_unaware_proxy_does_not_mutate_frames() {
1433+
setup_tracing();
14401434
identity_proxy_does_not_mutate_frames(ShardAwareness::Unaware).await
14411435
}
14421436

14431437
#[tokio::test]
14441438
#[ntest::timeout(1000)]
14451439
async fn identity_shard_aware_proxy_does_not_mutate_frames() {
1446-
init_logger();
1440+
setup_tracing();
14471441
identity_proxy_does_not_mutate_frames(ShardAwareness::QueryNode).await
14481442
}
14491443

14501444
#[tokio::test]
14511445
#[ntest::timeout(1000)]
14521446
async fn shard_aware_proxy_is_transparent_for_connection_to_shards() {
1447+
setup_tracing();
14531448
async fn test_for_shards_num(shards_num: u16) {
14541449
let node1_real_addr = next_local_address_with_port(9876);
14551450
let node1_proxy_addr = next_local_address_with_port(9876);
@@ -1499,6 +1494,7 @@ mod tests {
14991494
#[tokio::test]
15001495
#[ntest::timeout(1000)]
15011496
async fn shard_aware_proxy_queries_shards_number() {
1497+
setup_tracing();
15021498
async fn test_for_shards_num(shards_num: u16) {
15031499
for shard_num in 0..shards_num {
15041500
let node1_real_addr = next_local_address_with_port(9876);
@@ -1554,6 +1550,7 @@ mod tests {
15541550
#[tokio::test]
15551551
#[ntest::timeout(1000)]
15561552
async fn forger_proxy_forges_response() {
1553+
setup_tracing();
15571554
let node1_real_addr = next_local_address_with_port(9876);
15581555
let node1_proxy_addr = next_local_address_with_port(9876);
15591556

@@ -1685,6 +1682,7 @@ mod tests {
16851682
#[tokio::test]
16861683
#[ntest::timeout(1000)]
16871684
async fn ad_hoc_rules_changing() {
1685+
setup_tracing();
16881686
let node1_real_addr = next_local_address_with_port(9876);
16891687
let node1_proxy_addr = next_local_address_with_port(9876);
16901688
let proxy = Proxy::new([Node::new(
@@ -1779,6 +1777,7 @@ mod tests {
17791777
#[tokio::test]
17801778
#[ntest::timeout(2000)]
17811779
async fn limited_times_condition_expires() {
1780+
setup_tracing();
17821781
const FAILING_TRIES: usize = 4;
17831782
const PASSING_TRIES: usize = 5;
17841783

@@ -1880,6 +1879,7 @@ mod tests {
18801879
#[tokio::test]
18811880
#[ntest::timeout(1000)]
18821881
async fn proxy_reports_requests_and_responses_as_feedback() {
1882+
setup_tracing();
18831883
let node1_real_addr = next_local_address_with_port(9876);
18841884
let node1_proxy_addr = next_local_address_with_port(9876);
18851885

@@ -1952,6 +1952,7 @@ mod tests {
19521952
#[tokio::test]
19531953
#[ntest::timeout(1000)]
19541954
async fn sanity_check_reports_errors() {
1955+
setup_tracing();
19551956
let node1_real_addr = next_local_address_with_port(9876);
19561957
let node1_proxy_addr = next_local_address_with_port(9876);
19571958
let proxy = Proxy::new([Node::new(
@@ -2002,7 +2003,7 @@ mod tests {
20022003
#[tokio::test]
20032004
#[ntest::timeout(1000)]
20042005
async fn proxy_processes_requests_concurrently() {
2005-
init_logger();
2006+
setup_tracing();
20062007
let node1_real_addr = next_local_address_with_port(9876);
20072008
let node1_proxy_addr = next_local_address_with_port(9876);
20082009

@@ -2076,6 +2077,7 @@ mod tests {
20762077
#[tokio::test]
20772078
#[ntest::timeout(1000)]
20782079
async fn dry_mode_proxy_drops_incoming_frames() {
2080+
setup_tracing();
20792081
let node1_proxy_addr = next_local_address_with_port(9876);
20802082
let proxy = Proxy::new([Node::new_dry_mode(node1_proxy_addr, None)]);
20812083
let running_proxy = proxy.run().await.unwrap();
@@ -2100,6 +2102,7 @@ mod tests {
21002102
#[tokio::test]
21012103
#[ntest::timeout(1000)]
21022104
async fn dry_mode_forger_proxy_forges_response() {
2105+
setup_tracing();
21032106
let node1_proxy_addr = next_local_address_with_port(9876);
21042107

21052108
let this_shall_pass = b"This.Shall.Pass.";
@@ -2207,7 +2210,7 @@ mod tests {
22072210
#[tokio::test]
22082211
#[ntest::timeout(1000)]
22092212
async fn proxy_reports_target_shard_as_feedback() {
2210-
init_logger();
2213+
setup_tracing();
22112214

22122215
let node_port = 10101;
22132216
let node_real_addr = next_local_address_with_port(node_port);
@@ -2355,6 +2358,7 @@ mod tests {
23552358
#[tokio::test]
23562359
#[ntest::timeout(1000)]
23572360
async fn proxy_ignores_control_connection_messages() {
2361+
setup_tracing();
23582362
let node1_real_addr = next_local_address_with_port(9876);
23592363
let node1_proxy_addr = next_local_address_with_port(9876);
23602364

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();

0 commit comments

Comments
 (0)