anchor.diff:  
   cleanup_mock_getaddr() ->
       catch meck:unload(inet).
  +
  +mock_interactive_getaddr() ->
  +    Self = self(),
  +    ok = meck:expect(inet, getaddr, fun(Hostname, _) ->
  +        Ref = erlang:make_ref(),
  +        Self ! {self(), Ref, {getaddr, Hostname}},
  +        receive
  +            {Ref, error} ->
  +                throw(test_intervactive_call_error);
  +            {Ref, {Delay, Result}} ->
  +                timer:sleep(Delay),
  +                Result
  +        after 5000 ->
  +            throw(test_intervactive_call_timeout)
  +        end
  +    end).
   
   mock_getaddr(Result) ->
       Self = self(),
  
positive.code:     after (TIMEOUT) ->
          dump_messages(),
          ?fail("Message ~s not received", [(??MSG)])
      end
  end()).
  
  
negative.code: 
      ok.
  
  %% Test that adding multiple peers with the same hostname works.
  test_multiple_peers_same_hostname() ->
      test_mgr_set_recipient(self()),
      setup_mock_getaddr(),
  
      Source = {192, 168, 0, 1},
      PubKey1 = <<"ef42d46eace742cd">>,
      Peer1 = peer(PubKey1, <<"aeternity.com">>, 4000),
      PubKey2 = <<"52af7b3a5d2c460b">>,
      Peer2 = peer(PubKey2, <<"aeternity.com">>, 4001),
      PubKey3 = <<"d59e8323509a49da">>,
      Peer3 = peer(PubKey3, <<"aeternity.com">>, 4002),
  
      mock_getaddr({ok, {192, 168, 0, 10}}),
  
      aec_peers:add_peers(Source, Peer1),
      aec_peers:add_peers(Source, Peer2),
      aec_peers:add_peers(Source, Peer3),
  
      ?assertMessage({getaddr, "aeternity.com"}, 50),
      ?assertMessage({getaddr, "aeternity.com"}, 50),
      ?assertMessage({getaddr, "aeternity.com"}, 50),
  
      {ok, Conn1} = ?assertCalled(connect, _, {ok, _}, 300),
      ok = conn_peer_connected(Conn1),
      {ok, Conn2} = ?assertCalled(connect, _, {ok, _}, 1200),
      ok = conn_peer_connected(Conn2),
      {ok, Conn3} = ?assertCalled(connect, _, {ok, _}, 2200),
      ok = conn_peer_connected(Conn3),
  
      ?assertMatch(0, aec_peers:count(hostnames)),
      ?assertEqual(3, aec_peers:count(connections)),
      ?assertEqual(0, aec_peers:count(inbound)),
      ?assertEqual(3, aec_peers:count(outbound)),
      ?assertEqual(3, aec_peers:count(peers)),
      ?assertEqual(3, aec_peers:count(verified)),
      ?assertEqual(0, aec_peers:count(unverified)),
      ?assertEqual(0, aec_peers:count(standby)),
      ok.
  
  %% Test that when resolving multiple peers with the same hostname,
  %% that if some fails they are retried.
  test_multiple_peers_same_hostname_failures() ->
      test_mgr_set_recipient(self()),
      setup_mock_getaddr(),
      mock_interactive_getaddr(),
  
      Source = {192, 168, 0, 1},
      PubKey1 = <<"ef42d46eace742cd">>,
      Peer1 = peer(PubKey1, <<"aeternity.com">>, 4000),
      PubKey2 = <<"52af7b3a5d2c460b">>,
      Peer2 = peer(PubKey2, <<"aeternity.com">>, 4001),
      PubKey3 = <<"d59e8323509a49da">>,
      Peer3 = peer(PubKey3, <<"aeternity.com">>, 4002),
  
      aec_peers:add_peers(Source, Peer1),
      aec_peers:add_peers(Source, Peer2),
      aec_peers:add_peers(Source, Peer3),
  
      ?assertInteractiveMessage({getaddr, "aeternity.com"},
                                {100, {ok, {192, 168, 0, 10}}}, 50),
      ?assertInteractiveMessage({getaddr, "aeternity.com"},
                                {150, {error, nxdomain}}, 50),
      ?assertInteractiveMessage({getaddr, "aeternity.com"},
                                {150, {error, nxdomain}}, 50),
  
      {ok, Conn1} = ?assertCalled(connect, _, {ok, _}, 300),
      ok = conn_peer_connected(Conn1),
  
      ?assertEqual(1, aec_peers:count(connections)),
      ?assertEqual(0, aec_peers:count(inbound)),
      ?assertEqual(1, aec_peers:count(outbound)),
      ?assertEqual(1, aec_peers:count(peers)),
      ?assertEqual(1, aec_peers:count(verified)),
      ?assertEqual(0, aec_peers:count(unverified)),
      ?assertEqual(0, aec_peers:count(standby)),
  
      %% Retry counter is reset when a peer is resolved;
      %% check first try of the remaining peers.
      ?assertInteractiveMessage({getaddr, "aeternity.com"},
                                {50, {error, nxdomain}}, 200),
      ?assertInteractiveMessage({getaddr, "aeternity.com"},
                                {50, {error, nxdomain}}, 200),
  
      %% Check second try of the remaining peers;
      %% one of them resolve successfully.
      ?assertInteractiveMessage({getaddr, "aeternity.com"},
                                {50, {ok, {192, 168, 0, 10}}}, 300),
      ?assertInteractiveMessage({getaddr, "aeternity.com"},
                                {50, {error, nxdomain}}, 300),
  
      {ok, Conn2} = ?assertCalled(connect, _, {ok, _}, 1200),
      ok = conn_peer_connected(Conn2),
  
      %% Retry counter is reset when a peer is resolved;
      %% check first try of the remaining peer.
      ?assertInteractiveMessage({getaddr, "aeternity.com"},
                                {50, {error, nxdomain}}, 200),
  
      %% Check second try of the remaining peer.
      ?assertInteractiveMessage({getaddr, "aeternity.com"},
                                {50, {error, nxdomain}}, 300),
  
      %% Check third try of the remaining peer.
      ?assertInteractiveMessage({getaddr, "aeternity.com"},
                                {50, {error, nxdomain}}, 400),
  
      %% The resolution is not tried anymore.
      ?assertNoInteractiveMessage({getaddr, "aeternity.com"}, 500),
  
      ?assertMatch(0, aec_peers:count(hostnames)),
      ?assertEqual(2, aec_peers:count(connections)),
      ?assertEqual(0, aec_peers:count(inbound)),
      ?assertEqual(2, aec_peers:count(outbound)),
      ?assertEqual(2, aec_peers:count(peers)),
      ?assertEqual(2, aec_peers:count(verified)),
      ?assertEqual(0, aec_peers:count(unverified)),
      ?assertEqual(0, aec_peers:count(standby)),
      ok.
  
  test_address_group_selection() ->
      test_mgr_set_recipient(self()),
  
  