summaryrefslogtreecommitdiff
path: root/src/test/test.c
diff options
context:
space:
mode:
authorKarsten Loesing <karsten.loesing@gmx.net>2011-08-04 14:45:24 +0200
committerKarsten Loesing <karsten.loesing@gmx.net>2011-08-04 21:18:19 +0200
commitd690a99dfe65ba164aa3de0662be2a8fedc69b01 (patch)
tree1d939eb911af602d265845b6466f5a018e6d4d0f /src/test/test.c
parent88083463cb895df0286210830e14c635c9e026a5 (diff)
downloadtor-d690a99dfe65ba164aa3de0662be2a8fedc69b01.tar.gz
tor-d690a99dfe65ba164aa3de0662be2a8fedc69b01.zip
Clean up bridge-stats code.
Only write a bridge-stats string if bridge stats have been initialized. This behavior is similar to dirreq-stats, entry-stats, etc. Also add a few unit tests for the bridge-stats code.
Diffstat (limited to 'src/test/test.c')
-rw-r--r--src/test/test.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/test/test.c b/src/test/test.c
index fe8146a097..605e44ca4d 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -1483,7 +1483,10 @@ test_geoip(void)
int i, j;
time_t now = 1281533250; /* 2010-08-11 13:27:30 UTC */
char *s = NULL;
- const char *dirreq_stats_1 =
+ const char *bridge_stats_1 =
+ "bridge-stats-end 2010-08-12 13:27:30 (86400 s)\n"
+ "bridge-ips zz=24,xy=8\n",
+ *dirreq_stats_1 =
"dirreq-stats-end 2010-08-12 13:27:30 (86400 s)\n"
"dirreq-v3-ips ab=8\n"
"dirreq-v2-ips \n"
@@ -1594,6 +1597,24 @@ test_geoip(void)
test_assert(s);
test_streq("zz=24,xy=8", s);
+ /* Start testing bridge statistics by making sure that we don't output
+ * bridge stats without initializing them. */
+ s = geoip_format_bridge_stats(now + 86400);
+ test_assert(!s);
+
+ /* Initialize stats and generate the bridge-stats history string out of
+ * the connecting clients added above. */
+ geoip_bridge_stats_init(now);
+ s = geoip_format_bridge_stats(now + 86400);
+ test_streq(bridge_stats_1, s);
+ tor_free(s);
+
+ /* Stop collecting bridge stats and make sure we don't write a history
+ * string anymore. */
+ geoip_bridge_stats_term();
+ s = geoip_format_bridge_stats(now + 86400);
+ test_assert(!s);
+
/* Stop being a bridge and start being a directory mirror that gathers
* directory request statistics. */
geoip_bridge_stats_term();