Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ def add_sub_queue(self, key: K, priority: int) -> Optional[SubQueue]:
elif pg.priority > priority:
new_pg = self.PriorityGroup(priority)
new_pg.add_queue(sub_queue)
self.priority_groups.append(new_pg)
# Insert before the higher-priority-value group to keep the list sorted.
self.priority_groups.insert(i, new_pg)
added = True
break

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,17 @@ def test_len_matches_size(self, queue):
queue.put("data", 1)
queue.put("control", "s")
assert len(queue) == queue.size() == 2

def test_sub_queues_registered_out_of_priority_order_are_served_by_priority(self):
# Register the lower-priority (higher number) queue first; priority must still win.
lbmq = LinkedBlockingMultiQueue()
lbmq.add_sub_queue("data", 1)
lbmq.add_sub_queue("control", 0)
assert [pg.priority for pg in lbmq.sub_queue_selection.priority_groups] == [
0,
1,
]
lbmq.put("data", "d")
lbmq.put("control", "c")
assert lbmq.get() == "c"
assert lbmq.get() == "d"
Loading