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

Commit 8c9735d3 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Reduce concurrent issues of WmTests" into main

parents 87a7a1d9 ad6eb1a2
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -864,5 +865,24 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen
            throw new RuntimeException("Both mMessageString and mMessageHash should never be null");
        }
    }

    /**
     * This is only used by unit tests to wait until {@link #connectToConfigurationService} is
     * done. Because unit tests are sensitive to concurrent accesses.
     */
    @VisibleForTesting
    public static void waitForInitialization() {
        final IProtoLog currentInstance = ProtoLog.getSingleInstance();
        if (!(currentInstance instanceof PerfettoProtoLogImpl protoLog)) {
            return;
        }
        try {
            protoLog.mBackgroundLoggingService.submit(() -> {
                Log.i(LOG_TAG, "Complete initialization");
            }).get();
        } catch (InterruptedException | ExecutionException e) {
            Log.e(LOG_TAG, "Failed to wait for tracing service", e);
        }
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ import android.view.SurfaceControl;

import com.android.dx.mockito.inline.extended.StaticMockitoSession;
import com.android.internal.os.BackgroundThread;
import com.android.internal.protolog.PerfettoProtoLogImpl;
import com.android.internal.protolog.ProtoLog;
import com.android.internal.protolog.WmProtoLogGroups;
import com.android.server.AnimationThread;
@@ -187,7 +188,10 @@ public class SystemServicesTestRule implements TestRule {
    }

    private void setUp() {
        if (ProtoLog.getSingleInstance() == null) {
            ProtoLog.init(WmProtoLogGroups.values());
            PerfettoProtoLogImpl.waitForInitialization();
        }

        if (mOnBeforeServicesCreated != null) {
            mOnBeforeServicesCreated.run();