def test_pop_from_empty_queue_raises_error(): sim = Mock() sim.stime = 0 queue = Queue(sim, capacity=2) with pytest.raises(ValueError): queue.pop()
def test_pop_extracts_packets_in_correct_order(): sim = Mock() sim.stime = 0 data_size = [123, 412] packets = [NetworkPacket(data=AppData(0, sz, 0, 0)) for sz in data_size] queue = Queue(sim, capacity=2) queue.push(packets[0]) queue.push(packets[1]) assert queue.pop() == packets[0] assert not queue.empty() assert not queue.full() assert len(queue) == 1 assert queue.size() == 1 assert queue.bitsize() == data_size[1] assert tuple(qp.packet for qp in queue.as_tuple()) == (packets[1], ) assert queue.pop() == packets[1] assert queue.empty() assert not queue.full() assert len(queue) == 0 assert queue.size() == 0 assert queue.bitsize() == 0 assert queue.as_tuple() == ()
def test_finite_queue_without_service_writes_statistics(): sim = Mock() size = [123, 412, 230, 312] t0, t1, t2, t3, t4, t5 = 2, 7, 8, 10, 14, 19 packets = [NetworkPacket(data=AppData(0, sz, 0, 0)) for sz in size] sim.stime = t0 q = Queue(sim, capacity=2) # Run a sequence of operations: sim.stime = t1 q.push(packets[0]) # stored after: packet[0] sim.stime = t2 q.push(packets[1]) # stored after: packet[0], packet[1] sim.stime = t3 q.push(packets[2]) # dropped due to overflow, stored: packet[0], packet[1] sim.stime = t4 q.pop() # stored after: packet[1] sim.stime = t5 q.push(packets[3]) # stored after: packet[1], packet[3] assert tuple(qp.packet for qp in q.as_tuple()) == (packets[1], packets[3]) assert q.size_trace.as_tuple() == ((t0, 0), (t1, 1), (t2, 2), (t4, 1), (t5, 2)) assert q.bitsize_trace.as_tuple() == ( (t0, 0), (t1, size[0]), (t2, size[0] + size[1]), (t4, size[1]), (t5, size[1] + size[3]), ) assert q.num_dropped == 1