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 2021/04/27 15:58:46 UTC

[couchdb] 01/01: Fix flaky couch_jobs metadata test

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

vatamane pushed a commit to branch fix-flaky-couch-jobs-metadata-test
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit de5c24da490cc9a6012e36a4b6078e75b8849690
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Tue Apr 27 11:53:33 2021 -0400

    Fix flaky couch_jobs metadata test
    
    Previously we deleted the ets handle cache, then bumped the FDB metadata. That
    has a race condition if anything else, like fabric2_indexing or other
    couch_jobs users, tried to get a jtx() handle before the metadata bump. In that
    case, they would have re-inserted a handle with a stale `md_version` and the
    test assertions would fail.
    
    The fix is to first bump the md version, then delete the handles.
---
 src/couch_jobs/test/couch_jobs_tests.erl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/couch_jobs/test/couch_jobs_tests.erl b/src/couch_jobs/test/couch_jobs_tests.erl
index d006672..9f3a372 100644
--- a/src/couch_jobs/test/couch_jobs_tests.erl
+++ b/src/couch_jobs/test/couch_jobs_tests.erl
@@ -757,13 +757,15 @@ metadata_version_bump(_) ->
     JTx1 = couch_jobs_fdb:tx(couch_jobs_fdb:get_jtx(), fun(Tx) -> Tx end),
     ?assertMatch(#{md_version := not_found}, JTx1),
 
-    ets:delete_all_objects(couch_jobs_fdb),
     couch_jobs_fdb:bump_metadata_version(),
+    ets:delete_all_objects(couch_jobs_fdb),
+
     JTx2 = couch_jobs_fdb:tx(couch_jobs_fdb:get_jtx(), fun(Tx) -> Tx end),
     ?assertMatch(#{md_version := Bin} when is_binary(Bin), JTx2),
 
-    ets:delete_all_objects(couch_jobs_fdb),
     couch_jobs_fdb:bump_metadata_version(),
+    ets:delete_all_objects(couch_jobs_fdb),
+
     JTx3 = couch_jobs_fdb:tx(couch_jobs_fdb:get_jtx(), fun(Tx) -> Tx end),
     OldMdv = maps:get(md_version, JTx2),
     NewMdv = maps:get(md_version, JTx3),