Adds test and fixes for allocate bridges
This commit is contained in:
parent
45bb5756df
commit
8d0f570627
|
@ -339,8 +339,8 @@ impl BridgeAuth {
|
|||
distributor_bridges: &mut Vec<BridgeLine>,
|
||||
bdb: &mut BridgeDb,
|
||||
) {
|
||||
while let Some(bridge) = distributor_bridges.iter().next_back() {
|
||||
self.bridge_table.unallocated_bridges.push(*bridge)
|
||||
while let Some(bridge) = distributor_bridges.pop() {
|
||||
self.bridge_table.unallocated_bridges.push(bridge);
|
||||
}
|
||||
while self.bridge_table.unallocated_bridges.len() >= MAX_BRIDGES_PER_BUCKET {
|
||||
let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
|
||||
|
|
|
@ -601,9 +601,27 @@ fn test_redeem_invite() {
|
|||
#[test]
|
||||
fn test_allocate_bridges() {
|
||||
let mut th = TestHarness::new();
|
||||
// Check that any bridges in distributor_bridges are first added to unallocated bridges
|
||||
// and finally are added as openinv_buckets
|
||||
// TODO
|
||||
let distributor_bridges: &mut Vec<BridgeLine> = &mut Vec::new();
|
||||
let table_size = th.ba.bridge_table.buckets.len();
|
||||
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]
|
||||
|
|
Loading…
Reference in New Issue