Adds test and fixes for allocate bridges
This commit is contained in:
parent
0fd815951c
commit
84622bb7f8
|
@ -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];
|
||||||
|
|
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue