summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-11-08 08:11:22 -0500
committerNick Mathewson <nickm@torproject.org>2017-11-08 08:11:22 -0500
commite5a83062ed4e9e6b908efc6b75f13ab269f97377 (patch)
tree253abd655ffb82f7be81d3985e4a47c4c66f85b4 /src/test
parent3dc61a5d71423e86d4d8090a90782a1ddf164880 (diff)
parentcb29687e93169e9615de3bc5adcbf6d31551b32c (diff)
downloadtor-e5a83062ed4e9e6b908efc6b75f13ab269f97377.tar.gz
tor-e5a83062ed4e9e6b908efc6b75f13ab269f97377.zip
Merge branch 'bug23816_029_squashed' into maint-0.3.2
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_dir.c69
1 files changed, 39 insertions, 30 deletions
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 87b86c38b8..ee4a9780b1 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -4126,9 +4126,9 @@ download_status_random_backoff_helper(int min_delay, int max_delay)
int increment = -1;
int old_increment = -1;
time_t current_time = time(NULL);
- const int exponent = DIR_DEFAULT_RANDOM_MULTIPLIER + 1;
/* Check the random backoff cases */
+ int n_attempts = 0;
do {
increment = download_status_schedule_get_delay(&dls_random,
NULL,
@@ -4148,40 +4148,16 @@ download_status_random_backoff_helper(int min_delay, int max_delay)
/* Test */
tt_int_op(increment, OP_GE, min_delay);
tt_int_op(increment, OP_LE, max_delay);
- if (dls_random.last_backoff_position == 0) {
- /* regression tests for 17750
- * Always use the minimum delay for the first increment */
- tt_int_op(increment, OP_EQ, min_delay);
- } else {
- /* It's times like these I'd love a good saturating arithmetic
- * implementation */
- int min_inc = INT_MAX;
- if (old_increment <= INT_MAX - 1) {
- min_inc = old_increment + 1;
- }
-
- int max_inc = INT_MAX;
- if (old_increment <= (INT_MAX - 1)/exponent) {
- max_inc = (exponent * old_increment) + 1;
- }
-
- /* Regression test for 20534 and friends:
- * increment must always increase after the first */
- tt_int_op(increment, OP_GE, min_inc);
- /* We at most quadruple, and always add one */
- tt_int_op(increment, OP_LE, max_inc);
- }
/* Advance */
- ++(dls_random.n_download_attempts);
- ++(dls_random.n_download_failures);
+ if (dls_random.n_download_attempts < IMPOSSIBLE_TO_DOWNLOAD - 1) {
+ ++(dls_random.n_download_attempts);
+ ++(dls_random.n_download_failures);
+ }
/* Try another maybe */
old_increment = increment;
- if (increment >= max_delay)
- current_time += increment;
-
- } while (increment < max_delay);
+ } while (increment < max_delay && ++n_attempts < 1000);
done:
return;
@@ -4209,6 +4185,38 @@ test_dir_download_status_random_backoff(void *arg)
}
static void
+test_dir_download_status_random_backoff_ranges(void *arg)
+{
+ (void)arg;
+ int lo, hi;
+ next_random_exponential_delay_range(&lo, &hi, 0, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, 11);
+
+ next_random_exponential_delay_range(&lo, &hi, 6, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, 6*3);
+
+ next_random_exponential_delay_range(&lo, &hi, 13, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, 13 * 3);
+
+ next_random_exponential_delay_range(&lo, &hi, 37, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, 111);
+
+ next_random_exponential_delay_range(&lo, &hi, 123, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, 369);
+
+ next_random_exponential_delay_range(&lo, &hi, INT_MAX-5, 10);
+ tt_int_op(lo, OP_EQ, 10);
+ tt_int_op(hi, OP_EQ, INT_MAX);
+ done:
+ ;
+}
+
+static void
test_dir_download_status_increment(void *arg)
{
(void)arg;
@@ -6208,6 +6216,7 @@ struct testcase_t dir_tests[] = {
DIR(packages, 0),
DIR(download_status_schedule, 0),
DIR(download_status_random_backoff, 0),
+ DIR(download_status_random_backoff_ranges, 0),
DIR(download_status_increment, 0),
DIR(authdir_type_to_string, 0),
DIR(conn_purpose_to_string, 0),