You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2020/02/07 20:02:00 UTC

[couchdb] 01/01: Fix race condition in couch_replicator_clustering eunit setup

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch fix-replicator-clustering-test-race-condition
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 75be3c1a6c44f7ad0f25b359ec57c2e0d9e346be
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Fri Feb 7 15:00:31 2020 -0500

    Fix race condition in couch_replicator_clustering eunit setup
    
    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'
    ```
---
 src/couch_replicator/src/couch_replicator_clustering.erl | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/couch_replicator/src/couch_replicator_clustering.erl b/src/couch_replicator/src/couch_replicator_clustering.erl
index 3ea6934..18de1e8 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.