anchor.diff:      couch_mrview:cleanup(Db),
       couch_db:close(Db).
   
  -get_db_ref_counter(DbName) ->
  -    {ok, #db{fd_ref_counter = Ref} = Db} = couch_db:open_int(DbName, []),
  +count_users(DbName) ->
  +    {ok, Db} = couch_db:open_int(DbName, [?ADMIN_CTX]),
  +    {monitored_by, Monitors} = erlang:process_info(Db#db.main_pid, monitored_by),
       ok = couch_db:close(Db),
  -    Ref.
  -
  -count_db_refs(DbName) ->
  -    Ref = get_db_ref_counter(DbName),
  -    % have to sleep a bit to let couchdb cleanup all refs and leave only
  -    % active ones. otherwise the related tests will randomly fail due to
  -    % count number mismatch
  -    timer:sleep(200),
  -    couch_ref_counter:count(Ref).
  +    length(lists:usort(Monitors) -- [self()]).
   
   count_index_files(DbName) ->
       % call server to fetch the index files
  
positive.code:         ?assert(is_pid(NewIndexerPid)),
          ?assert(is_process_alive(NewIndexerPid)),
          ?assertNotEqual(IndexerPid, NewIndexerPid),
          ?assertEqual(2, count_db_refs(DbName)),
  
          Rows1 = query_view(DbName, "foo", "bar", ok),
          ?assertEqual(0, length(Rows1)),
  
negative.code: 
  restore_backup_db_file(DbName) ->
      DbDir = config:get("couchdb", "database_dir"),
  
      {ok, Db} = couch_db:open_int(DbName, []),
      ok = couch_db:close(Db),
      exit(Db#db.main_pid, shutdown),
  
      DbFile = filename:join([DbDir, ?b2l(DbName) ++ ".couch"]),
      ok = file:delete(DbFile),
      ok = file:rename(DbFile ++ ".backup", DbFile),
      ok.
  
  compact_db(DbName) ->
  