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

Commit 097a5edb authored by Lyn's avatar Lyn
Browse files

Fix flaky history job service test

I suspect this test flakes because it sets JobServiceEngine
via reflection, bypassing the proper construction of
JobServiceEngine (via JobService.onBind), which inits the
JobHandler that we need to get a non-null message.

Fixes: 302339170
Test: NotificationHistoryJobServiceTest
Change-Id: Ia7af0f2c2b96ecb6202369418b53a69d083982da
parent 192076db
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.Context;
import android.os.CancellationSignal;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.LocalServices;

import java.util.concurrent.TimeUnit;
@@ -77,5 +78,11 @@ public class NotificationHistoryJobService extends JobService {
        }
        return false;
    }

    @Override
    @VisibleForTesting
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -71,10 +71,10 @@ public class NotificationHistoryJobServiceTest extends UiServiceTestCase {
    @Before
    public void setUp() throws Exception {
        mJobService = new NotificationHistoryJobService();
        mJobService.attachBaseContext(mContext);
        mJobService.onCreate();
        mJobService.onBind(/* intent= */ null);  // Create JobServiceEngine within JobService.

        final Field field = JobService.class.getDeclaredField("mEngine");
        field.setAccessible(true);
        field.set(mJobService, mock(JobServiceEngine.class));
        mContext.addMockSystemService(JobScheduler.class, mMockJobScheduler);

        // add NotificationManagerInternal to LocalServices