Skip to content

Commit 0a151af

Browse files
committed
validate lower bound + more comments
1 parent d734048 commit 0a151af

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

tests/v5/mqtt5_client_tests.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ static bool s_is_within_percentage_of(uint64_t expected_time, uint64_t actual_ti
2525
return fabs(actual_percent) <= percentage;
2626
}
2727

28+
/* The function is used to validate the time interval for the expected and actual time. We used a user determined
29+
* percentage for margin and a minimal of AWS_MQTT5_TESTING_DELAY_NS considering the system delay. */
2830
static bool s_validate_time_interval(uint64_t expected_time, uint64_t actual_time, double percentage) {
2931
uint64_t delta = actual_time > expected_time ? actual_time - expected_time : expected_time - actual_time;
3032
return delta < AWS_MQTT5_TESTING_DELAY_NS || s_is_within_percentage_of(expected_time, actual_time, percentage);
@@ -1727,7 +1729,13 @@ static int s_verify_reconnection_after_success_used_backoff(
17271729
AWS_TIMESTAMP_MILLIS,
17281730
NULL);
17291731

1730-
if (!s_validate_time_interval(expected_reconnect_delay_ms, post_success_reconnect_time_ms, .3)) {
1732+
/* The reconnect delay should be at least the expected backoff time.
1733+
* Meanwhile, to make sure the backoff time is reset to minimal properly, we also would like to validate the upper
1734+
* bound of the reconnect time. With function `s_validate_time_interval()`, we used a 30% margin and a minimal of
1735+
* AWS_MQTT5_TESTING_DELAY_NS for system delay to validate the upper bound.
1736+
*/
1737+
if (!s_check_time_lower_bound(expected_reconnect_delay_ms, post_success_reconnect_time_ms) &&
1738+
!s_validate_time_interval(expected_reconnect_delay_ms, post_success_reconnect_time_ms, .3)) {
17311739
return AWS_OP_ERR;
17321740
}
17331741

0 commit comments

Comments
 (0)