anchor.diff:      couch_file:close(Fd),
       Header.
   
  --endif.
  +stop_indexer(StopFun, Pid, Line, Reason) ->
  +    case test_util:stop_sync(Pid, StopFun) of
  +    timeout ->
  +        erlang:error(
  +            {assertion_failed,
  +             [{module, ?MODULE}, {line, Line},
  +              {reason, Reason}]});
  +    ok ->
  +        ok
  +    end.
  +
  +wait_indexer(IndexerPid) ->
  +    test_util:wait(fun() ->
  +        {ok, Info} = couch_index:get_info(IndexerPid),
  +        case couch_util:get_value(compact_running, Info) of
  +            true ->
  +                wait;
  +            false ->
  +                ok
  +        end
  +    end).
  
positive.code:             couch_mrview_index, DbName, <<"_design/foo">>),
          ?assert(is_pid(IndexerPid)),
          ?assert(is_process_alive(IndexerPid)),
          ?assertEqual(2, count_db_refs(DbName)),
  
          Rows0 = query_view(DbName, "foo", "bar"),
          ?assertEqual(3, length(Rows0)),
          ?assertEqual(2, count_db_refs(DbName)),
          ?assert(is_process_alive(IndexerPid)),
  
          create_doc(DbName, "doc1000"),
          Rows1 = query_view(DbName, "foo", "bar"),
          ?assertEqual(4, length(Rows1)),
          ?assertEqual(2, count_db_refs(DbName)),
          ?assert(is_process_alive(IndexerPid)),
  
          Ref1 = get_db_ref_counter(DbName),
          compact_db(DbName),
          Ref2 = get_db_ref_counter(DbName),
          ?assertEqual(2, couch_ref_counter:count(Ref2)),
          ?assertNotEqual(Ref2, Ref1),
          ?assertNot(is_process_alive(Ref1)),
          ?assert(is_process_alive(IndexerPid)),
  
          compact_view_group(DbName, "foo"),
          ?assertEqual(2, count_db_refs(DbName)),
          Ref3 = get_db_ref_counter(DbName),
          ?assertEqual(Ref3, Ref2),
          ?assert(is_process_alive(IndexerPid)),
  
          create_doc(DbName, "doc1001"),
          Rows2 = query_view(DbName, "foo", "bar"),
          ?assertEqual(5, length(Rows2)),
          ?assertEqual(2, count_db_refs(DbName)),
          ?assert(is_process_alive(IndexerPid))
      end).
  
  
negative.code:             couch_mrview_index, DbName, <<"_design/foo">>),
          ?assert(is_pid(IndexerPid)),
          ?assert(is_process_alive(IndexerPid)),
          ?assertEqual(2, count_users(DbName)),
  
          wait_indexer(IndexerPid),
  
          create_doc(DbName, "doc1001"),
          Rows0 = query_view(DbName, "foo", "bar"),
          check_rows_value(Rows0, null),
          ?assertEqual(4, length(Rows0)),
          ?assertEqual(2, count_users(DbName)),
  
          ?assert(is_process_alive(IndexerPid)),
  
          update_design_doc(DbName,  <<"_design/foo">>, <<"bar">>),
  