Add a 120s timeout to transformer running within instrumentation tests.

PiperOrigin-RevId: 411526089
This commit is contained in:
samrobinson 2021-11-22 12:43:54 +00:00 committed by Ian Baker
parent 1a1d27aee6
commit d6cddf9ac1
6 changed files with 34 additions and 14 deletions

View File

@ -15,6 +15,9 @@
*/ */
package androidx.media3.transformer; package androidx.media3.transformer;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.util.concurrent.TimeUnit.SECONDS;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -29,8 +32,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
/** Utilities for instrumentation tests. */ /** Utilities for instrumentation tests. */
/* package */ final class AndroidTestUtil { /* package */ final class AndroidTestUtil {
public static final String MP4_ASSET_URI = "asset:///media/mp4/sample.mp4"; public static final String MP4_ASSET_URI_STRING = "asset:///media/mp4/sample.mp4";
public static final String SEF_ASSET_URI = "asset:///media/mp4/sample_sef_slow_motion.mp4"; public static final String SEF_ASSET_URI_STRING = "asset:///media/mp4/sample_sef_slow_motion.mp4";
public static final String REMOTE_MP4_10_SECONDS_URI_STRING = public static final String REMOTE_MP4_10_SECONDS_URI_STRING =
"https://storage.googleapis.com/exoplayer-test-media-1/mp4/android-screens-10s.mp4"; "https://storage.googleapis.com/exoplayer-test-media-1/mp4/android-screens-10s.mp4";
@ -43,9 +46,19 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
} }
} }
/** Transforms the {@code uriString} with the {@link Transformer}. */ /**
* Transforms the {@code uriString} with the {@link Transformer}.
*
* @param context The {@link Context}.
* @param transformer The {@link Transformer} that performs the transformation.
* @param uriString The uri (as a {@link String}) that will be transformed.
* @param timeoutSeconds The transformer timeout. An assertion confirms this is not exceeded.
* @return The {@link TransformationResult}.
* @throws Exception The cause of the transformation not completing.
*/
public static TransformationResult runTransformer( public static TransformationResult runTransformer(
Context context, Transformer transformer, String uriString) throws Exception { Context context, Transformer transformer, String uriString, int timeoutSeconds)
throws Exception {
AtomicReference<@NullableType Exception> exceptionReference = new AtomicReference<>(); AtomicReference<@NullableType Exception> exceptionReference = new AtomicReference<>();
CountDownLatch countDownLatch = new CountDownLatch(1); CountDownLatch countDownLatch = new CountDownLatch(1);
@ -80,7 +93,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
exceptionReference.set(e); exceptionReference.set(e);
} }
}); });
countDownLatch.await();
assertWithMessage("Transformer timed out after " + timeoutSeconds + " seconds.")
.that(countDownLatch.await(timeoutSeconds, SECONDS))
.isTrue();
@Nullable Exception exception = exceptionReference.get(); @Nullable Exception exception = exceptionReference.get();
if (exception != null) { if (exception != null) {
throw exception; throw exception;

View File

@ -15,7 +15,7 @@
*/ */
package androidx.media3.transformer; package androidx.media3.transformer;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_URI; import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_URI_STRING;
import static androidx.media3.transformer.AndroidTestUtil.runTransformer; import static androidx.media3.transformer.AndroidTestUtil.runTransformer;
import android.content.Context; import android.content.Context;
@ -32,6 +32,6 @@ public class RemoveAudioTransformationTest {
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = Transformer transformer =
new Transformer.Builder().setContext(context).setRemoveAudio(true).build(); new Transformer.Builder().setContext(context).setRemoveAudio(true).build();
runTransformer(context, transformer, MP4_ASSET_URI); runTransformer(context, transformer, MP4_ASSET_URI_STRING, /* timeoutSeconds= */ 120);
} }
} }

View File

@ -15,7 +15,7 @@
*/ */
package androidx.media3.transformer; package androidx.media3.transformer;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_URI; import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_URI_STRING;
import static androidx.media3.transformer.AndroidTestUtil.runTransformer; import static androidx.media3.transformer.AndroidTestUtil.runTransformer;
import android.content.Context; import android.content.Context;
@ -32,6 +32,6 @@ public class RemoveVideoTransformationTest {
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = Transformer transformer =
new Transformer.Builder().setContext(context).setRemoveVideo(true).build(); new Transformer.Builder().setContext(context).setRemoveVideo(true).build();
runTransformer(context, transformer, MP4_ASSET_URI); runTransformer(context, transformer, MP4_ASSET_URI_STRING, /* timeoutSeconds= */ 120);
} }
} }

View File

@ -47,7 +47,11 @@ public final class RepeatedTranscodeTransformationTest {
for (int i = 0; i < TRANSCODE_COUNT; i++) { for (int i = 0; i < TRANSCODE_COUNT; i++) {
// Use a long video in case an error occurs a while after the start of the video. // Use a long video in case an error occurs a while after the start of the video.
long outputSizeBytes = long outputSizeBytes =
runTransformer(context, transformer, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING) runTransformer(
context,
transformer,
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
/* timeoutSeconds= */ 120)
.outputSizeBytes; .outputSizeBytes;
if (previousOutputSizeBytes != C.LENGTH_UNSET) { if (previousOutputSizeBytes != C.LENGTH_UNSET) {
assertWithMessage("Unexpected output size on transcode " + i + " out of " + TRANSCODE_COUNT) assertWithMessage("Unexpected output size on transcode " + i + " out of " + TRANSCODE_COUNT)

View File

@ -15,7 +15,7 @@
*/ */
package androidx.media3.transformer; package androidx.media3.transformer;
import static androidx.media3.transformer.AndroidTestUtil.SEF_ASSET_URI; import static androidx.media3.transformer.AndroidTestUtil.SEF_ASSET_URI_STRING;
import static androidx.media3.transformer.AndroidTestUtil.runTransformer; import static androidx.media3.transformer.AndroidTestUtil.runTransformer;
import android.content.Context; import android.content.Context;
@ -32,6 +32,6 @@ public class SefTransformationTest {
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = Transformer transformer =
new Transformer.Builder().setContext(context).setFlattenForSlowMotion(true).build(); new Transformer.Builder().setContext(context).setFlattenForSlowMotion(true).build();
runTransformer(context, transformer, SEF_ASSET_URI); runTransformer(context, transformer, SEF_ASSET_URI_STRING, /* timeoutSeconds= */ 120);
} }
} }

View File

@ -15,7 +15,7 @@
*/ */
package androidx.media3.transformer; package androidx.media3.transformer;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_URI; import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_URI_STRING;
import static androidx.media3.transformer.AndroidTestUtil.runTransformer; import static androidx.media3.transformer.AndroidTestUtil.runTransformer;
import android.content.Context; import android.content.Context;
@ -31,6 +31,6 @@ public class TransformationTest {
public void transform() throws Exception { public void transform() throws Exception {
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder().setContext(context).build(); Transformer transformer = new Transformer.Builder().setContext(context).build();
runTransformer(context, transformer, MP4_ASSET_URI); runTransformer(context, transformer, MP4_ASSET_URI_STRING, /* timeoutSeconds= */ 120);
} }
} }