diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2014-08-20 22:07:08 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-08-20 15:29:56 -0400 |
commit | 8b539cc27684534a6a71cef92f9a6782040f6ca9 (patch) | |
tree | 8fe796bf3fb6d9fa878e8622fc29b4315659a9af /src/test | |
parent | c731a1c68f47812f0bc536a8fab548c3c734ce28 (diff) | |
download | tor-8b539cc27684534a6a71cef92f9a6782040f6ca9.tar.gz tor-8b539cc27684534a6a71cef92f9a6782040f6ca9.zip |
Unit testing entry_is_time_to_retry().
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test_entrynodes.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c index ede93fb43a..5fee0336da 100644 --- a/src/test/test_entrynodes.c +++ b/src/test/test_entrynodes.c @@ -538,6 +538,83 @@ test_entry_guards_set_from_config(void *arg) routerset_free(options->EntryNodes); } +static void +test_entry_is_time_to_retry(void *arg) +{ + (void)arg; + + entry_guard_t *test_guard; + time_t now; + int retval; + + now = time(NULL); + + test_guard = tor_malloc(sizeof(entry_guard_t)); + memset(test_guard,0,sizeof(entry_guard_t)); + + test_guard->last_attempted = now - 10; + test_guard->unreachable_since = now - 1; + + retval = entry_is_time_to_retry(test_guard,now); + tt_int_op(retval,==,1); + + test_guard->unreachable_since = now - (6*60*60 - 1); + test_guard->last_attempted = now - (60*60 + 1); + + retval = entry_is_time_to_retry(test_guard,now); + tt_int_op(retval,==,1); + + test_guard->last_attempted = now - (60*60 - 1); + + retval = entry_is_time_to_retry(test_guard,now); + tt_int_op(retval,==,0); + + test_guard->unreachable_since = now - (6*60*60 + 1); + test_guard->last_attempted = now - (4*60*60 + 1); + + retval = entry_is_time_to_retry(test_guard,now); + tt_int_op(retval,==,1); + + test_guard->unreachable_since = now - (3*24*60*60 - 1); + test_guard->last_attempted = now - (4*60*60 + 1); + + retval = entry_is_time_to_retry(test_guard,now); + tt_int_op(retval,==,1); + + test_guard->unreachable_since = now - (3*24*60*60 + 1); + test_guard->last_attempted = now - (18*60*60 + 1); + + retval = entry_is_time_to_retry(test_guard,now); + tt_int_op(retval,==,1); + + test_guard->unreachable_since = now - (7*24*60*60 - 1); + test_guard->last_attempted = now - (18*60*60 + 1); + + retval = entry_is_time_to_retry(test_guard,now); + tt_int_op(retval,==,1); + + test_guard->last_attempted = now - (18*60*60 - 1); + + retval = entry_is_time_to_retry(test_guard,now); + tt_int_op(retval,==,0); + + test_guard->unreachable_since = now - (7*24*60*60 + 1); + test_guard->last_attempted = now - (36*60*60 + 1); + + retval = entry_is_time_to_retry(test_guard,now); + tt_int_op(retval,==,1); + + test_guard->unreachable_since = now - (7*24*60*60 + 1); + test_guard->last_attempted = now - (36*60*60 + 1); + + retval = entry_is_time_to_retry(test_guard,now); + tt_int_op(retval,==,1); + + done: + tor_free(test_guard); + return; +} + /** XXX Do some tests that entry_is_live() */ static void test_entry_is_live(void *arg) @@ -608,6 +685,8 @@ static const struct testcase_setup_t fake_network = { }; struct testcase_t entrynodes_tests[] = { + { "entry_is_time_to_retry", test_entry_is_time_to_retry, + TT_FORK, NULL, NULL }, { "choose_random_entry_no_guards", test_choose_random_entry_no_guards, TT_FORK, &fake_network, NULL }, { "choose_random_entry_one_possibleguard", |