Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeout in couchdb_views_test for couchdb_1283 #668

Merged
merged 1 commit into from
Jul 13, 2017

Conversation

davisp
Copy link
Member

@davisp davisp commented Jul 12, 2017

Fix for #655

I believe the race here was that the query could return before the
actual index updating process exited. Then it was just a race to
creating a database before the monitor is released.

If we do end up creating the database before the monitor is released
then the database we want to have closed ends up being ignored as its
not idle. The second two created databases then don't end up forcing the
database from couch_server's LRU which leads us to the timeout waiting
for DatabaseMonRef to fire.

Fixes #655
@nickva
Copy link
Contributor

nickva commented Jul 13, 2017

Confirmed this fixes the issue.

Couldn't replicate this easily on my artificially slowed down VM even. Got it to where the test itself would timeout but it wouldn't fail like on Travis. I think the idea is to slow down the storage subsystem not the CPU.

There is a way to do it, but I am lazy so did resorted to just adding a sleep to the update runner before the:

exit({updated, self(), FinalIdxState}) line.

And a few log statements:

(655-fix-couchdb-views-tests)$ git diff
diff --git a/src/couch_index/src/couch_index_updater.erl b/src/couch_index/src/couch_index_updater.erl
index ad48f40..aedd2d1 100644
--- a/src/couch_index/src/couch_index_updater.erl
+++ b/src/couch_index/src/couch_index_updater.erl
@@ -69,6 +69,7 @@ handle_call({update, IdxState}, _From, #st{idx=Idx, mod=Mod}=State) ->
     Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
     couch_log:info("Starting index update for db: ~s idx: ~s", Args),
     Pid = spawn_link(?MODULE, update, [Idx, Mod, IdxState]),
+    io:format(standard_error, "~n XXXXXX handle_call update spawned ~p~n", [Pid]),
     {reply, ok, State#st{pid=Pid}};
 handle_call({restart, IdxState}, _From, #st{idx=Idx, mod=Mod}=State) ->
     Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
@@ -100,6 +101,7 @@ handle_info({'EXIT', _, {reset, Pid}}, #st{idx=Idx, pid=Pid}=State) ->
     Pid2 = spawn_link(?MODULE, update, [Idx, State#st.mod, NewIdxState]),
     {noreply, State#st{pid=Pid2}};
 handle_info({'EXIT', Pid, normal}, #st{pid=Pid}=State) ->
+    io:format(standard_error, "~n XXXXXX handle_info Pid normal set to undefined ~p~n", [Pid]),
     {noreply, State#st{pid=undefined}};
 handle_info({'EXIT', Pid, {{nocatch, Error}, _Trace}}, State) ->
     handle_info({'EXIT', Pid, Error}, State);
@@ -193,6 +195,8 @@ update(Idx, Mod, IdxState) ->
         end,

         {ok, FinalIdxState} = Mod:finish_update(LastIdxSt),
+        timer:sleep(1000),
+        io:format(standard_error, "~n XXXXXX  update exiting self() = ~p~n", [self()]),
         exit({updated, self(), FinalIdxState})
     end).

Now could see the failure:

*failed*
in function couchdb_views_tests:wait_for_process_shutdown/3 (test/couchdb_views_tests.erl, line 413)
in call from couchdb_views_tests:'-couchdb_1283/0-fun-21-'/0 (test/couchdb_views_tests.erl, line 358)
**error:{assertion_failed,[{module,couchdb_views_tests},
                   {line,415},
                   {reason,"Failure waiting for db shutdown"}]}

Then the PR fixes the failure:

==> couch (eunit)
    Running test function(s):
      couchdb_views_tests:view_group_shutdown_test_/0
======================== EUnit ========================
View group shutdown
Application crypto was left running!
  couchdb_views_tests:315: couchdb_1283...
 XXXXXX handle_call update spawned <0.318.0>

 XXXXXX  update exiting self() = <0.318.0>
[1.286 s] ok

+1

Very nice!

@davisp davisp merged commit 11afc8b into master Jul 13, 2017
@davisp davisp deleted the 655-fix-couchdb-views-tests branch July 13, 2017 15:47
nickva pushed a commit to nickva/couchdb that referenced this pull request Sep 7, 2022
…ranch names (apache#668)

* Fix broken couch_replicator link

* Fix broken README.Debian link

* Use main branch in contributing guide

* Remove README build state badge pointing to unused Travis CI project
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants