Skip to content

Commit 3fb3af4

Browse files
android-interop-testing: skip integration tests if there is not enough memory
1 parent f5f9ca5 commit 3fb3af4

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

  • android-interop-testing/app/src/main/java/io/grpc/android/integrationtest

android-interop-testing/app/src/main/java/io/grpc/android/integrationtest/InteropTester.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ public void emptyUnary() {
219219
}
220220

221221
public void largeUnary() {
222+
if (shouldSkip()) {
223+
return;
224+
}
222225
final Messages.SimpleRequest request = new Messages.SimpleRequest();
223226
request.responseSize = 314159;
224227
request.responseType = Messages.COMPRESSABLE;
@@ -516,6 +519,9 @@ public void onClose(io.grpc.Status status, Metadata trailers) {
516519
}
517520

518521
public void veryLargeRequest() throws Exception {
522+
if (shouldSkip()) {
523+
return;
524+
}
519525
final SimpleRequest request = new SimpleRequest();
520526
request.payload = new Payload();
521527
request.payload.type = Messages.COMPRESSABLE;
@@ -531,6 +537,9 @@ public void veryLargeRequest() throws Exception {
531537
}
532538

533539
public void veryLargeResponse() throws Exception {
540+
if (shouldSkip()) {
541+
return;
542+
}
534543
final SimpleRequest request = new SimpleRequest();
535544
request.responseSize = unaryPayloadLength();
536545
request.responseType = Messages.COMPRESSABLE;
@@ -738,4 +747,21 @@ public interface TestListener {
738747

739748
void onPostTest(String result);
740749
}
750+
751+
/**
752+
* Some tests run on memory constrained environments. Rather than OOM, just give up. 64 is
753+
* choosen as a maximum amount of memory a large test would need.
754+
*/
755+
private static boolean shouldSkip() {
756+
Runtime r = Runtime.getRuntime();
757+
long usedMem = r.totalMemory() - r.freeMemory();
758+
long actuallyFreeMemory = r.maxMemory() - usedMem;
759+
long wantedFreeMemory = 64 * 1024 * 1024;
760+
if (actuallyFreeMemory < wantedFreeMemory) {
761+
Log.i(LOG_TAG, "Skipping due to lack of memory. " +
762+
"Have: " + actuallyFreeMemory + " Want: " + wantedFreeMemory);
763+
return true;
764+
}
765+
return false;
766+
}
741767
}

0 commit comments

Comments
 (0)