summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Avdey <eiri@eiri.ca>2017-06-16 14:01:20 -0300
committerEric Avdey <eiri@eiri.ca>2017-06-16 14:01:20 -0300
commit4249ab34c0e7685285685401f7710559e3c77d01 (patch)
tree8a07592104b58aef3877aef3dc1cf24d85ab8fb6
parentd3bae3f14062b6957f5daaa7208c4b7ed63154ac (diff)
downloadcouchdb-4249ab34c0e7685285685401f7710559e3c77d01.tar.gz
Fix race in couchdb_views_tests
There are a race condition in `restore_backup_db_file` function between couch_server eviction of an old db updater and a test quering view on restored db file. The query in test can get old record for the updater and then crash with `noproc` exception. This change makes `restore_backup_db_file` to wait until start of the new db updater.
-rw-r--r--src/couch/test/couchdb_views_tests.erl15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/couch/test/couchdb_views_tests.erl b/src/couch/test/couchdb_views_tests.erl
index 05a4d98ab..e320b54c6 100644
--- a/src/couch/test/couchdb_views_tests.erl
+++ b/src/couch/test/couchdb_views_tests.erl
@@ -168,7 +168,7 @@ should_not_remember_docs_in_index_after_backup_restore(DbName) ->
?assert(has_doc("doc3", Rows0)),
?assert(has_doc("doc666", Rows0)),
- restore_backup_db_file(DbName),
+ ?assertEqual(ok, restore_backup_db_file(DbName)),
Rows1 = query_view(DbName, "foo", "bar"),
?assert(has_doc("doc1", Rows1)),
@@ -565,14 +565,21 @@ backup_db_file(DbName) ->
restore_backup_db_file(DbName) ->
DbDir = config:get("couchdb", "database_dir"),
- {ok, Db} = couch_db:open_int(DbName, []),
+ {ok, #db{main_pid = UpdaterPid} = Db} = couch_db:open_int(DbName, []),
ok = couch_db:close(Db),
- exit(Db#db.main_pid, shutdown),
+ exit(UpdaterPid, shutdown),
DbFile = filename:join([DbDir, ?b2l(DbName) ++ ".couch"]),
ok = file:delete(DbFile),
ok = file:rename(DbFile ++ ".backup", DbFile),
- ok.
+
+ test_util:wait(fun() ->
+ case couch_server:open(DbName, [{timeout, ?TIMEOUT}]) of
+ {ok, #db{main_pid = UpdaterPid}} -> wait;
+ {ok, _} -> ok;
+ Else -> Else
+ end
+ end, ?TIMEOUT, ?DELAY).
compact_db(DbName) ->
{ok, Db} = couch_db:open_int(DbName, []),