Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9a5c6f92 authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Fix TileServiceTest

The test needed to wait for work in the looper to be processed. It was
not waiting for it, leading to flakes.

Test: atest --rerun-until-failure 1000 TileServiceTest
Fixed: 298075609
Change-Id: I62baeb013aad53ab2311ff0372563d58e4a8bc9b
parent f619577c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -61,11 +61,11 @@ android_test {
        "testng",
        "servicestests-utils",
        "device-time-shell-utils",
        "testables",
    ],

    libs: [
        "android.test.runner",
        "testables",
        "org.apache.http.legacy",
        "android.test.base",
        "android.test.mock",
+9 −5
Original line number Diff line number Diff line
@@ -28,26 +28,27 @@ import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@SmallTest
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class TileServiceTest {

    @Mock
    private IQSService.Stub mIQSService;

    private TestableLooper mTestableLooper;

    private IBinder mTileToken;
    private TileService mTileService;
    private Tile mTile;
@@ -56,6 +57,8 @@ public class TileServiceTest {
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        mTestableLooper = TestableLooper.get(this);

        mTileToken = new Binder();
        when(mIQSService.asBinder()).thenCallRealMethod();
        when(mIQSService.queryLocalInterface(anyString())).thenReturn(mIQSService);
@@ -73,6 +76,7 @@ public class TileServiceTest {
        when(mIQSService.getTile(mTileToken)).thenThrow(new RemoteException());

        IBinder result = mTileService.onBind(intent);
        mTestableLooper.processAllMessages();
        assertNull(result);
    }

@@ -84,13 +88,12 @@ public class TileServiceTest {
        when(mIQSService.getTile(mTileToken)).thenReturn(null);

        IBinder result = mTileService.onBind(intent);
        mTestableLooper.processAllMessages();

        assertNotNull(result);
        verify(mIQSService, never()).onStartSuccessful(any());
    }

    // TODO(b/298075609): Test is disabled due to flakiness.
    @Ignore
    @Test
    public void testBindSuccessful() throws RemoteException {
        Intent intent = new Intent();
@@ -99,6 +102,7 @@ public class TileServiceTest {
        when(mIQSService.getTile(mTileToken)).thenReturn(mTile);

        IBinder result = mTileService.onBind(intent);
        mTestableLooper.processAllMessages();

        assertNotNull(result);
        verify(mIQSService).onStartSuccessful(mTileToken);