Skip to content

Commit 4683f51

Browse files
committed
Whait db close a little bit before failing test
Databases are closed asynchronously. However it was not accounted for in the test case. This commit waits database to close before it makes a decission to abort the test. I.e. if test case detects that database is still opened after 1 second it considers it as failure.
1 parent 6a54abe commit 4683f51

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/couch_index/test/couch_index_compaction_tests.erl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
-include_lib("couch/include/couch_eunit.hrl").
1616
-include_lib("couch/include/couch_db.hrl").
1717

18+
-define(WAIT_TIMEOUT, 1000).
19+
1820
setup() ->
1921
DbName = ?tempdb(),
2022
{ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
@@ -86,10 +88,18 @@ hold_db_for_recompaction({Db, Idx}) ->
8688
throw(timeout)
8789
end,
8890

89-
?assertNot(is_opened(Db)),
91+
?assertEqual(ok, wait_db_close(Db)),
9092
ok
9193
end).
9294

95+
wait_db_close(Db) ->
96+
test_util:wait(fun() ->
97+
case is_opened(Db) of
98+
false -> ok;
99+
true -> wait
100+
end
101+
end, ?WAIT_TIMEOUT).
102+
93103
is_opened(Db) ->
94104
Monitors = [M || M <- couch_db:monitored_by(Db), M =/= self()],
95105
Monitors /= [].

0 commit comments

Comments
 (0)