8229284: jdk/internal/platform/cgroup/TestCgroupMetrics.java fails for - memory:getMemoryUsage
Reviewed-by: mseledtsov, sgehwolf
--- a/test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java Thu Aug 29 08:35:31 2019 -0700
+++ b/test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java Wed Aug 28 14:22:56 2019 +0200
@@ -582,19 +582,28 @@
Metrics metrics = Metrics.systemMetrics();
long memoryMaxUsage = metrics.getMemoryMaxUsage();
long memoryUsage = metrics.getMemoryUsage();
-
- byte[] bb = new byte[64*1024*1024]; // 64M
+ long newMemoryMaxUsage = 0, newMemoryUsage = 0;
- long newMemoryMaxUsage = metrics.getMemoryMaxUsage();
- long newMemoryUsage = metrics.getMemoryUsage();
+ // allocate memory in a loop and check more than once for new values
+ // otherwise we might see seldom the effect of decreasing new memory values
+ // e.g. because the system could free up memory
+ byte[][] bytes = new byte[32][];
+ for (int i = 0; i < 32; i++) {
+ bytes[i] = new byte[8*1024*1024];
+ newMemoryUsage = metrics.getMemoryUsage();
+ if (newMemoryUsage > memoryUsage) {
+ break;
+ }
+ }
+ newMemoryMaxUsage = metrics.getMemoryMaxUsage();
- if(newMemoryMaxUsage < memoryMaxUsage) {
- fail(SubSystem.MEMORY, "getMemoryMaxUsage", newMemoryMaxUsage,
- memoryMaxUsage);
+ if (newMemoryMaxUsage < memoryMaxUsage) {
+ fail(SubSystem.MEMORY, "getMemoryMaxUsage", memoryMaxUsage,
+ newMemoryMaxUsage);
}
- if(newMemoryUsage < memoryUsage) {
- fail(SubSystem.MEMORY, "getMemoryUsage", newMemoryUsage, memoryUsage);
+ if (newMemoryUsage < memoryUsage) {
+ fail(SubSystem.MEMORY, "getMemoryUsage", memoryUsage, newMemoryUsage);
}
}