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

Commit ba211efa authored by David Duarte's avatar David Duarte Committed by Gerrit Code Review
Browse files

Merge "BumbleBluetoothTests: Ignore UNAVAILABLE status during factoryReset" into main

parents e63bdffe 33e99399
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -23,18 +23,20 @@ import androidx.test.core.app.ApplicationProvider;
import com.google.protobuf.Empty;

import io.grpc.ManagedChannel;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.okhttp.OkHttpChannelBuilder;

import org.junit.rules.ExternalResource;

import java.util.concurrent.TimeUnit;

import pandora.DckGrpc;
import pandora.GATTGrpc;
import pandora.HostGrpc;
import pandora.HostProto;
import pandora.SecurityGrpc;

import java.util.concurrent.TimeUnit;

public final class PandoraDevice extends ExternalResource {
    private static final String TAG = PandoraDevice.class.getSimpleName();
    private final String mNetworkAddress;
@@ -59,7 +61,16 @@ public final class PandoraDevice extends ExternalResource {
        ManagedChannel channel =
                OkHttpChannelBuilder.forAddress(mNetworkAddress, mPort).usePlaintext().build();
        HostGrpc.HostBlockingStub stub = HostGrpc.newBlockingStub(channel);
        try {
            stub.factoryReset(Empty.getDefaultInstance());
        } catch (StatusRuntimeException e) {
            if (e.getStatus().getCode() == Status.Code.UNAVAILABLE) {
                // Server is shutting down, the call might be canceled with an UNAVAILABLE status
                // because the stream is closed.
            } else {
                throw e;
            }
        }
        try {
            // terminate the channel
            channel.shutdown().awaitTermination(1, TimeUnit.SECONDS);