diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-11-30 11:28:18 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-12-16 11:06:20 -0500 |
commit | 171981f8a0eebf3f00feabe36dc66e031d51c5bd (patch) | |
tree | 37aa61595d3b02c46f1fe1095665d55ee746fd9b /src | |
parent | 217590ad05943968683f02c3f556b987e99158b1 (diff) | |
download | tor-171981f8a0eebf3f00feabe36dc66e031d51c5bd.tar.gz tor-171981f8a0eebf3f00feabe36dc66e031d51c5bd.zip |
Add a test for entry_guard_state_should_expire()
Diffstat (limited to 'src')
-rw-r--r-- | src/test/test_entrynodes.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c index 5fff1d6d22..5360b0e440 100644 --- a/src/test/test_entrynodes.c +++ b/src/test/test_entrynodes.c @@ -2926,6 +2926,37 @@ test_entry_guard_upgrade_not_blocked_by_worse_circ_pending(void *arg) smartlist_free(result); } +static void +test_enty_guard_should_expire_waiting(void *arg) +{ + (void)arg; + circuit_guard_state_t *fake_state = tor_malloc_zero(sizeof(*fake_state)); + /* We'll leave "guard" unset -- it won't matter here. */ + + /* No state? Can't expire. */ + tt_assert(! entry_guard_state_should_expire(NULL)); + + /* Let's try one that expires. */ + fake_state->state = GUARD_CIRC_STATE_WAITING_FOR_BETTER_GUARD; + fake_state->state_set_at = + approx_time() - DFLT_NONPRIMARY_GUARD_IDLE_TIMEOUT - 1; + + tt_assert(entry_guard_state_should_expire(fake_state)); + + /* But it wouldn't expire if we changed the state. */ + fake_state->state = GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD; + tt_assert(! entry_guard_state_should_expire(fake_state)); + + /* And it wouldn't have expired a few seconds ago. */ + fake_state->state = GUARD_CIRC_STATE_WAITING_FOR_BETTER_GUARD; + fake_state->state_set_at = + approx_time() - DFLT_NONPRIMARY_GUARD_IDLE_TIMEOUT + 5; + tt_assert(! entry_guard_state_should_expire(fake_state)); + + done: + tor_free(fake_state); +} + static const struct testcase_setup_t fake_network = { fake_network_setup, fake_network_cleanup }; @@ -3017,6 +3048,8 @@ struct testcase_t entrynodes_tests[] = { UPGRADE_TEST(upgrade_not_blocked_by_worse_circ_complete, "c1-done c2-done"), UPGRADE_TEST(upgrade_blocked_by_better_circ_pending, "c2-done"), UPGRADE_TEST(upgrade_not_blocked_by_worse_circ_pending, "c1-done"), + { "should_expire_waiting", test_enty_guard_should_expire_waiting, TT_FORK, + NULL, NULL }, END_OF_TESTCASES }; |