Skip to content

Commit

Permalink
Fixed race condition with os:cmd and initial write.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Meredith committed Nov 24, 2010
1 parent 4553570 commit 29ee5e9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions test/bctt
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ do_test(State0) ->
io:format("\nInitial populate.\n"),
State1 = start_writer(State0),
kick_writer(State1),
receive
{'EXIT', _From, Why} ->
erlang:error({writer_failed, Why});
wait_for_writer(State1),

{write_done, 1} ->
ok
end,
%% Start continually rewriting the keys and optionally reading,
%% folding and merging
State = State1#state{seq = 1},
kick_writer(State),
start_readers(State, State#state.readers),
Expand Down Expand Up @@ -149,6 +146,19 @@ restart_procs(State) ->
State
end.

%% Wait for the initial writer to complete - the os:cmd call
%% can generate an EXIT message
wait_for_writer(State) ->
WriterPid = State#state.writer_pid,
receive
{'EXIT', WriterPid, Why} ->
erlang:error({initial_write_failed, Why});
{'EXIT', _Pid, _Why} ->
wait_for_writer(State);
{write_done, 1} ->
ok
end.

wait_for_procs(#state{writers = 0, readers = 0, folders = 0, mergers = 0}) ->
io:format("Test complete\n");
wait_for_procs(State) ->
Expand Down

0 comments on commit 29ee5e9

Please sign in to comment.