diff options
author | Nick Vatamaniuc <vatamane@apache.org> | 2020-02-07 15:00:31 -0500 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2020-02-07 17:10:20 -0500 |
commit | b3d9399ada1a1262c1cd68ecf997b46bf4ed2b44 (patch) | |
tree | 612f1d0be14d78ff074b94e59f2e5c6a95c489b5 | |
parent | c4aee4dc5b19cdcc55bb44e8863bc62403d635e6 (diff) | |
download | couchdb-b3d9399ada1a1262c1cd68ecf997b46bf4ed2b44.tar.gz |
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'
```
-rw-r--r-- | src/couch_replicator/src/couch_replicator_clustering.erl | 16 |
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. |