Fix the test flake in testRemoveServicesAfterSocketDestroyed

The removeServices() is running on a different handler, which
might take some time to complete. Therefore, the verification
should include a timeout to wait longer and prevent test flake.

Bug: 367429622
Test: atest MdnsDiscoveryManagerTests#testRemoveServicesAfter\
      SocketDestroyed --iteration
Change-Id: I79626bad680a62993c3e7d6b356acc10755257e3
This commit is contained in:
Paul Hu 2024-09-26 05:56:28 +00:00
commit 78bd66003a

View file

@ -26,6 +26,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -499,7 +500,7 @@ public class MdnsDiscoveryManagerTests {
verify(executorProvider).shutdownExecutorService(mockExecutorService);
verify(mockServiceTypeClientType1Network1).stopSendAndReceive(mockListenerOne);
verify(socketClient).stopDiscovery();
verify(mockServiceCache).removeServices(cacheKey);
verify(mockServiceCache, timeout(DEFAULT_TIMEOUT)).removeServices(cacheKey);
}
@Test
@ -523,7 +524,7 @@ public class MdnsDiscoveryManagerTests {
runOnHandler(() -> callback.onSocketDestroyed(SOCKET_KEY_NETWORK_1));
verify(mockServiceTypeClientType1Network1).notifySocketDestroyed();
verify(executorProvider).shutdownExecutorService(mockExecutorService);
verify(mockServiceCache).removeServices(cacheKey);
verify(mockServiceCache, timeout(DEFAULT_TIMEOUT)).removeServices(cacheKey);
}
private MdnsPacket createMdnsPacket(String serviceType) {