Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions proto/proto/test_context.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ message LineNumber {
}

message TestOutput {
// Typically the full message, including backtrace if applicable
string text = 1;
// Typically the short failure message
string message = 2;
string system_out = 3;
string system_err = 4;
Expand Down
15 changes: 12 additions & 3 deletions rspec-trunk-flaky-tests/lib/trunk_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def run
# TrunkAnalyticsListener is a class that is used to listen to the execution of the Example class
# it generates and submits the final test reports
class TrunkAnalyticsListener
MAX_TEXT_FIELD_SIZE = 8_000

def initialize
@testreport = $test_report
end
Expand Down Expand Up @@ -221,8 +223,15 @@ def close(_notification)

# trunk-ignore(rubocop/Metrics/CyclomaticComplexity,rubocop/Metrics/AbcSize,rubocop/Metrics/MethodLength)
def add_test_case(example)
failure_message = example.exception.to_s if example.exception
failure_message = example.metadata[:quarantined_exception].to_s if example.metadata[:quarantined_exception]
exception = example.exception || example.metadata[:quarantined_exception]
failure_message = ''
backtrace = ''
if exception
failure_message = exception.to_s
backtrace = exception.backtrace.join("\n") if exception.backtrace && !exception.backtrace.empty?
end
failure_message = failure_message[0...MAX_TEXT_FIELD_SIZE] if failure_message.length > MAX_TEXT_FIELD_SIZE
backtrace = backtrace[0...MAX_TEXT_FIELD_SIZE] if backtrace.length > MAX_TEXT_FIELD_SIZE
# TODO: should we use concatenated string or alias when auto-generated description?
name = example.full_description
file = escape(example.metadata[:file_path])
Expand All @@ -247,7 +256,7 @@ def add_test_case(example)
parent_name = example.example_group.metadata[:description]
parent_name = parent_name.empty? ? 'rspec' : parent_name
@testreport.add_test(id, name, classname, file, parent_name, line, status, attempt_number,
started_at, finished_at, failure_message || '', is_quarantined)
started_at, finished_at, failure_message || '', backtrace || '', is_quarantined)
end
end

Expand Down
11 changes: 6 additions & 5 deletions test_report/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
variant: variant.clone().unwrap_or_default(),
});
let test_report = TestReportProto {
// trunk-ignore(clippy/deprecated)

Check notice on line 164 in test_report/src/report.rs

View workflow job for this annotation

GitHub Actions / Trunk Check

trunk(ignore-does-nothing)

[new] trunk-ignore(clippy/deprecated) is not suppressing a lint issue
uploader_metadata: test_result.uploader_metadata.clone(),
test_results: vec![test_result],
};
Expand Down Expand Up @@ -234,7 +234,7 @@
let repo_root = self.get_repo_root();
let command_string = self.0.borrow().command.clone();
let sentry_layer = sentry_tracing::layer().event_mapper(move |event, context| {
// trunk-ignore(clippy/match_ref_pats)

Check notice on line 237 in test_report/src/report.rs

View workflow job for this annotation

GitHub Actions / Trunk Check

trunk(ignore-does-nothing)

[new] trunk-ignore(clippy/match_ref_pats) is not suppressing a lint issue
match event.metadata().level() {
&tracing::Level::ERROR => {
let mut event = sentry_tracing::event_from_event(event, context);
Expand Down Expand Up @@ -554,7 +554,7 @@
let test_report = &mut self.0.borrow_mut().test_report;
// legacy: update the variant in all test results
for test_result in &mut test_report.test_results {
// trunk-ignore(clippy/deprecated)

Check notice on line 557 in test_report/src/report.rs

View workflow job for this annotation

GitHub Actions / Trunk Check

trunk(ignore-does-nothing)

[new] trunk-ignore(clippy/deprecated) is not suppressing a lint issue
if let Some(uploader_metadata) = &mut test_result.uploader_metadata {
uploader_metadata.variant = variant.clone();
}
Expand Down Expand Up @@ -727,7 +727,8 @@
attempt_number: i32,
started_at: i64,
finished_at: i64,
output: String,
failure_text: String,
backtrace: String,
is_quarantined: bool,
) {
let mut test = TestCaseRun::default();
Expand Down Expand Up @@ -778,12 +779,12 @@
nanos: finished_at_date_time.timestamp_subsec_nanos() as i32,
};
test.finished_at = Some(test_finished_at);
// trunk-ignore(clippy/deprecated)

Check notice on line 782 in test_report/src/report.rs

View workflow job for this annotation

GitHub Actions / Trunk Check

trunk(ignore-does-nothing)

[new] trunk-ignore(clippy/deprecated) is not suppressing a lint issue
test.status_output_message = output.clone();
test.status_output_message = failure_text.clone();
if status != Status::Success {
test.test_output = Some(TestOutput {
text: output,
message: "".into(),
text: backtrace,
message: failure_text,
system_out: "".into(),
system_err: "".into(),
});
Expand Down Expand Up @@ -828,7 +829,7 @@
test_report.define_singleton_method("new", magnus::function!(MutTestReport::new, 3))?;
test_report.define_method("to_s", magnus::method!(MutTestReport::to_string, 0))?;
test_report.define_method("publish", magnus::method!(MutTestReport::publish, 0))?;
test_report.define_method("add_test", magnus::method!(MutTestReport::add_test, 12))?;
test_report.define_method("add_test", magnus::method!(MutTestReport::add_test, 13))?;
test_report.define_method("try_save", magnus::method!(MutTestReport::try_save, 1))?;
test_report.define_method(
"is_quarantined",
Expand Down
8 changes: 6 additions & 2 deletions test_report/tests/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
1000,
1001,
"test-message".into(),
"test-backtrace".into(),
false,
);
// call this twice to later validate we only send one request
Expand Down Expand Up @@ -129,6 +130,7 @@
1000,
1001,
"test-message".into(),
"test-backtrace".into(),
true,
);
let result = test_report.publish();
Expand Down Expand Up @@ -270,8 +272,8 @@
assert_eq!(
test_case_run.test_output,
Some(TestOutput {
text: "test-message".into(),
message: "".into(),
text: "test-backtrace".into(),
message: "test-message".into(),
system_out: "".into(),
system_err: "".into(),
})
Expand Down Expand Up @@ -369,6 +371,7 @@
1000,
1001,
"test-message".into(),
"test-backtrace".into(),
false,
);
let result = test_report.publish();
Expand Down Expand Up @@ -429,7 +432,7 @@
let bin = fs::read(tar_extract_directory.join(&bundled_file.path)).unwrap();
let report = TestReport::decode(&*bin).unwrap();
let test_result = report.test_results.first().unwrap();
// trunk-ignore(clippy/deprecated)

Check notice on line 435 in test_report/tests/report.rs

View workflow job for this annotation

GitHub Actions / Trunk Check

trunk(ignore-does-nothing)

[new] trunk-ignore(clippy/deprecated) is not suppressing a lint issue
if let Some(uploader_metadata) = &test_result.uploader_metadata {
assert_eq!(uploader_metadata.variant, "env-variant");
}
Expand Down Expand Up @@ -500,6 +503,7 @@
1000,
1001,
"test-message".into(),
"test-backtrace".into(),
false,
);
let result = test_report.publish();
Expand Down
Loading