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 2023/10/04 22:26:43 UTC

[couchdb] branch main updated: Fix flaky fabric_bench test

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

vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/main by this push:
     new 44a357d3e Fix flaky fabric_bench test
44a357d3e is described below

commit 44a357d3e983f77b4800ec7bbdac1b0d27eab5bb
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Wed Oct 4 17:30:41 2023 -0400

    Fix flaky fabric_bench test
    
    Rapidly creating and deleting a db in the this test triggers a race condition.
    A potential culprit might be the gen_server cast in
    https://github.com/apache/couchdb/blob/main/src/mem3/src/mem3_util.erl#L176. To
    fix the flakiness use the newer `opts_for_db/1` function with a test wait
    function. This way we may also avoid inadvertently re-creating the shard file
    due to the `create_if_missing` option from `get_doc_count/1`.
---
 src/fabric/test/eunit/fabric_bench_test.erl | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/fabric/test/eunit/fabric_bench_test.erl b/src/fabric/test/eunit/fabric_bench_test.erl
index afdd03db1..0c9e85372 100644
--- a/src/fabric/test/eunit/fabric_bench_test.erl
+++ b/src/fabric/test/eunit/fabric_bench_test.erl
@@ -56,7 +56,17 @@ t_old_db_deletion_works(_Ctx) ->
     Db = <<"fabricbenchdb-", Suffix/binary>>,
     ok = fabric:create_db(Db, [{q, 1}, {n, 1}]),
     fabric_bench:delete_old_dbs(),
-    ?assertError(database_does_not_exist, fabric:get_doc_count(Db)).
+    % Quick db creation and deletion is racy so
+    % we have to wait until the db is gone before proceeding.
+    WaitFun = fun() ->
+        try mem3_shards:opts_for_db(Db) of
+            _ -> wait
+        catch
+            error:database_does_not_exist ->
+                ok
+        end
+    end,
+    test_util:wait(WaitFun, 1000).
 
 t_newer_db_deletion_doesnt_work(_Ctx) ->
     SevenHoursAgoUsec = os:system_time(microsecond) - (7 * 60 * 60 * 1000000),