You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "rjuare8 (via GitHub)" <gi...@apache.org> on 2025/10/03 04:44:40 UTC
[PR] fixed undeterministic RollingAppenderDirectCronTest [logging-log4j2]
rjuare8 opened a new pull request, #3946:
URL: https://github.com/apache/logging-log4j2/pull/3946
**Stabilize `RollingAppenderDirectCronTest` by waiting for rolled file content and relaxing rollover timeout**
Addresses #3046.
> [!IMPORTANT]
> Base your changes on `2.x` branch if you are targeting Log4j 2; use `main` otherwise.
This PR hardens `RollingAppenderDirectCronTest` against timing races observed with cron-based rollovers. In practice, `rolloverComplete(...)` can fire before the first write to the newly rolled file has reached disk, causing the test to intermittently assert on an empty file. Under scheduler jitter, the test could also time out while waiting for a rollover.
### What changed (test-only)
- In `rolloverComplete(...)`, wait briefly until the rolled file exists **and** has non-zero length before asserting its contents:
```java
waitAtMost(2, TimeUnit.SECONDS).until(() -> Files.exists(path) && Files.size(path) > 0);
**Why**
- With CronTriggeringPolicy, the rollover completion callback may run before any event for the new time window is flushed to disk. The test previously asserted isNotEmpty() immediately and could race with IO, leading to flakiness (see #3046).
## Checklist
Before we can review and merge your changes, please go through the checklist below. If you're still working on some items, feel free to submit your pull request as a draft—our CI will help guide you through the remaining steps.
### ✅ Required checks
- ✅ **License**: I confirm that my changes are submitted under the [Apache License, Version 2.0](https://apache.org/licenses/LICENSE-2.0).
- ✅ **Commit signatures**: All commits are signed and verifiable. (See [GitHub Docs on Commit Signature Verification](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)).
- ✅ **Code formatting**: The code is formatted according to the project’s style guide.
<details>
<summary>How to check and fix formatting</summary>
- To **check** formatting: `./mvnw spotless:check`
- To **fix** formatting: `./mvnw spotless:apply`
See [the build instructions](https://logging.apache.org/log4j/2.x/development.html#building) for details.
</details>
- ✅ **Build & Test**: I verified that the project builds and all unit tests pass.
<details>
<summary>How to build the project</summary>
Run: `./mvnw verify`
See [the build instructions](https://logging.apache.org/log4j/2.x/development.html#building) for details.
</details>
### 🧪 Tests (select one)
- [ ] I have added or updated tests to cover my changes.
- ✅ No additional tests are needed for this change.
### 📝 Changelog (select one)
- [ ] I added a changelog entry in `src/changelog/.2.x.x`. (See [Changelog Entry File Guide](https://logging.apache.org/log4j/tools/log4j-changelog.html#changelog-entry-file)).
- ✅ This is a trivial change and does not require a changelog entry.
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Stabilize `RollingAppenderDirectCronTest` [logging-log4j2]
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on code in PR #3946:
URL: https://github.com/apache/logging-log4j2/pull/3946#discussion_r2451222129
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java:
##########
@@ -102,16 +102,18 @@ public void rolloverComplete(final String fileName) {
final Path path = Paths.get(fileName);
final Matcher matcher = FILE_PATTERN.matcher(path.getFileName().toString());
assertThat(matcher).as("Rolled file").matches();
- try {
- final List<String> lines = Files.readAllLines(path);
- assertThat(lines).isNotEmpty();
- assertThat(lines.get(0)).startsWith(matcher.group(1));
- } catch (final IOException ex) {
- fail("Unable to read file " + fileName + ": " + ex.getMessage());
- }
+
+ // Wait until the file is non-empty (or timeout)
+ waitAtMost(2, TimeUnit.SECONDS).until(() -> Files.exists(path) && Files.size(path) > 0);
+
+ final List<String> lines = Files.readAllLines(path);
+ assertThat(lines).isNotEmpty();
+ assertThat(lines.get(0)).startsWith(matcher.group(1));
Review Comment:
After waiting for 2 weeks, implemented myself in 6fbd257b8.
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Stabilize `RollingAppenderDirectCronTest` [logging-log4j2]
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on code in PR #3946:
URL: https://github.com/apache/logging-log4j2/pull/3946#discussion_r2440047760
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java:
##########
Review Comment:
Does this serve any purpose related with the `RollingAppenderDirectCronTest` fix? If not, please revert this incidental change.
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java:
##########
@@ -102,16 +102,18 @@ public void rolloverComplete(final String fileName) {
final Path path = Paths.get(fileName);
final Matcher matcher = FILE_PATTERN.matcher(path.getFileName().toString());
assertThat(matcher).as("Rolled file").matches();
- try {
- final List<String> lines = Files.readAllLines(path);
- assertThat(lines).isNotEmpty();
- assertThat(lines.get(0)).startsWith(matcher.group(1));
- } catch (final IOException ex) {
- fail("Unable to read file " + fileName + ": " + ex.getMessage());
- }
+
+ // Wait until the file is non-empty (or timeout)
+ waitAtMost(2, TimeUnit.SECONDS).until(() -> Files.exists(path) && Files.size(path) > 0);
+
+ final List<String> lines = Files.readAllLines(path);
+ assertThat(lines).isNotEmpty();
+ assertThat(lines.get(0)).startsWith(matcher.group(1));
Review Comment:
Could you instead move the assertion block inside a `waitAtMost(Duration.ofSeconds(5)).untilAsserted(...)`, please?
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fixed undeterministic RollingAppenderDirectCronTest [logging-log4j2]
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on PR #3946:
URL: https://github.com/apache/logging-log4j2/pull/3946#issuecomment-3415652510
@rjuare8, **all your commits** must be signed, and they are not. See the [Commits](https://github.com/apache/logging-log4j2/pull/3946/commits) tab and `Unverified` labels there.
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Stabilize `RollingAppenderDirectCronTest` [logging-log4j2]
Posted by "rjuare8 (via GitHub)" <gi...@apache.org>.
rjuare8 commented on PR #3946:
URL: https://github.com/apache/logging-log4j2/pull/3946#issuecomment-3429569835
Signed all my commits! Let me know if there is additional actions I need to take.
Related to my fix for `testFlushAtEndOfBatch()`. This change hardens `XmlCompleteFileAppenderTest#testFlushAtEndOfBatch` against formatting/timing variance where a blank line after the `<Events>` root element is not guaranteed. The prior test unconditionally consumed one line after `<Events>`, assuming it was always blank; when the blank line was absent, the `<Event …> `line was skipped and later assertions occasionally saw `line3 == null`.
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fixed undeterministic RollingAppenderDirectCronTest [logging-log4j2]
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on PR #3946:
URL: https://github.com/apache/logging-log4j2/pull/3946#issuecomment-3388725635
@rjuare8, thanks for the contribution. Would you mind performing the following tasks, please?
1. [Sign your commits](https://chatgpt.com/share/689f0f3a-22b8-8002-90d7-6b7c1d702ffa)
2. Run `./mvnw spotless:apply -pl :log4j-core-test`
3. Ensure `./mvnw verify -pl :log4j-core-test` passes
4. Read [the Log4j Development Guide](https://github.com/apache/logging-log4j2/blob/2.x/BUILDING.adoc#development)
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Stabilize `RollingAppenderDirectCronTest` [logging-log4j2]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3946:
URL: https://github.com/apache/logging-log4j2/pull/3946#issuecomment-3431498711
<table>
<tr>
<th>Job</th>
<th>Requested goals</th>
<th>Build Tool Version</th>
<th>Build Outcome</th>
<th>Build Scan®</th>
</tr>
<tr>
<td>build-macos-latest</td>
<td>clean install</td>
<td align='center'>3.9.8</td>
<td align='center'>:x:</td>
<td><a href="https://develocity.apache.org/s/acr2aaaqwyvjq" rel="nofollow"><img src="https://img.shields.io/badge/Build%20Scan%C2%AE-PUBLISHED-06A0CE?logo=Gradle" alt="Build Scan PUBLISHED" /></a></td>
</tr>
<tr>
<td>build-ubuntu-latest</td>
<td>clean install</td>
<td align='center'>3.9.8</td>
<td align='center'>:x:</td>
<td><a href="https://develocity.apache.org/s/dy2f3coxg5i6w" rel="nofollow"><img src="https://img.shields.io/badge/Build%20Scan%C2%AE-PUBLISHED-06A0CE?logo=Gradle" alt="Build Scan PUBLISHED" /></a></td>
</tr>
<tr>
<td>build-windows-latest</td>
<td>clean install</td>
<td align='center'>3.9.8</td>
<td align='center'>:x:</td>
<td><a href="https://develocity.apache.org/s/ny4ufd7vkotsu" rel="nofollow"><img src="https://img.shields.io/badge/Build%20Scan%C2%AE-PUBLISHED-06A0CE?logo=Gradle" alt="Build Scan PUBLISHED" /></a></td>
</tr>
</table>
###### Generated by gradle/develocity-actions
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Stabilize `RollingAppenderDirectCronTest` and `XmlCompleteFileAppenderTest` [logging-log4j2]
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy merged PR #3946:
URL: https://github.com/apache/logging-log4j2/pull/3946
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Stabilize `RollingAppenderDirectCronTest` [logging-log4j2]
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on PR #3946:
URL: https://github.com/apache/logging-log4j2/pull/3946#issuecomment-3431386501
> Signed all my commits! Let me know if there is additional actions I need to take.
Yes, there ~are~ were: https://github.com/apache/logging-log4j2/pull/3946#discussion_r2418816253 Since it was 2 weeks ago, I have decided to address it myself in 6fbd257b8. While I really appreciate your contribution, I'd very glad if you can read and address all review remarks next time.
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Stabilize `RollingAppenderDirectCronTest` [logging-log4j2]
Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on code in PR #3946:
URL: https://github.com/apache/logging-log4j2/pull/3946#discussion_r2451216687
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java:
##########
Review Comment:
Explained in another thread: https://github.com/apache/logging-log4j2/pull/3946#issuecomment-3429569835
--
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: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org