Skip to content

Commit

Permalink
android-interop-testing: skip integration tests if there is not enoug…
Browse files Browse the repository at this point in the history
…h memory
  • Loading branch information
carl-mastrangelo committed Sep 29, 2016
1 parent f5f9ca5 commit 3fb3af4
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ public void emptyUnary() {
}

public void largeUnary() {
if (shouldSkip()) {
return;
}
final Messages.SimpleRequest request = new Messages.SimpleRequest();
request.responseSize = 314159;
request.responseType = Messages.COMPRESSABLE;
Expand Down Expand Up @@ -516,6 +519,9 @@ public void onClose(io.grpc.Status status, Metadata trailers) {
}

public void veryLargeRequest() throws Exception {
if (shouldSkip()) {
return;
}
final SimpleRequest request = new SimpleRequest();
request.payload = new Payload();
request.payload.type = Messages.COMPRESSABLE;
Expand All @@ -531,6 +537,9 @@ public void veryLargeRequest() throws Exception {
}

public void veryLargeResponse() throws Exception {
if (shouldSkip()) {
return;
}
final SimpleRequest request = new SimpleRequest();
request.responseSize = unaryPayloadLength();
request.responseType = Messages.COMPRESSABLE;
Expand Down Expand Up @@ -738,4 +747,21 @@ public interface TestListener {

void onPostTest(String result);
}

/**
* Some tests run on memory constrained environments. Rather than OOM, just give up. 64 is
* choosen as a maximum amount of memory a large test would need.
*/
private static boolean shouldSkip() {
Runtime r = Runtime.getRuntime();
long usedMem = r.totalMemory() - r.freeMemory();
long actuallyFreeMemory = r.maxMemory() - usedMem;
long wantedFreeMemory = 64 * 1024 * 1024;
if (actuallyFreeMemory < wantedFreeMemory) {
Log.i(LOG_TAG, "Skipping due to lack of memory. " +
"Have: " + actuallyFreeMemory + " Want: " + wantedFreeMemory);
return true;
}
return false;
}
}

0 comments on commit 3fb3af4

Please sign in to comment.