summaryrefslogtreecommitdiff
path: root/test/routing.c
diff options
context:
space:
mode:
authorJesper Jensen <jesper@slashwin.dk>2021-10-05 22:48:37 +0200
committerJesper Jensen <jesper@slashwin.dk>2021-10-05 22:48:37 +0200
commit6e6829ad209550fbac0e363f9421c1fba78915b5 (patch)
treea769fdc053e5cd8dabbebe9048725bdc9b6500cc /test/routing.c
parente3eb0d2eda0bb8c4decf9bc56b025157e70387c2 (diff)
Add getclient timeout
Diffstat (limited to 'test/routing.c')
-rw-r--r--test/routing.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/routing.c b/test/routing.c
index eb899ba..ad6f2c3 100644
--- a/test/routing.c
+++ b/test/routing.c
@@ -219,3 +219,64 @@ void test_get_after_offer_and_remove() {
TEST_ASSERT_NULL(e);
}
+
+void test_close_to_self_load_factor() {
+ routing_flush();
+
+ // The address we are going to store
+ struct addr addr = (struct addr){.ip = IP(128,0,0,1), .port = 0};
+
+ // Make a nodeid that is one bit different
+ struct nodeid new = self;
+
+ new.inner[4] += 1;
+ struct entry* entry;
+ TEST_ASSERT_TRUE_MESSAGE(routing_offer(&new, &entry), "Did not accept new entry");
+
+ // Set the entries
+ entry->addr = addr;
+ entry->expire = time(NULL);
+
+ int filled;
+ int total;
+ double load_factor[8] = {0};
+ routing_status(&filled, &total, load_factor, 8);
+
+ TEST_ASSERT_EQUAL(1, filled);
+ TEST_ASSERT_EQUAL(1280, total);
+ // First bucket should have none
+ TEST_ASSERT_EQUAL_DOUBLE(0.0, load_factor[0]);
+ // The final bucket should have the one node
+ TEST_ASSERT_EQUAL_DOUBLE(1.0/(1280/8), load_factor[7]);
+}
+
+void test_far_from_self_load_factor() {
+ routing_flush();
+
+ // The address we are going to store
+ struct addr addr = (struct addr){.ip = IP(128,0,0,1), .port = 0};
+
+ // Make a nodeid that is one bit different
+ struct nodeid new = self;
+
+ // Flip top bit to make it very dissimilar
+ new.inner[0] ^= 0x80000000;
+ struct entry* entry;
+ TEST_ASSERT_TRUE_MESSAGE(routing_offer(&new, &entry), "Did not accept new entry");
+
+ // Set the entries
+ entry->addr = addr;
+ entry->expire = time(NULL);
+
+ int filled;
+ int total;
+ double load_factor[8] = {0};
+ routing_status(&filled, &total, load_factor, 8);
+
+ TEST_ASSERT_EQUAL(1, filled);
+ TEST_ASSERT_EQUAL(1280, total);
+ // First bucket should have the one node
+ TEST_ASSERT_EQUAL_DOUBLE(1.0/(1280/8), load_factor[0]);
+ // The final bucket should have none
+ TEST_ASSERT_EQUAL_DOUBLE(0.0, load_factor[7]);
+}