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

Commit 33e99399 authored by David Duarte's avatar David Duarte
Browse files

BumbleBluetoothTests: Ignore UNAVAILABLE status during factoryReset

During factoryReset a Pandora Server might shutdown itself (Bumble do
this) leading to the stream being closed and the call failing with
an UNAVAILABLE status.
As this is an expected behavior, ignore this error.

Bug: 322509596
Test: atest BumbleBluetoothTests
Flag: Exempt, Test only change
Change-Id: I98f937089413d480519e80b8ad41d7498150437b
parent 25dea0d2
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);