summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2020-02-07 15:00:31 -0500
committerNick Vatamaniuc <vatamane@apache.org>2020-02-07 15:00:31 -0500
commit75be3c1a6c44f7ad0f25b359ec57c2e0d9e346be (patch)
tree612f1d0be14d78ff074b94e59f2e5c6a95c489b5
parentc4aee4dc5b19cdcc55bb44e8863bc62403d635e6 (diff)
downloadcouchdb-fix-replicator-clustering-test-race-condition.tar.gz
Fix race condition in couch_replicator_clustering eunit setupfix-replicator-clustering-test-race-condition
Observed on FreeBSD Jenkins test runner: ``` function couch_replicator_clustering:setup/0 (src/couch_replicator_clustering.erl, line 257) **error:{badmatch,{error,{already_started,<0.3165.0>}}} in module 'couch_replicator_clustering' ```
-rw-r--r--src/couch_replicator/src/couch_replicator_clustering.erl16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/couch_replicator/src/couch_replicator_clustering.erl b/src/couch_replicator/src/couch_replicator_clustering.erl
index 3ea693465..18de1e825 100644
--- a/src/couch_replicator/src/couch_replicator_clustering.erl
+++ b/src/couch_replicator/src/couch_replicator_clustering.erl
@@ -254,12 +254,26 @@ setup() ->
couch_stats,
couch_replicator_notifier
]),
+ stop_clustering_process(),
{ok, Pid} = start_link(),
Pid.
teardown(Pid) ->
+ stop_clustering_process(Pid).
+
+
+stop_clustering_process() ->
+ stop_clustering_process(whereis(?MODULE)).
+
+
+stop_clustering_process(undefined) ->
+ ok;
+
+stop_clustering_process(Pid) when is_pid(Pid) ->
+ Ref = erlang:monitor(process, Pid),
unlink(Pid),
- exit(Pid, kill).
+ exit(Pid, kill),
+ receive {'DOWN', Ref, _, _, _} -> ok end.
-endif.