Adds test and fixes for allocate bridges

This commit is contained in:
onyinyang 2023-05-15 18:57:23 -04:00
parent 45bb5756df
commit 8d0f570627
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
2 changed files with 23 additions and 5 deletions

View File

@ -339,8 +339,8 @@ impl BridgeAuth {
distributor_bridges: &mut Vec<BridgeLine>, distributor_bridges: &mut Vec<BridgeLine>,
bdb: &mut BridgeDb, bdb: &mut BridgeDb,
) { ) {
while let Some(bridge) = distributor_bridges.iter().next_back() { while let Some(bridge) = distributor_bridges.pop() {
self.bridge_table.unallocated_bridges.push(*bridge) self.bridge_table.unallocated_bridges.push(bridge);
} }
while self.bridge_table.unallocated_bridges.len() >= MAX_BRIDGES_PER_BUCKET { while self.bridge_table.unallocated_bridges.len() >= MAX_BRIDGES_PER_BUCKET {
let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET]; let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];

View File

@ -601,9 +601,27 @@ fn test_redeem_invite() {
#[test] #[test]
fn test_allocate_bridges() { fn test_allocate_bridges() {
let mut th = TestHarness::new(); let mut th = TestHarness::new();
// Check that any bridges in distributor_bridges are first added to unallocated bridges let distributor_bridges: &mut Vec<BridgeLine> = &mut Vec::new();
// and finally are added as openinv_buckets let table_size = th.ba.bridge_table.buckets.len();
// TODO for _ in 0..3 {
distributor_bridges.push(BridgeLine::random());
}
assert!(!distributor_bridges.is_empty(), "No BridgeLines in distributor_bridges");
th.ba.allocate_bridges(distributor_bridges, &mut th.bdb);
assert!(distributor_bridges.is_empty(), "BridgeLines in distributor_bridges were not allocated");
assert!(th.ba.bridge_table.buckets.len() > table_size, "Size of bridge table did not increase");
let table_size = th.ba.bridge_table.buckets.len();
for _ in 0..2 {
distributor_bridges.push(BridgeLine::random());
th.ba.bridge_table.unallocated_bridges.push(BridgeLine::random());
}
assert!(!th.ba.bridge_table.unallocated_bridges.is_empty(), "No BridgeLines in unallocated bridges");
assert!(!distributor_bridges.is_empty(), "No BridgeLines in distributor_bridges");
th.ba.allocate_bridges(distributor_bridges, &mut th.bdb);
assert!(th.ba.bridge_table.unallocated_bridges.len() == 1, "Incorrect number of bridges remain unallocated");
assert!(distributor_bridges.is_empty(), "BridgeLines in distributor_bridges were not allocated");
assert!(th.ba.bridge_table.buckets.len() > table_size, "Size of bridge table did not increase");
} }
#[test] #[test]