diff options
author | Karsten Loesing <karsten.loesing@gmx.net> | 2010-08-18 15:44:02 +0200 |
---|---|---|
committer | Karsten Loesing <karsten.loesing@gmx.net> | 2010-12-03 16:47:53 +0100 |
commit | 91fec693e01cf5ef77fddca48ed4c0ba4fcd0d1a (patch) | |
tree | 4d0f8facaffa6b414a3d003a3626d269b27d0546 /src/test | |
parent | 076a688d76f7acb3c2efc0efef6bdb621de9fefd (diff) | |
download | tor-91fec693e01cf5ef77fddca48ed4c0ba4fcd0d1a.tar.gz tor-91fec693e01cf5ef77fddca48ed4c0ba4fcd0d1a.zip |
Refactor conn stats and add unit tests.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/test/test.c b/src/test/test.c index 960a6659a7..56a7a9a0cb 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -1104,7 +1104,8 @@ test_stats(void) char *s = NULL; int i; - /* We shouldn't collect exit stats without initializing them. */ + /* Start with testing exit port statistics; we shouldn't collect exit + * stats without initializing them. */ rep_hist_note_exit_stream_opened(80); rep_hist_note_exit_bytes(80, 100, 10000); s = rep_hist_format_exit_stats(now + 86400); @@ -1149,7 +1150,7 @@ test_stats(void) test_assert(!s); /* Re-start stats, add some bytes, reset stats, and see what history we - * get when observing no streams or bytes at all. */ + * get when observing no streams or bytes at all. */ rep_hist_exit_stats_init(now); rep_hist_note_exit_stream_opened(80); rep_hist_note_exit_bytes(80, 100, 10000); @@ -1159,6 +1160,43 @@ test_stats(void) "exit-kibibytes-written other=0\n" "exit-kibibytes-read other=0\n" "exit-streams-opened other=0\n", s); + tor_free(s); + + /* Continue with testing connection statistics; we shouldn't collect + * conn stats without initializing them. */ + rep_hist_note_or_conn_bytes(1, 20, 400, now); + s = rep_hist_format_conn_stats(now + 86400); + test_assert(!s); + + /* Initialize stats, note bytes, and generate history string. */ + rep_hist_conn_stats_init(now); + rep_hist_note_or_conn_bytes(1, 30000, 400000, now); + rep_hist_note_or_conn_bytes(1, 30000, 400000, now + 5); + rep_hist_note_or_conn_bytes(2, 400000, 30000, now + 10); + rep_hist_note_or_conn_bytes(2, 400000, 30000, now + 15); + s = rep_hist_format_conn_stats(now + 86400); + test_streq("conn-stats-end 2010-08-12 13:27:30 (86400 s)\n" + "conn-bi-direct 0,0,1,0\n", s); + tor_free(s); + + /* Stop collecting stats, add some bytes, and ensure we don't generate + * a history string. */ + rep_hist_conn_stats_term(); + rep_hist_note_or_conn_bytes(2, 400000, 30000, now + 15); + s = rep_hist_format_conn_stats(now + 86400); + test_assert(!s); + + /* Re-start stats, add some bytes, reset stats, and see what history we + * get when observing no streams or bytes at all. */ + rep_hist_conn_stats_init(now); + rep_hist_note_or_conn_bytes(1, 30000, 400000, now); + rep_hist_note_or_conn_bytes(1, 30000, 400000, now + 5); + rep_hist_note_or_conn_bytes(2, 400000, 30000, now + 10); + rep_hist_note_or_conn_bytes(2, 400000, 30000, now + 15); + rep_hist_reset_conn_stats(now); + s = rep_hist_format_conn_stats(now + 86400); + test_streq("conn-stats-end 2010-08-12 13:27:30 (86400 s)\n" + "conn-bi-direct 0,0,0,0\n", s); done: tor_free(s); |