Skip to content

Commit 0c25a13

Browse files
committed
Update tests
1 parent ccd5f08 commit 0c25a13

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

opentelemetry-otlp/tests/integration_test/tests/integration_tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(unix)]
2+
13
use integration_test_runner::images::Collector;
24
use std::fs::File;
35
use std::os::unix::fs::PermissionsExt;

opentelemetry-otlp/tests/integration_test/tests/traces.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(unix)]
2+
13
use integration_test_runner::asserter::{read_spans_from_json, TraceAsserter};
24
use opentelemetry::global;
35
use opentelemetry::global::shutdown_tracer_provider;

opentelemetry-prometheus/tests/integration_test.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,14 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &'
405405
let encoder = TextEncoder::new();
406406
let metric_families = registry.gather();
407407
encoder.encode(&metric_families, &mut output).unwrap();
408-
let output_string = String::from_utf8(output).unwrap();
408+
let output_string;
409+
410+
if cfg!(windows) {
411+
output_string = String::from_utf8(output).unwrap().replace("\n", "\r\n");
412+
}
413+
else {
414+
output_string = String::from_utf8(output).unwrap();
415+
}
409416

410417
assert_eq!(output_string, expected, "{name}");
411418
}
@@ -816,7 +823,15 @@ fn gather_and_compare_multi(
816823
let encoder = TextEncoder::new();
817824
let metric_families = registry.gather();
818825
encoder.encode(&metric_families, &mut output).unwrap();
819-
let output_string = String::from_utf8(output).unwrap();
826+
827+
let output_string;
828+
829+
if cfg!(windows) {
830+
output_string = String::from_utf8(output).unwrap().replace("\n", "\r\n");
831+
}
832+
else {
833+
output_string = String::from_utf8(output).unwrap();
834+
}
820835

821836
assert!(
822837
expected.contains(&output_string),

opentelemetry-proto/tests/grpc_build.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"];
1818

1919
#[test]
2020
fn build_tonic() {
21-
let before_build = build_content_map(TONIC_OUT_DIR);
21+
let before_build = build_content_map(TONIC_OUT_DIR, false);
2222

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

@@ -95,11 +95,11 @@ fn build_tonic() {
9595
.compile(TONIC_PROTO_FILES, TONIC_INCLUDES)
9696
.expect("cannot compile protobuf using tonic");
9797

98-
let after_build = build_content_map(out_dir.path());
98+
let after_build = build_content_map(out_dir.path(), true);
9999
ensure_files_are_same(before_build, after_build, TONIC_OUT_DIR);
100100
}
101101

102-
fn build_content_map(path: impl AsRef<Path>) -> HashMap<String, String> {
102+
fn build_content_map(path: impl AsRef<Path>, normalize_line_feed: bool) -> HashMap<String, String> {
103103
std::fs::read_dir(path)
104104
.expect("cannot open dictionary of generated files")
105105
.flatten()
@@ -108,9 +108,18 @@ fn build_content_map(path: impl AsRef<Path>) -> HashMap<String, String> {
108108
let file_name = path
109109
.file_name()
110110
.expect("file name should always exist for generated files");
111+
112+
let file_contents;
113+
if normalize_line_feed && cfg!(windows) {
114+
file_contents = std::fs::read_to_string(path.clone()).expect("cannot read from existing generated file").replace("\n", "\r\n");
115+
}
116+
else {
117+
file_contents = std::fs::read_to_string(path.clone()).expect("cannot read from existing generated file");
118+
}
119+
111120
(
112121
file_name.to_string_lossy().to_string(),
113-
std::fs::read_to_string(path).expect("cannot read from existing generated file"),
122+
file_contents,
114123
)
115124
})
116125
.collect()

opentelemetry-sdk/src/metrics/periodic_reader.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,11 @@ mod tests {
435435
})
436436
.expect("callback registration should succeed");
437437

438+
_ = meter_provider.force_flush();
439+
438440
// Assert
439441
receiver
440-
.recv_timeout(interval * 2)
442+
.try_recv()
441443
.expect("message should be available in channel, indicating a collection occurred");
442444
}
443445

0 commit comments

Comments
 (0)