Skip to content

[ML] Avoid 5s wait in AbstractNativeProcessTests #74916

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

Merged
merged 2 commits into from
Jul 5, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,23 @@ public void terminateExecutorService() {
public void testStart_DoNotDetectCrashWhenNoInputPipeProvided() throws Exception {
when(processPipes.getProcessInStream()).thenReturn(Optional.empty());
try (AbstractNativeProcess process = new TestNativeProcess()) {
process.start(executorService);
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
// Not detecting a crash is confirmed in terminateExecutorService()
try {
process.start(executorService);
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
// Not detecting a crash is confirmed in terminateExecutorService()
}
}
}

public void testStart_DoNotDetectCrashWhenProcessIsBeingClosed() throws Exception {
try (AbstractNativeProcess process = new TestNativeProcess()) {
process.start(executorService);
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
// Not detecting a crash is confirmed in terminateExecutorService()
try {
process.start(executorService);
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
// Not detecting a crash is confirmed in terminateExecutorService()
}
}
}

Expand Down Expand Up @@ -142,65 +146,74 @@ public void testCrashReporting() throws Exception {

public void testWriteRecord() throws Exception {
try (AbstractNativeProcess process = new TestNativeProcess()) {
process.start(executorService);
process.writeRecord(new String[] {"a", "b", "c"});
process.flushStream();

verify(inputStream).write(any(), anyInt(), anyInt());

} finally {
mockNativeProcessLoggingStreamEnds.countDown();
try {
process.start(executorService);
process.writeRecord(new String[]{"a", "b", "c"});
process.flushStream();
verify(inputStream).write(any(), anyInt(), anyInt());
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
}
}
}

public void testWriteRecord_FailWhenNoInputPipeProvided() throws Exception {
when(processPipes.getProcessInStream()).thenReturn(Optional.empty());
try (AbstractNativeProcess process = new TestNativeProcess()) {
process.start(executorService);
expectThrows(NullPointerException.class, () -> process.writeRecord(new String[] {"a", "b", "c"}));
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
try {
process.start(executorService);
expectThrows(NullPointerException.class, () -> process.writeRecord(new String[]{"a", "b", "c"}));
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
}
}
}

public void testFlush() throws Exception {
try (AbstractNativeProcess process = new TestNativeProcess()) {
process.start(executorService);
process.flushStream();

verify(inputStream).flush();
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
try {
process.start(executorService);
process.flushStream();
verify(inputStream).flush();
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
}
}
}

public void testFlush_FailWhenNoInputPipeProvided() throws Exception {
when(processPipes.getProcessInStream()).thenReturn(Optional.empty());
try (AbstractNativeProcess process = new TestNativeProcess()) {
process.start(executorService);
expectThrows(NullPointerException.class, process::flushStream);
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
try {
process.start(executorService);
expectThrows(NullPointerException.class, process::flushStream);
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
}
}
}

public void testIsReady() throws Exception {
try (AbstractNativeProcess process = new TestNativeProcess()) {
process.start(executorService);
assertThat(process.isReady(), is(false));
process.setReady();
assertThat(process.isReady(), is(true));
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
try {
process.start(executorService);
assertThat(process.isReady(), is(false));
process.setReady();
assertThat(process.isReady(), is(true));
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
}
}
}

public void testConsumeAndCloseOutputStream_GivenNoOutputStream() throws Exception {
when(processPipes.getProcessOutStream()).thenReturn(Optional.empty());
try (AbstractNativeProcess process = new TestNativeProcess()) {
process.consumeAndCloseOutputStream();
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
try {
process.consumeAndCloseOutputStream();
} finally {
mockNativeProcessLoggingStreamEnds.countDown();
}
}
}

Expand Down