Copilot commented on code in PR #4631:
URL: https://github.com/apache/flink-cdc/pull/4631#discussion_r4661678787
##########
flink-cdc-e2e-tests/flink-cdc-pipeline-e2e-tests/src/test/java/org/apache/flink/cdc/pipeline/tests/utils/PipelineTestEnvironment.java:
##########
@@ -644,21 +635,91 @@ protected void waitUntilLogContains(ToStringConsumer
consumer, String fragment)
protected void waitUntilLogContains(
ToStringConsumer consumer, String fragment, Duration timeout)
throws Exception {
- boolean result = false;
- long endTimeout = System.currentTimeMillis() + timeout.toMillis();
- while (System.currentTimeMillis() < endTimeout) {
- if (consumer.toUtf8String().contains(fragment)) {
- result = true;
- break;
+ waitUntilOutput(
+ consumer,
+ stdout -> stdout.contains(fragment),
+ "failed to get log fragment: " + fragment,
+ timeout);
+ }
+
+ /**
+ * Waits until the consumer's output satisfies the condition. A wait on
the JobManager or
+ * TaskManager output gives up once every job of the cluster has ended, as
no more output will
+ * come, and reports how the jobs ended, which the TaskManager output does
not show.
+ */
+ private void waitUntilOutput(
+ ToStringConsumer consumer,
+ Predicate<String> condition,
+ String failureMessage,
+ Duration timeout)
+ throws Exception {
+ boolean flinkOutput = consumer == taskManagerConsumer || consumer ==
jobManagerConsumer;
+ long deadline = System.currentTimeMillis() + timeout.toMillis();
+ long allJobsEndedAt = -1;
+ while (!condition.test(consumer.toUtf8String())) {
+ long now = System.currentTimeMillis();
+ if (now >= deadline) {
+ throw new TimeoutException(
+ failureMessage + " from stdout: " +
consumer.toUtf8String());
+ }
+ List<JobStatusMessage> endedJobs =
+ flinkOutput ? jobsIfAllEnded() : Collections.emptyList();
+ if (endedJobs.isEmpty()) {
+ allJobsEndedAt = -1;
+ } else if (allJobsEndedAt < 0) {
+ allJobsEndedAt = now;
Review Comment:
`now` was sampled before the potentially 10-second `listJobs()` request, so
assigning it here counts request time toward the output grace period, including
time when the job may still have been running. For example, if the job ends
just before a 9.5-second response arrives, the next poll at 10.5 seconds can
give up after only about one second of post-job grace. Record the timestamp
when terminal jobs are actually observed so output receives the full 10-second
grace period.
##########
flink-cdc-e2e-tests/flink-cdc-pipeline-e2e-tests/src/test/java/org/apache/flink/cdc/pipeline/tests/utils/PipelineTestEnvironment.java:
##########
@@ -644,21 +635,91 @@ protected void waitUntilLogContains(ToStringConsumer
consumer, String fragment)
protected void waitUntilLogContains(
ToStringConsumer consumer, String fragment, Duration timeout)
throws Exception {
- boolean result = false;
- long endTimeout = System.currentTimeMillis() + timeout.toMillis();
- while (System.currentTimeMillis() < endTimeout) {
- if (consumer.toUtf8String().contains(fragment)) {
- result = true;
- break;
+ waitUntilOutput(
+ consumer,
+ stdout -> stdout.contains(fragment),
+ "failed to get log fragment: " + fragment,
+ timeout);
+ }
+
+ /**
+ * Waits until the consumer's output satisfies the condition. A wait on
the JobManager or
+ * TaskManager output gives up once every job of the cluster has ended, as
no more output will
+ * come, and reports how the jobs ended, which the TaskManager output does
not show.
+ */
+ private void waitUntilOutput(
+ ToStringConsumer consumer,
+ Predicate<String> condition,
+ String failureMessage,
+ Duration timeout)
+ throws Exception {
+ boolean flinkOutput = consumer == taskManagerConsumer || consumer ==
jobManagerConsumer;
+ long deadline = System.currentTimeMillis() + timeout.toMillis();
+ long allJobsEndedAt = -1;
+ while (!condition.test(consumer.toUtf8String())) {
+ long now = System.currentTimeMillis();
+ if (now >= deadline) {
+ throw new TimeoutException(
+ failureMessage + " from stdout: " +
consumer.toUtf8String());
+ }
+ List<JobStatusMessage> endedJobs =
+ flinkOutput ? jobsIfAllEnded() : Collections.emptyList();
+ if (endedJobs.isEmpty()) {
+ allJobsEndedAt = -1;
+ } else if (allJobsEndedAt < 0) {
+ allJobsEndedAt = now;
+ } else if (now - allJobsEndedAt >=
ENDED_JOBS_OUTPUT_GRACE.toMillis()) {
+ throw new TimeoutException(
+ failureMessage
+ + ", and every job has ended:"
+ + describeEndedJobs(endedJobs)
+ + "\nstdout: "
+ + consumer.toUtf8String());
Review Comment:
If the expected output arrives while `jobsIfAllEnded()` is waiting for its
REST response after the grace period expires, this branch still throws even
though the condition now matches. Fetching failure details adds another
blocking window. Recheck the predicate on a fresh output snapshot after
collecting the diagnostics and before throwing to avoid false e2e failures.
--
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]