diff options
author | Matthias Radestock <matthias@lshift.net> | 2009-04-15 17:48:37 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@lshift.net> | 2009-04-15 17:48:37 +0100 |
commit | 2fc070e4fec26687cfd9af4fd10cf60ce36a0ad4 (patch) | |
tree | 344f7226a472184367fc80d71a437e5fdfcc6e20 | |
parent | 627b5bc7237a365add060bb869ab773ca3daa64b (diff) | |
download | rabbitmq-server-bug20354.tar.gz |
handle negative prioritiesbug20354
-rw-r--r-- | src/priority_queue.erl | 2 | ||||
-rw-r--r-- | src/rabbit_tests.erl | 4 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/priority_queue.erl b/src/priority_queue.erl index b872c8d5..88ad0c18 100644 --- a/src/priority_queue.erl +++ b/src/priority_queue.erl @@ -111,6 +111,8 @@ in(X, 0, {queue, [_] = In, []}) -> {queue, [X], In}; in(X, 0, {queue, In, Out}) when is_list(In), is_list(Out) -> {queue, [X|In], Out}; +in(X, Priority, Q = {queue, [], []}) -> + in(X, Priority, {pqueue, []}); in(X, Priority, Q = {queue, _, _}) -> in(X, Priority, {pqueue, [{0, Q}]}); in(X, Priority, {pqueue, Queues}) -> diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 946b8c31..7d5fe2c1 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -83,6 +83,10 @@ test_priority_queue() -> {true, false, 2, [{2, bar}, {1, foo}], [bar, foo]} = test_priority_queue(Q3), + %% 1-element negative priority Q + Q4 = priority_queue:in(foo, -1, priority_queue:new()), + {true, false, 1, [{-1, foo}], [foo]} = test_priority_queue(Q4), + passed. priority_queue_in_all(Q, L) -> |