Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code changes for the new Clippy version and running test on Windows #1704

Merged
merged 13 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(unix)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests use use std::os::unix::fs::PermissionsExt which cannot be used on Windows.


use integration_test_runner::images::Collector;
use std::fs::File;
use std::os::unix::fs::PermissionsExt;
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-otlp/tests/integration_test/tests/traces.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(unix)]

use integration_test_runner::asserter::{read_spans_from_json, TraceAsserter};
use opentelemetry::global;
use opentelemetry::global::shutdown_tracer_provider;
Expand Down
17 changes: 15 additions & 2 deletions opentelemetry-prometheus/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,13 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &'
let encoder = TextEncoder::new();
let metric_families = registry.gather();
encoder.encode(&metric_families, &mut output).unwrap();
let output_string = String::from_utf8(output).unwrap();
let output_string;

if cfg!(windows) {
output_string = String::from_utf8(output).unwrap().replace("\n", "\r\n");
} else {
output_string = String::from_utf8(output).unwrap();
}

assert_eq!(output_string, expected, "{name}");
}
Expand Down Expand Up @@ -816,7 +822,14 @@ fn gather_and_compare_multi(
let encoder = TextEncoder::new();
let metric_families = registry.gather();
encoder.encode(&metric_families, &mut output).unwrap();
let output_string = String::from_utf8(output).unwrap();

let output_string;

if cfg!(windows) {
output_string = String::from_utf8(output).unwrap().replace("\n", "\r\n");
} else {
output_string = String::from_utf8(output).unwrap();
}

assert!(
expected.contains(&output_string),
Expand Down
21 changes: 14 additions & 7 deletions opentelemetry-proto/tests/grpc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"];

#[test]
fn build_tonic() {
let before_build = build_content_map(TONIC_OUT_DIR);
let before_build = build_content_map(TONIC_OUT_DIR, false);

let out_dir = TempDir::new().expect("failed to create temp dir to store the generated files");

Expand Down Expand Up @@ -95,11 +95,11 @@ fn build_tonic() {
.compile(TONIC_PROTO_FILES, TONIC_INCLUDES)
.expect("cannot compile protobuf using tonic");

let after_build = build_content_map(out_dir.path());
let after_build = build_content_map(out_dir.path(), true);
ensure_files_are_same(before_build, after_build, TONIC_OUT_DIR);
}

fn build_content_map(path: impl AsRef<Path>) -> HashMap<String, String> {
fn build_content_map(path: impl AsRef<Path>, normalize_line_feed: bool) -> HashMap<String, String> {
std::fs::read_dir(path)
.expect("cannot open dictionary of generated files")
.flatten()
Expand All @@ -108,10 +108,17 @@ fn build_content_map(path: impl AsRef<Path>) -> HashMap<String, String> {
let file_name = path
.file_name()
.expect("file name should always exist for generated files");
(
file_name.to_string_lossy().to_string(),
std::fs::read_to_string(path).expect("cannot read from existing generated file"),
)

let file_contents;
if normalize_line_feed && cfg!(windows) {
file_contents = std::fs::read_to_string(path.clone())
.expect("cannot read from existing generated file")
.replace("\n", "\r\n");
} else {
file_contents = std::fs::read_to_string(path.clone())
.expect("cannot read from existing generated file");
}
(file_name.to_string_lossy().to_string(), file_contents)
})
.collect()
}
Expand Down
4 changes: 3 additions & 1 deletion opentelemetry-sdk/src/metrics/periodic_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,11 @@ mod tests {
})
.expect("callback registration should succeed");

_ = meter_provider.force_flush();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why force_flush here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to trigger the callback code deterministically. This lets us assert things on the receiver end with certainty instead of waiting for interval * 2 milliseconds and hoping that the sender sends the data in that time.


// Assert
receiver
.recv_timeout(interval * 2)
.try_recv()
.expect("message should be available in channel, indicating a collection occurred");
}

Expand Down
Loading