Skip to content

Commit

Permalink
Fix flaky fabric_bench test
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
nickva committed Oct 4, 2023
1 parent baa3767 commit 44a357d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/fabric/test/eunit/fabric_bench_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 44a357d

Please sign in to comment.