Skip to content

Commit 2f8ef5b

Browse files
authored
fix: deflake //rs/registry/canister:registry_canister_integration_test_tests/rate_limits (#9172)
## Root Cause The test uses `.with_current_time()` to set the state machine's clock to `SystemTime::now()` at build time. However, `prepare_add_node_payload` generates TLS certificates using the real system clock (via `generate_node_keys_once`). The CSP vault sets the certificate's `notBefore` to `system_time - 2_minutes`. As the test runs its loop of 70 add/remove node iterations (~2 minutes of wall-clock time), the real system time advances while the state machine's time drifts behind. When the registry canister validates the TLS certificate, it compares the cert's `notBefore` against the state machine's time. If the state machine's time has fallen far enough behind the system time that `system_time - 2min > state_machine_time`, the validation fails with: ``` invalid TLS certificate: notBefore date is in the future compared to current time ``` All 11 flaky failures in the past week show this exact pattern — the `notBefore` is 1–5 seconds ahead of the state machine's clock. ## Fix Call `env.set_time(SystemTime::now())` before each `add_node` call to resync the state machine's clock with the system clock. This is a well-established pattern used in other state machine tests (e.g., `gtc.rs`, `node_provider_remuneration.rs`). --- This PR was created following the steps in `.claude/skills/fix-flaky-tests/SKILL.md`.
1 parent 66db527 commit 2f8ef5b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

rs/registry/canister/tests/rate_limits.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use registry_canister::{
1414
init::RegistryCanisterInitPayloadBuilder,
1515
mutations::do_add_node_operator::AddNodeOperatorPayload,
1616
};
17+
use std::time::SystemTime;
1718

1819
/// StateMachine test that verifies rate limiting works correctly for node operator operations
1920
#[test]
@@ -70,6 +71,11 @@ fn test_rate_limiting_state_machine() {
7071
};
7172

7273
for _ in 0..70 {
74+
// Sync state machine time with system time so that TLS certificates
75+
// generated by `prepare_add_node_payload` (which uses the system clock)
76+
// have a `notBefore` that is not in the future relative to the state
77+
// machine's time.
78+
env.set_time(SystemTime::now());
7379
// Create a simple add_node payload for testing with unique IP addresses
7480
let add_node_payload = next_add_node_payload(); // Use unique IDs
7581

@@ -94,6 +100,7 @@ fn test_rate_limiting_state_machine() {
94100
.unwrap();
95101
}
96102

103+
env.set_time(SystemTime::now());
97104
let add_node_payload = next_add_node_payload();
98105
let error = env
99106
.execute_ingress_as(

0 commit comments

Comments
 (0)