Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky test ResourceAwareTasksTests on windows. #5077

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Backport failures for merge conflicts on CHANGELOG.md file ([#4977](https://github.com/opensearch-project/OpenSearch/pull/4977))
- Remove gradle-check dependency on precommit [#5027](https://github.com/opensearch-project/OpenSearch/pull/5027)
- Fix version check for 2.x release for awareness attribute decommission([#5034](https://github.com/opensearch-project/OpenSearch/pull/5034))
- Fix flaky test ResourceAwareTasksTests on Windows ([#5077](https://github.com/opensearch-project/OpenSearch/pull/5077))

### Security
- CVE-2022-25857 org.yaml:snakeyaml DOS vulnerability ([#4341](https://github.com/opensearch-project/OpenSearch/pull/4341))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.action.admin.cluster.node.tasks;

import com.sun.management.ThreadMXBean;
import org.apache.lucene.util.Constants;
import org.opensearch.ExceptionsHelper;
import org.opensearch.action.ActionListener;
import org.opensearch.action.NotifyOnceListener;
Expand Down Expand Up @@ -303,7 +304,7 @@ public void testBasicTaskResourceTracking() throws Exception {
actualTaskMemoryOverhead - taskTestContext.memoryConsumptionWhenExecutionStarts,
expectedArrayAllocationOverhead
);
assertTrue(task.getTotalResourceStats().getCpuTimeInNanos() > 0);
assertCPUTime(task.getTotalResourceStats().getCpuTimeInNanos());
};

startResourceAwareNodesAction(testNodes[0], false, taskTestContext, new ActionListener<NodesResponse>() {
Expand Down Expand Up @@ -362,7 +363,7 @@ public void testTaskResourceTrackingDuringTaskCancellation() throws Exception {
actualTaskMemoryOverhead - taskTestContext.memoryConsumptionWhenExecutionStarts,
expectedOverhead
);
assertTrue(task.getTotalResourceStats().getCpuTimeInNanos() > 0);
assertCPUTime(task.getTotalResourceStats().getCpuTimeInNanos());
};

startResourceAwareNodesAction(testNodes[0], true, taskTestContext, new ActionListener<NodesResponse>() {
Expand Down Expand Up @@ -463,7 +464,7 @@ public void testTaskResourceTrackingDisabledWhileTaskInProgress() throws Excepti
actualTaskMemoryOverhead - taskTestContext.memoryConsumptionWhenExecutionStarts,
expectedArrayAllocationOverhead
);
assertTrue(task.getTotalResourceStats().getCpuTimeInNanos() > 0);
assertCPUTime(task.getTotalResourceStats().getCpuTimeInNanos());
};

startResourceAwareNodesAction(testNodes[0], false, taskTestContext, new ActionListener<NodesResponse>() {
Expand Down Expand Up @@ -543,7 +544,7 @@ public void testOnDemandRefreshWhileFetchingTasks() throws InterruptedException

assertNotNull(taskInfo.getResourceStats());
assertNotNull(taskInfo.getResourceStats().getResourceUsageInfo());
assertTrue(taskInfo.getResourceStats().getResourceUsageInfo().get("total").getCpuTimeInNanos() > 0);
assertCPUTime(taskInfo.getResourceStats().getResourceUsageInfo().get("total").getCpuTimeInNanos());
assertTrue(taskInfo.getResourceStats().getResourceUsageInfo().get("total").getMemoryInBytes() > 0);
};

Expand Down Expand Up @@ -655,4 +656,15 @@ private void assertMemoryUsageWithinLimits(long actual, long expected) {
long maxOverhead = Math.min(200000, expected * 5 / 100);
assertThat(actual, lessThanOrEqualTo(expected + maxOverhead));
}

private void assertCPUTime(long cpuTimeInNanos) {
// Windows registers a cpu tick at a default of ~15ms which is slightly slower than other OSs.
// The work done within the runnable in this test often completes in under that time and returns a 0 value from
// ThreadMXBean.getThreadCpuTime. To reduce flakiness in this test accept 0 as a value on Windows.
if (Constants.WINDOWS) {
assertTrue("Cpu should be non negative on windows", cpuTimeInNanos >= 0);
} else {
assertTrue("Cpu should have a positive value", cpuTimeInNanos > 0);
}
}
}