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
3 changes: 3 additions & 0 deletions crates/icp-cli/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ fn random_send_interval(is_prerelease: bool) -> u64 {
}

fn should_send(telemetry_dir: &Path) -> bool {
if std::env::var_os("ICP_CLI_TEST_NO_TELEMETRY_UPLOAD").is_some() {
return false;
}
let is_prerelease = env!("CARGO_PKG_VERSION").contains('-');

// Size-based trigger
Expand Down
2 changes: 2 additions & 0 deletions crates/icp-cli/tests/common/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ impl TestContext {
cmd.env("ICP_HOME", self.home_path().join("icp"));
cmd.env("PATH", self.os_path.clone());
cmd.env("ICP_CLI_KEYRING_MOCK_DIR", self.mock_cred_dir.clone());
cmd.env("ICP_TELEMETRY_DISABLED", "1");
cmd.env("ICP_CLI_TEST_NO_TELEMETRY_UPLOAD", "1");

// If SoftHSM has been initialized, include its config
if let Some(hsm) = self.softhsm.get() {
Expand Down
22 changes: 18 additions & 4 deletions crates/icp-cli/tests/telemetry_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ macro_rules! icp_with_telemetry {
.env_remove("ICP_TELEMETRY_DISABLED");
(icp_home, cmd)
}};
($ctx:expr, allow_upload) => {{
let icp_home = $ctx.home_path().join("icp-home");
let mut cmd = $ctx.icp();
cmd.env("ICP_HOME", icp_home.as_str())
.env_remove("CI")
.env_remove("DO_NOT_TRACK")
.env_remove("ICP_TELEMETRY_DISABLED")
.env_remove("ICP_CLI_TEST_NO_TELEMETRY_UPLOAD")
.env(
"ICP_TELEMETRY_ENDPOINT",
"https://telemetry.invalid/v1/events",
);
(icp_home, cmd)
}};
}

/// Each of the three opt-out env vars must prevent any telemetry state from
Expand Down Expand Up @@ -273,7 +287,7 @@ fn telemetry_notice_suppressed_when_marker_exists() {
#[test]
fn telemetry_time_trigger_rotates_events() {
let ctx = TestContext::new();
let (icp_home, mut cmd) = icp_with_telemetry!(ctx);
let (icp_home, mut cmd) = icp_with_telemetry!(ctx, allow_upload);
let telemetry_dir = icp_home.join("telemetry");

// Set next-send-time to Unix epoch (far in the past).
Expand All @@ -297,7 +311,7 @@ fn telemetry_time_trigger_rotates_events() {
#[test]
fn telemetry_size_trigger_rotates_events() {
let ctx = TestContext::new();
let (icp_home, mut cmd) = icp_with_telemetry!(ctx);
let (icp_home, mut cmd) = icp_with_telemetry!(ctx, allow_upload);
let telemetry_dir = icp_home.join("telemetry");

// next-send-time far in the future → only the size trigger can fire.
Expand Down Expand Up @@ -415,7 +429,7 @@ fn telemetry_send_batch_delivers_data() {
#[test]
fn telemetry_stale_batches_deleted_on_trigger() {
let ctx = TestContext::new();
let (icp_home, mut cmd) = icp_with_telemetry!(ctx);
let (icp_home, mut cmd) = icp_with_telemetry!(ctx, allow_upload);
let telemetry_dir = icp_home.join("telemetry");

// Time trigger will fire.
Expand Down Expand Up @@ -449,7 +463,7 @@ fn telemetry_stale_batches_deleted_on_trigger() {
#[test]
fn telemetry_excess_batches_pruned_on_trigger() {
let ctx = TestContext::new();
let (icp_home, mut cmd) = icp_with_telemetry!(ctx);
let (icp_home, mut cmd) = icp_with_telemetry!(ctx, allow_upload);
let telemetry_dir = icp_home.join("telemetry");

// Time trigger will fire.
Expand Down