Permalink
Browse files

MB-7467: added mapreduce test of context usability after timeout

Change-Id: I977b997e70c1b052ee939ca81317094e9b58769c
Reviewed-on: http://review.couchbase.org/23584
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-on: http://review.couchbase.org/24950
  • Loading branch information...
Aliaksey Kandratsenka authored and fdmanana committed Dec 27, 2012
1 parent dade4e4 commit aa2c26fb3386ee326ce3f204ed7874dd0d60688e
Showing with 31 additions and 1 deletion.
  1. +31 −1 src/mapreduce/test/01-map.t
@@ -26,7 +26,7 @@
main(_) ->
test_util:init_code_path(),
- etap:plan(90),
+ etap:plan(120),
case (catch test()) of
ok ->
etap:end_tests();
@@ -58,6 +58,7 @@ test() ->
test_parallel_burst_maps(25000, 10),
test_parallel_burst_maps(25000, 20),
ok = mapreduce:set_timeout(1000),
+ test_context_is_usable_after_timeout(),
test_many_timeouts(1),
test_many_timeouts(5),
test_many_timeouts(10),
@@ -307,6 +308,35 @@ test_many_timeouts(NumProcesses) ->
end,
Pids).
+test_context_is_usable_after_timeout() ->
+ Doc1 = <<"{\"_id\": \"doc1\", \"value\": 1}">>,
+ Doc2 = <<"{\"_id\": \"doc2\", \"value\": 1}">>,
+ NumProcesses = 30,
+ Pids = lists:map(
+ fun(_) ->
+ spawn_monitor(fun() ->
+ {ok, Ctx} = mapreduce:start_map_context([
+ <<"function(doc) { if (doc._id == \"doc1\") {while (true) { };} else {emit(doc._id, null)} }">>
+ ]),
+ erlang:bump_reductions(100000),
+ RVs = [mapreduce:map_doc(Ctx, D, <<"{}">>) || D <- [Doc1, Doc2]],
+ exit({ok, RVs})
+ end)
+ end,
+ lists:seq(1, NumProcesses)),
+ lists:foreach(
+ fun({Pid, Ref}) ->
+ receive
+ {'DOWN', Ref, process, Pid, {ok, Value}} ->
+ etap:is(Value, [{error, <<"timeout">>}, {ok, [[{<<"\"doc2\"">>, <<"null">>}]]}], "Worker got timeout error and value");
+ {'DOWN', Ref, process, Pid, _Reason} ->
+ etap:bail("Worker died unexpectedly")
+ after 120000 ->
+ etap:bail("Timeout waiting for worker result")
+ end
+ end,
+ Pids).
+
test_half_timeouts(NumProcesses) ->
Pids = lists:map(

0 comments on commit aa2c26f

Please sign in to comment.