From e6f41c0d16916c06a7314b9ddc16f78e70474b8a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 24 Sep 2013 08:14:50 +0000 Subject: [PATCH] remove randomness from test_dht, to make it pass consistently --- test/test_dht.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 87ff2fedb..dbf2fe057 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -105,14 +105,6 @@ sha1_hash generate_next() return ret; } -node_id random_id() -{ - node_id ret; - for (int i = 0; i < 20; ++i) - ret[i] = rand(); - return ret; -} - boost::array generate_key() { boost::array ret; @@ -326,6 +318,8 @@ struct print_alert : alert_dispatcher // TODO: 3 test find_data, obfuscated_get_peers and bootstrap int test_main() { + libtorrent::random_seed(1936584); + dht_settings sett; sett.max_torrents = 4; sett.max_dht_items = 4; @@ -750,16 +744,21 @@ int test_main() { sett.extended_routing_table = false; - routing_table tbl(random_id(), 8, sett); + node_id id = to_hash("1234876923549721020394873245098347598635"); + node_id diff = to_hash("15764f7459456a9453f8719b09547c11d5f34061"); + + routing_table tbl(id, 8, sett); // insert 256 nodes evenly distributed across the ID space. // we expect to fill the top 5 buckets for (int i = 0; i < 256; ++i) { - node_id id = random_id(); + // test a node with the same IP:port changing ID + add_and_replace(id, diff); id[0] = i; - tbl.node_seen(id, rand_ep(), libtorrent::random() % 20 + 20); + tbl.node_seen(id, rand_ep(), 20 + (id[19] & 0xff)); } + printf("num_active_buckets: %d\n", tbl.num_active_buckets()); TEST_EQUAL(tbl.num_active_buckets(), 6); #if defined TORRENT_DHT_VERBOSE_LOGGING || defined TORRENT_DEBUG @@ -769,12 +768,15 @@ int test_main() { sett.extended_routing_table = true; - routing_table tbl(random_id(), 8, sett); + node_id id = to_hash("1234876923549721020394873245098347598635"); + node_id diff = to_hash("15764f7459456a9453f8719b09547c11d5f34061"); + + routing_table tbl(id, 8, sett); for (int i = 0; i < 256; ++i) { - node_id id = random_id(); + add_and_replace(id, diff); id[0] = i; - tbl.node_seen(id, rand_ep(), libtorrent::random() % 20 + 20); + tbl.node_seen(id, rand_ep(), 20 + (id[19] & 0xff)); } TEST_EQUAL(tbl.num_active_buckets(), 6); @@ -1003,10 +1005,11 @@ int test_main() nodes.clear(); for (int i = 0; i < 7000; ++i) { - table.node_seen(tmp, udp::endpoint(rand_v4(), rand()), libtorrent::random() % 20 + 20); + table.node_seen(tmp, udp::endpoint(rand_v4(), rand()), 20 + (tmp[19] & 0xff)); add_and_replace(tmp, diff); } - TEST_EQUAL(table.num_active_buckets(), 11); + printf("active buckets: %d\n", table.num_active_buckets()); + TEST_EQUAL(table.num_active_buckets(), 10); TEST_CHECK(table.size().get<0>() > 10 * 10); //#error test num_global_nodes //#error test need_refresh