aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_scheduler.c
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@torproject.org>2014-01-23 21:13:44 -0800
committerAndrea Shepard <andrea@torproject.org>2014-09-30 23:14:58 -0700
commit030608d68d393c90fb789638e5e93ac6af7d4f5e (patch)
treed0dabe03828826ed4d074dbb3f818f03ab297f07 /src/test/test_scheduler.c
parent71a9ed6feb9e28cce0a2e776e23b440b0139e479 (diff)
downloadtor-030608d68d393c90fb789638e5e93ac6af7d4f5e.tar.gz
tor-030608d68d393c90fb789638e5e93ac6af7d4f5e.zip
Add scheduler/queue_heuristic unit test
Diffstat (limited to 'src/test/test_scheduler.c')
-rw-r--r--src/test/test_scheduler.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/test/test_scheduler.c b/src/test/test_scheduler.c
index e8bceeb2d4..02426f3723 100644
--- a/src/test/test_scheduler.c
+++ b/src/test/test_scheduler.c
@@ -15,6 +15,7 @@
#define TOR_CHANNEL_INTERNAL_
#include "or.h"
#include "compat_libevent.h"
+#define SCHEDULER_PRIVATE_
#include "scheduler.h"
/* Test suite stuff */
@@ -134,8 +135,44 @@ test_scheduler_initfree(void *arg)
return;
}
+static void
+test_scheduler_queue_heuristic(void *arg)
+{
+ time_t now = approx_time();
+ uint64_t qh;
+
+ (void)arg;
+
+ queue_heuristic = 0;
+ queue_heuristic_timestamp = 0;
+
+ /* Not yet inited case */
+ scheduler_update_queue_heuristic(now - 180);
+ test_eq(queue_heuristic, 0);
+ test_eq(queue_heuristic_timestamp, now - 180);
+
+ queue_heuristic = 1000000000L;
+ queue_heuristic_timestamp = now - 120;
+
+ scheduler_update_queue_heuristic(now - 119);
+ test_eq(queue_heuristic, 500000000L);
+ test_eq(queue_heuristic_timestamp, now - 119);
+
+ scheduler_update_queue_heuristic(now - 116);
+ test_eq(queue_heuristic, 62500000L);
+ test_eq(queue_heuristic_timestamp, now - 116);
+
+ qh = scheduler_get_queue_heuristic();
+ test_eq(qh, 0);
+
+ done:
+ return;
+}
+
struct testcase_t scheduler_tests[] = {
{ "initfree", test_scheduler_initfree, TT_FORK, NULL, NULL },
+ { "queue_heuristic", test_scheduler_queue_heuristic,
+ TT_FORK, NULL, NULL },
END_OF_TESTCASES
};