Swallow exceptions in TestContentProvider when writing to a pipe fails
The existing code results in flaky tests, where sometimes the write fails (with "EPIPE (broken pipe)") and the exception propagates out and causes the test to never complete and time out. Swallowing the exception resolves this flakiness. #minor-release PiperOrigin-RevId: 372909415
This commit is contained in:
parent
5517fd7936
commit
7a3d8b5ef0
@ -23,6 +23,8 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.OsConstants;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -110,12 +112,17 @@ public final class TestContentProvider extends ContentProvider
|
||||
String mimeType,
|
||||
@Nullable Bundle opts,
|
||||
@Nullable Object args) {
|
||||
try {
|
||||
try (FileOutputStream outputStream = new FileOutputStream(output.getFileDescriptor())) {
|
||||
byte[] data = TestUtil.getByteArray(getContext(), getFileName(uri));
|
||||
FileOutputStream outputStream = new FileOutputStream(output.getFileDescriptor());
|
||||
outputStream.write(data);
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
if (e.getCause() instanceof ErrnoException
|
||||
&& ((ErrnoException) e.getCause()).errno == OsConstants.EPIPE) {
|
||||
// Swallow the exception if it's caused by a broken pipe - this indicates the reader has
|
||||
// closed the pipe and is therefore no longer interested in the data being written.
|
||||
// [See internal b/186728171].
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException("Error writing to pipe", e);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user