Skip to content

Commit 47f50ae

Browse files
feat: use docker cli instead of relying on testcontainers (#1224)
* feat: use docker cli instead of relying on tst containers # Motivations Both testcontainers and httpmock have a lot of dependencies which we don't use elsewhere (some of them duplicates with incompatible versions). This makes building tests quite a bit slower... Also since testcontainer uses the docker sock, which is not available by default on mac, running the tests on a brand new mac install requires some extra setup. In total this PR drops 60 tests dependencies on the data-pipeline crare # Changes * testcontainers can be replaced by running a few command with the docker cli directly, * httpmock has been updated to the latest version, which uses hyper 1.0 instead of 0.14, which means deps are reusable now
1 parent 1c3e746 commit 47f50ae

File tree

23 files changed

+10915
-17665
lines changed

23 files changed

+10915
-17665
lines changed

Cargo.lock

Lines changed: 139 additions & 856 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ members = [
4343
"tinybytes",
4444
"dogstatsd-client",
4545
"datadog-log",
46-
"datadog-log-ffi"
46+
"datadog-log-ffi",
4747
]
4848

4949
# https://doc.rust-lang.org/cargo/reference/resolver.html
@@ -65,6 +65,17 @@ edition = "2021"
6565
version = "21.0.0"
6666
license = "Apache-2.0"
6767

68+
[workspace.dependencies]
69+
hyper = { version = "1.6", features = [
70+
"http1",
71+
"client",
72+
], default-features = false }
73+
hyper-util = { version = "0.1.10", features = [
74+
"http1",
75+
"client",
76+
"client-legacy",
77+
] }
78+
6879
[profile.dev]
6980
debug = 2 # full debug info
7081

LICENSE-3rdparty.yml

Lines changed: 10578 additions & 16663 deletions
Large diffs are not rendered by default.

data-pipeline-ffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cbindgen = ["build_common/cbindgen", "ddcommon-ffi/cbindgen"]
2323
build_common = { path = "../build-common" }
2424

2525
[dev-dependencies]
26-
httpmock = "0.7.0"
26+
httpmock = "0.8.0-alpha.1"
2727
rmp-serde = "1.1.1"
2828
datadog-trace-utils = { path = "../datadog-trace-utils" }
2929

data-pipeline-ffi/src/trace_exporter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,8 +1080,8 @@ mod tests {
10801080
let mock_metrics = server.mock(|when, then| {
10811081
when.method(POST)
10821082
.path("/telemetry/proxy/api/v2/apmtelemetry")
1083-
.body_contains(r#""runtime_id":"foo""#)
1084-
.body_contains(r#""metric":"trace_api."#);
1083+
.body_includes(r#""runtime_id":"foo""#)
1084+
.body_includes(r#""metric":"trace_api."#);
10851085
then.status(200)
10861086
.header("content-type", "application/json")
10871087
.body("");
@@ -1134,7 +1134,7 @@ mod tests {
11341134

11351135
ddog_trace_exporter_free(exporter);
11361136
// It should receive 1 metrics payload (excluding heartbeats)
1137-
mock_metrics.assert_hits(1);
1137+
mock_metrics.assert_calls(1);
11381138
}
11391139
}
11401140

data-pipeline/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ autobenches = false
1212
[dependencies]
1313
anyhow = { version = "1.0" }
1414
arc-swap = "1.7.1"
15-
hyper = { version = "1.6", features = ["http1", "client"] }
16-
hyper-util = { version = "0.1", features = ["client", "client-legacy"] }
15+
hyper = { workspace = true }
16+
hyper-util = { workspace = true }
1717
http = "1.0"
1818
http-body-util = "0.1"
1919
tracing = { version = "0.1", default-features = false }
@@ -55,7 +55,7 @@ criterion = "0.5.1"
5555
datadog-trace-utils = { path = "../datadog-trace-utils", features = [
5656
"test-utils",
5757
] }
58-
httpmock = "0.7.0"
58+
httpmock = "0.8.0-alpha.1"
5959
rand = "0.8.5"
6060
regex = "1.5"
6161
tempfile = "3.3.0"

data-pipeline/src/agent_info/fetcher.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ mod single_threaded_tests {
382382
.await
383383
.unwrap();
384384

385-
mock.assert_hits(2);
385+
mock.assert_calls(2);
386386
assert!(
387387
matches!(new_state_info_status, FetchInfoStatus::NewState(info) if *info == AgentInfo {
388388
state_hash: TEST_INFO_HASH.to_string(),
@@ -466,7 +466,7 @@ mod single_threaded_tests {
466466
.await;
467467

468468
// Wait for second fetch
469-
while mock_v2.hits_async().await == 0 {
469+
while mock_v2.calls_async().await == 0 {
470470
tokio::time::sleep(Duration::from_millis(100)).await;
471471
}
472472

@@ -533,13 +533,13 @@ mod single_threaded_tests {
533533
const SLEEP_DURATION_MS: u64 = 10;
534534

535535
let mut attempts = 0;
536-
while mock.hits_async().await == 0 && attempts < MAX_ATTEMPTS {
536+
while mock.calls_async().await == 0 && attempts < MAX_ATTEMPTS {
537537
attempts += 1;
538538
tokio::time::sleep(Duration::from_millis(SLEEP_DURATION_MS)).await;
539539
}
540540

541541
// Should trigger a fetch since the state is different
542-
mock.assert_hits_async(1).await;
542+
mock.assert_calls_async(1).await;
543543

544544
// Wait for the cache to be updated with proper timeout
545545
let mut attempts = 0;
@@ -616,6 +616,6 @@ mod single_threaded_tests {
616616
tokio::time::sleep(Duration::from_millis(500)).await;
617617

618618
// Should not trigger a fetch since the state is the same
619-
mock.assert_hits_async(0).await;
619+
mock.assert_calls_async(0).await;
620620
}
621621
}

data-pipeline/src/stats_exporter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ mod tests {
253253
when.method(POST)
254254
.header("Content-type", "application/msgpack")
255255
.path("/v0.6/stats")
256-
.body_contains("libdatadog-test");
256+
.body_includes("libdatadog-test");
257257
then.status(200).body("");
258258
})
259259
.await;
@@ -312,7 +312,7 @@ mod tests {
312312
when.method(POST)
313313
.header("Content-type", "application/msgpack")
314314
.path("/v0.6/stats")
315-
.body_contains("libdatadog-test");
315+
.body_includes("libdatadog-test");
316316
then.status(200).body("");
317317
})
318318
.await;
@@ -349,7 +349,7 @@ mod tests {
349349
when.method(POST)
350350
.header("Content-type", "application/msgpack")
351351
.path("/v0.6/stats")
352-
.body_contains("libdatadog-test");
352+
.body_includes("libdatadog-test");
353353
then.status(200).body("");
354354
})
355355
.await;

data-pipeline/src/telemetry/mod.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,10 @@ mod tests {
368368
client.start().await;
369369
let _ = client.send(&data);
370370
client.shutdown().await;
371-
while telemetry_srv.hits_async().await == 0 {
371+
while telemetry_srv.calls_async().await == 0 {
372372
sleep(Duration::from_millis(10)).await;
373373
}
374-
telemetry_srv.assert_hits_async(1).await;
374+
telemetry_srv.assert_calls_async(1).await;
375375
}
376376

377377
#[cfg_attr(miri, ignore)]
@@ -397,10 +397,10 @@ mod tests {
397397
client.start().await;
398398
let _ = client.send(&data);
399399
client.shutdown().await;
400-
while telemetry_srv.hits_async().await == 0 {
400+
while telemetry_srv.calls_async().await == 0 {
401401
sleep(Duration::from_millis(10)).await;
402402
}
403-
telemetry_srv.assert_hits_async(1).await;
403+
telemetry_srv.assert_calls_async(1).await;
404404
}
405405

406406
#[cfg_attr(miri, ignore)]
@@ -426,10 +426,10 @@ mod tests {
426426
client.start().await;
427427
let _ = client.send(&data);
428428
client.shutdown().await;
429-
while telemetry_srv.hits_async().await == 0 {
429+
while telemetry_srv.calls_async().await == 0 {
430430
sleep(Duration::from_millis(10)).await;
431431
}
432-
telemetry_srv.assert_hits_async(1).await;
432+
telemetry_srv.assert_calls_async(1).await;
433433
}
434434

435435
#[cfg_attr(miri, ignore)]
@@ -455,10 +455,10 @@ mod tests {
455455
client.start().await;
456456
let _ = client.send(&data);
457457
client.shutdown().await;
458-
while telemetry_srv.hits_async().await == 0 {
458+
while telemetry_srv.calls_async().await == 0 {
459459
sleep(Duration::from_millis(10)).await;
460460
}
461-
telemetry_srv.assert_hits_async(1).await;
461+
telemetry_srv.assert_calls_async(1).await;
462462
}
463463

464464
#[cfg_attr(miri, ignore)]
@@ -484,10 +484,10 @@ mod tests {
484484
client.start().await;
485485
let _ = client.send(&data);
486486
client.shutdown().await;
487-
while telemetry_srv.hits_async().await == 0 {
487+
while telemetry_srv.calls_async().await == 0 {
488488
sleep(Duration::from_millis(10)).await;
489489
}
490-
telemetry_srv.assert_hits_async(1).await;
490+
telemetry_srv.assert_calls_async(1).await;
491491
}
492492

493493
#[cfg_attr(miri, ignore)]
@@ -513,10 +513,10 @@ mod tests {
513513
client.start().await;
514514
let _ = client.send(&data);
515515
client.shutdown().await;
516-
while telemetry_srv.hits_async().await == 0 {
516+
while telemetry_srv.calls_async().await == 0 {
517517
sleep(Duration::from_millis(10)).await;
518518
}
519-
telemetry_srv.assert_hits_async(1).await;
519+
telemetry_srv.assert_calls_async(1).await;
520520
}
521521

522522
#[cfg_attr(miri, ignore)]
@@ -542,10 +542,10 @@ mod tests {
542542
client.start().await;
543543
let _ = client.send(&data);
544544
client.shutdown().await;
545-
while telemetry_srv.hits_async().await == 0 {
545+
while telemetry_srv.calls_async().await == 0 {
546546
sleep(Duration::from_millis(10)).await;
547547
}
548-
telemetry_srv.assert_hits_async(1).await;
548+
telemetry_srv.assert_calls_async(1).await;
549549
}
550550

551551
#[cfg_attr(miri, ignore)]
@@ -571,10 +571,10 @@ mod tests {
571571
client.start().await;
572572
let _ = client.send(&data);
573573
client.shutdown().await;
574-
while telemetry_srv.hits_async().await == 0 {
574+
while telemetry_srv.calls_async().await == 0 {
575575
sleep(Duration::from_millis(10)).await;
576576
}
577-
telemetry_srv.assert_hits_async(1).await;
577+
telemetry_srv.assert_calls_async(1).await;
578578
}
579579

580580
#[test]
@@ -698,7 +698,7 @@ mod tests {
698698

699699
let telemetry_srv = server
700700
.mock_async(|when, then| {
701-
when.method(POST).body_contains(r#""runtime_id":"foo""#);
701+
when.method(POST).body_includes(r#""runtime_id":"foo""#);
702702
then.status(200).body("");
703703
})
704704
.await;
@@ -765,10 +765,10 @@ mod tests {
765765
})
766766
.unwrap();
767767
client.shutdown().await;
768-
while telemetry_srv.hits_async().await == 0 {
768+
while telemetry_srv.calls_async().await == 0 {
769769
sleep(Duration::from_millis(10)).await;
770770
}
771771
// One payload generate-metrics
772-
telemetry_srv.assert_hits_async(1).await;
772+
telemetry_srv.assert_calls_async(1).await;
773773
}
774774
}

0 commit comments

Comments
 (0)