Skip to content

Commit

Permalink
test: fix tests accounting for the changes in how pocketic handles time
Browse files Browse the repository at this point in the history
  • Loading branch information
ilbertt committed Jul 20, 2024
1 parent 82fa1a1 commit bcc76dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::utils::{
messages::{get_next_polling_nonce_from_messages, verify_messages, AppMessage},
test_env::{
get_test_env, DEFAULT_TEST_MAX_NUMBER_OF_RETURNED_MESSAGES,
DEFAULT_TEST_SEND_ACK_INTERVAL_MS,
DEFAULT_TEST_SEND_ACK_INTERVAL_MS, DEFAULT_TEST_SEND_ACK_INTERVAL_NS,
},
};

Expand Down Expand Up @@ -260,6 +260,7 @@ fn test_7_empty_gateway_can_get_messages_until_next_keep_alive_check_if_removed_
let send_messages_count = 10;
// first, reset the canister
call_wipe(None);
let current_time = get_test_env().get_canister_time();
// second, register client 1
let client_1_key = CLIENT_1_KEY.deref();
call_ws_open_for_client_key_with_panic(client_1_key);
Expand All @@ -269,13 +270,14 @@ fn test_7_empty_gateway_can_get_messages_until_next_keep_alive_check_if_removed_
text: format!("test{}", i),
})
.collect();
call_send_with_panic(&client_1_key.client_principal, messages_to_send.clone());
call_send_with_panic(&client_1_key.client_principal, messages_to_send);

// check that gateway can receive the messages
helpers::assert_gateway_has_messages(send_messages_count);

// wait for the ack interval to fire
get_test_env().advance_canister_time_ms(DEFAULT_TEST_SEND_ACK_INTERVAL_MS);
// wait for the ack interval to fire, accounting for the time elapsed in the previous rounds
let elapsed_time = get_test_env().get_canister_time() - current_time;
get_test_env().advance_canister_time_ns(DEFAULT_TEST_SEND_ACK_INTERVAL_NS - elapsed_time);

// disconnect the client and check that gateway can still receive the messages
call_ws_close_with_panic(
Expand All @@ -296,7 +298,8 @@ fn test_7_empty_gateway_can_get_messages_until_next_keep_alive_check_if_removed_
helpers::assert_gateway_has_messages(expected_messages_len);

// wait for next ack interval to expire
get_test_env().advance_canister_time_ms(DEFAULT_TEST_SEND_ACK_INTERVAL_MS);
get_test_env()
.advance_canister_time_ms(DEFAULT_TEST_SEND_ACK_INTERVAL_MS - CLIENT_KEEP_ALIVE_TIMEOUT_MS);

// the gateway can still receive the messages, because empty expired gateways
// are removed only in the keep alive timeout callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub const DEFAULT_TEST_MAX_NUMBER_OF_RETURNED_MESSAGES: u64 = 50;
///
/// Value: `300_000` = 5 minutes
pub const DEFAULT_TEST_SEND_ACK_INTERVAL_MS: u64 = 300_000;
/// Same as [DEFAULT_TEST_SEND_ACK_INTERVAL_MS], but in nanoseconds.
pub const DEFAULT_TEST_SEND_ACK_INTERVAL_NS: u64 = DEFAULT_TEST_SEND_ACK_INTERVAL_MS * NS_IN_MS;

/// (`max_number_or_returned_messages`, `send_ack_interval_ms`)
pub type CanisterInitArgs = (u64, u64);
Expand Down

0 comments on commit bcc76dc

Please sign in to comment.