iilyak commented on a change in pull request #610: Optimize ddoc cache URL: https://github.com/apache/couchdb/pull/610#discussion_r129131704
########## File path: src/ddoc_cache/test/ddoc_cache_coverage_test.erl ########## @@ -0,0 +1,77 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(ddoc_cache_coverage_test). + + +-include_lib("couch/include/couch_db.hrl"). +-include_lib("eunit/include/eunit.hrl"). +-include("ddoc_cache_test.hrl"). + + +coverage_test_() -> + { + setup, + fun ddoc_cache_tutil:start_couch/0, + fun ddoc_cache_tutil:stop_couch/1, + [ + fun restart_lru/0, + fun stop_on_evictor_death/0 + ] + }. + + +restart_lru() -> + send_bad_messages(ddoc_cache_lru), + ?assertEqual(ok, ddoc_cache_lru:terminate(bang, {st, a, b, c})), + ?assertEqual({ok, foo}, ddoc_cache_lru:code_change(1, foo, [])). + + +stop_on_evictor_death() -> + meck:new(ddoc_cache_ev, [passthrough]), + try + Lru = whereis(ddoc_cache_lru), + State = sys:get_state(Lru), Review comment: Would you consider to not rely on internals? There are few approaches to do it: 1. Export a small boilerplate with every gen_server [which uses `r2l` macro](https://github.com/cloudant/cfcheck/blob/master/src/cfcheck.erl#L98). ``` get_state() -> ?r2l(sys:get_state(whereis(?MODULE)). get_state(Keys) -> %% this would return values in the order of the Keys %% so we can use [Foo, Bar] = ddoc_cache_lru:get_state([foo, bar]). %% end we wouldn't have to update all integer offsets when we change the record [proplists:get_value(K, get_state()) || K <- Keys]. ``` 2. export specific introspection functions for testing (get_evictor) 3. export test function implementing actions (stop_evictor) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
