use super::*;
#[test]
fn blocked_streams_empty_budget_available() {
let table = new_table_with_blocked_streams(4096, 2);
assert_eq!(table.currently_blocked_streams(), 0);
assert!(!table.is_stream_blocking(1));
assert!(table.can_block_another_stream(1));
}
#[test]
fn blocked_streams_non_blocking_section_does_not_count() {
let table = new_table_with_blocked_streams(4096, 0);
table.register_outstanding_section(1, blocking_section(0));
assert_eq!(table.currently_blocked_streams(), 0);
assert!(!table.is_stream_blocking(1));
}
#[test]
fn blocked_streams_counts_distinct_streams() {
let table = new_table_with_blocked_streams(4096, 3);
table.register_outstanding_section(1, blocking_section(5));
table.register_outstanding_section(2, blocking_section(7));
assert_eq!(table.currently_blocked_streams(), 2);
assert!(table.is_stream_blocking(1));
assert!(table.is_stream_blocking(2));
assert!(!table.is_stream_blocking(3));
}
#[test]
fn blocked_streams_per_stream_dedup() {
let table = new_table_with_blocked_streams(4096, 1);
table.register_outstanding_section(1, blocking_section(3));
table.register_outstanding_section(1, blocking_section(5));
table.register_outstanding_section(1, blocking_section(7));
assert_eq!(table.currently_blocked_streams(), 1);
assert!(table.can_block_another_stream(1)); assert!(!table.can_block_another_stream(2)); }
#[test]
fn blocked_streams_budget_exhausted() {
let table = new_table_with_blocked_streams(4096, 2);
table.register_outstanding_section(1, blocking_section(5));
table.register_outstanding_section(2, blocking_section(7));
assert_eq!(table.currently_blocked_streams(), 2);
assert!(table.can_block_another_stream(1)); assert!(table.can_block_another_stream(2)); assert!(!table.can_block_another_stream(3)); }
#[test]
fn encode_required_insert_count_formula() {
assert_eq!(encode_required_insert_count(0, 0), 0);
assert_eq!(encode_required_insert_count(0, 4096), 0);
assert_eq!(encode_required_insert_count(1, 32), 2); assert_eq!(encode_required_insert_count(2, 32), 1); assert_eq!(encode_required_insert_count(3, 32), 2);
assert_eq!(encode_required_insert_count(5, 100), 6); assert_eq!(encode_required_insert_count(6, 100), 1); assert_eq!(encode_required_insert_count(13, 100), 2);
assert_eq!(encode_required_insert_count(1, 4096), 2);
assert_eq!(encode_required_insert_count(256, 4096), 1);
assert_eq!(encode_required_insert_count(300, 4096), 45); }
#[test]
fn set_capacity_emits_wire_instruction() {
let table = new_table(4096);
table.set_capacity(1024).unwrap();
assert_eq!(
drain_instructions(&table),
vec![
EncoderInstruction::SetCapacity(4096),
EncoderInstruction::SetCapacity(1024),
]
);
}
#[test]
fn set_capacity_rejects_above_max() {
let table = new_table(4096);
assert!(table.set_capacity(8192).is_err());
}
#[test]
fn drain_is_fifo() {
let table = new_table(4096);
table.set_capacity(256).unwrap();
table.set_capacity(1024).unwrap();
assert_eq!(
drain_instructions(&table),
vec![
EncoderInstruction::SetCapacity(4096),
EncoderInstruction::SetCapacity(256),
EncoderInstruction::SetCapacity(1024),
]
);
}