You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2020/06/05 21:38:17 UTC

[couchdb] 02/05: WIP fixing tests

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

davisp pushed a commit to branch prototype/fdb-layer-db-version-as-vstamps
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit da4fe9494885621c366147703af72f8816e5cf91
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Fri Jun 5 15:38:52 2020 -0500

    WIP fixing tests
---
 src/fabric/test/fabric2_db_misc_tests.erl | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/fabric/test/fabric2_db_misc_tests.erl b/src/fabric/test/fabric2_db_misc_tests.erl
index a8a2677..2777236 100644
--- a/src/fabric/test/fabric2_db_misc_tests.erl
+++ b/src/fabric/test/fabric2_db_misc_tests.erl
@@ -340,13 +340,18 @@ metadata_bump({DbName, _, _}) ->
     % Perform a random operation which calls ensure_current
     {ok, _} = fabric2_db:get_db_info(Db),
 
+    % After previous operation, the cache should have been cleared
+    ?assertMatch(undefined, fabric2_server:fetch(DbName, undefined)),
+
+    % Call open again and check that we have the latest db version
+    {ok, Db2} = fabric2_db:open(DbName, [{user_ctx, ?ADMIN_USER}]),
+
     % Check that db handle in the cache got the new metadata version
     % and that check_current_ts was updated
-    CachedDb = fabric2_server:fetch(DbName, undefined),
     ?assertMatch(#{
         md_version := NewMDVersion,
         check_current_ts := Ts
-    } when Ts >= TsBeforeEnsureCurrent, CachedDb).
+    } when Ts >= TsBeforeEnsureCurrent, Db2).
 
 
 db_version_bump({DbName, _, _}) ->
@@ -358,12 +363,12 @@ db_version_bump({DbName, _, _}) ->
     % regular db open + update security doc or something like that to make sure
     % we don't touch the local cache
     #{db_prefix := DbPrefix} = Db,
-    DbVersionKey = erlfdb_tuple:pack({?DB_VERSION}, DbPrefix),
     {ok, Fdb} = application:get_env(fabric, db),
-    NewDbVersion = fabric2_util:uuid(),
     erlfdb:transactional(Fdb, fun(Tx) ->
-        erlfdb:set(Tx, DbVersionKey, NewDbVersion),
-        erlfdb:set_versionstamped_value(Tx, ?METADATA_VERSION_KEY, <<0:112>>)
+        DbVersionKey = erlfdb_tuple:pack({?DB_VERSION}, DbPrefix),
+        DbVersion = fabric2_fdb:new_versionstamp(Tx),
+        DbVersionVal = erlfdb_tuple:pack_vs({DbVersion}),
+        ok = erlfdb:set_versionstamped_value(Tx, DbVersionKey, DbVersionVal)
     end),
 
     % Perform a random operation which calls ensure_current
@@ -376,14 +381,14 @@ db_version_bump({DbName, _, _}) ->
     {ok, Db2} = fabric2_db:open(DbName, [{user_ctx, ?ADMIN_USER}]),
 
     % Check that db handle in the cache got the new metadata version
-    ?assertMatch(#{db_version := NewDbVersion}, Db2).
+    ?assert(maps:get(db_version, Db) /= maps:get(db_version, Db2)).
 
 
 db_cache_doesnt_evict_newer_handles({DbName, _, _}) ->
     {ok, Db} = fabric2_db:open(DbName, [{user_ctx, ?ADMIN_USER}]),
     CachedDb = fabric2_server:fetch(DbName, undefined),
 
-    StaleDb = Db#{md_version := <<0>>},
+    StaleDb = Db#{db_version := <<0>>},
 
     ok = fabric2_server:store(StaleDb),
     ?assertEqual(CachedDb, fabric2_server:fetch(DbName, undefined)),