summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2010-06-02 17:36:23 +0100
committerMatthias Radestock <matthias@lshift.net>2010-06-02 17:36:23 +0100
commit3f23842bba1f0c7431b829b0934399bb51f9aab9 (patch)
treed5d2bf5df933a918e72c1e7f7ae4f9e64c1c6a68
parentbbccf25f6ee73eacd8bee60a1eaec6b520bb1f69 (diff)
downloadrabbitmq-server-bug21932.tar.gz
refactoringbug21932
-rw-r--r--src/rabbit_channel.erl12
-rw-r--r--src/rabbit_tests.erl41
2 files changed, 17 insertions, 36 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl
index d34c5a72..8bc53b4a 100644
--- a/src/rabbit_channel.erl
+++ b/src/rabbit_channel.erl
@@ -220,13 +220,11 @@ handle_cast({deliver, ConsumerTag, AckRequired, Msg},
ok = internal_deliver(WriterPid, true, ConsumerTag, DeliveryTag, Msg),
noreply(State1#ch{next_tag = DeliveryTag + 1});
-handle_cast({conserve_memory, Conserve}, State = #ch{state = starting}) ->
- case Conserve of
- true -> noreply(State);
- false -> ok = rabbit_writer:send_command(State#ch.writer_pid,
- #'channel.open_ok'{}),
- noreply(State#ch{state = running})
- end;
+handle_cast({conserve_memory, true}, State = #ch{state = starting}) ->
+ noreply(State);
+handle_cast({conserve_memory, false}, State = #ch{state = starting}) ->
+ ok = rabbit_writer:send_command(State#ch.writer_pid, #'channel.open_ok'{}),
+ noreply(State#ch{state = running});
handle_cast({conserve_memory, Conserve}, State = #ch{state = running}) ->
flow_control(not Conserve, State);
handle_cast({conserve_memory, _Conserve}, State) ->
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index 8f40d3fa..ecc2613d 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -888,20 +888,19 @@ test_memory_pressure_spawn() ->
end,
{Writer, Ch, MRef}.
+expect_normal_channel_termination(MRef, Ch) ->
+ receive {'DOWN', MRef, process, Ch, normal} -> ok
+ after 1000 -> throw(channel_failed_to_exit)
+ end.
+
test_memory_pressure() ->
{Writer0, Ch0, MRef0} = test_memory_pressure_spawn(),
- ok = rabbit_channel:conserve_memory(Ch0, false),
- ok = rabbit_channel:conserve_memory(Ch0, false),
- ok = rabbit_channel:conserve_memory(Ch0, true),
- ok = rabbit_channel:conserve_memory(Ch0, false),
- ok = rabbit_channel:conserve_memory(Ch0, true),
- ok = rabbit_channel:conserve_memory(Ch0, true),
- ok = rabbit_channel:conserve_memory(Ch0, false),
+ [ok = rabbit_channel:conserve_memory(Ch0, Conserve) ||
+ Conserve <- [false, false, true, false, true, true, false]],
ok = test_memory_pressure_sync(Ch0, Writer0),
receive {'DOWN', MRef0, process, Ch0, Info0} ->
throw({channel_died_early, Info0})
- after 0 ->
- ok
+ after 0 -> ok
end,
%% we should have just 1 active=false waiting for us
@@ -919,11 +918,7 @@ test_memory_pressure() ->
properties_bin = <<>>,
payload_fragments_rev = []},
ok = rabbit_channel:do(Ch0, #'basic.publish'{}, Content),
- receive {'DOWN', MRef0, process, Ch0, normal} ->
- ok
- after 1000 ->
- throw(channel_failed_to_exit)
- end,
+ expect_normal_channel_termination(MRef0, Ch0),
{Writer1, Ch1, MRef1} = test_memory_pressure_spawn(),
ok = rabbit_channel:conserve_memory(Ch1, true),
@@ -934,20 +929,12 @@ test_memory_pressure() ->
ok = test_memory_pressure_receive_flow(true),
%% send back the wrong flow_ok. Channel should die.
ok = rabbit_channel:do(Ch1, #'channel.flow_ok'{active = false}),
- receive {'DOWN', MRef1, process, Ch1, normal} ->
- ok
- after 1000 ->
- throw(channel_failed_to_exit)
- end,
+ expect_normal_channel_termination(MRef1, Ch1),
{_Writer2, Ch2, MRef2} = test_memory_pressure_spawn(),
%% just out of the blue, send a flow_ok. Life should end.
ok = rabbit_channel:do(Ch2, #'channel.flow_ok'{active = true}),
- receive {'DOWN', MRef2, process, Ch2, normal} ->
- ok
- after 1000 ->
- throw(channel_failed_to_exit)
- end,
+ expect_normal_channel_termination(MRef2, Ch2),
{_Writer3, Ch3, MRef3} = test_memory_pressure_spawn(),
ok = rabbit_channel:conserve_memory(Ch3, true),
@@ -976,11 +963,7 @@ test_memory_pressure() ->
after 1000 -> throw(failed_to_receive_channel_open_ok)
end,
rabbit_channel:shutdown(Ch4),
- receive {'DOWN', MRef4, process, Ch4, normal} ->
- ok
- after 1000 ->
- throw(channel_failed_to_exit)
- end,
+ expect_normal_channel_termination(MRef4, Ch4),
passed.