FrankChen021 commented on code in PR #20549:
URL: https://github.com/apache/druid/pull/20549#discussion_r4237632566
##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/IngestionSmokeTest.java:
##########
@@ -429,22 +429,27 @@ public void test_streamLogs_ofCancelledTask() throws
Exception
.hasDimension(DruidMetrics.TASK_STATUS, "FAILED")
);
- final Optional<InputStream> streamOptional =
- cluster.callApi().waitForResult(
- () -> overlord.bindings()
- .getInstance(TaskLogStreamer.class)
- .streamTaskLog(taskId, 0),
- Optional::isPresent
- ).go();
-
- Assertions.assertTrue(streamOptional.isPresent());
-
- final String logs = IOUtils.toString(streamOptional.get(),
StandardCharsets.UTF_8);
-
final String expectedLogLine = StringUtils.format(
"Running task[%s] for [%d] millis",
taskId, runDurationMillis
);
+
+ // The Indexer serves this task's log over HTTP straight from its own
process log file
+ // (see HttpRemoteTaskRunner#streamTaskLog), so the stream can become
present before the
+ // expected line has actually been written to that file. Poll until the
expected line shows
+ // up, rather than just until the stream is present, to avoid racing
against that lag.
+ final String logs = cluster.callApi().waitForResult(
+ () -> {
+ final Optional<InputStream> streamOptional = overlord.bindings()
+
.getInstance(TaskLogStreamer.class)
+
.streamTaskLog(taskId, 0);
+ return streamOptional.isPresent()
+ ? IOUtils.toString(streamOptional.get(),
StandardCharsets.UTF_8)
Review Comment:
[P2] Close task-log streams during polling
**Finding:** The new retry loop obtains a fresh InputStream on every attempt
but never closes it. When the expected line is delayed, file-backed task-log
providers can leave multiple RandomAccessFile descriptors open, potentially
making repeated or parallel embedded test runs flaky.
**Suggestion:** Close every present InputStream with try-with-resources
after converting it to text, including attempts that do not satisfy the matcher.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]