[CI] Wait for the flush in testBatchSizeFromConfig instead of sleeping 4 s - #42
Merged
Merged
Conversation
…g 4 s The 200th line starts the flush on another thread and the request goes to the real ingesting endpoint. The test slept a fixed 4 s and then required exactly one API call and a 202 response, so it failed whenever the request took longer (a bare AssertionError from isOk()) or had failed and been retried by the appender by then (expected:<1> but was:<2>) - six times since 2026-09-08, hidden by the retry wrapper in the Java Build workflow. Wait for the flush with LogtailAppenderDecorator.awaitFlushCompletion() instead, and count the calls the endpoint accepted rather than all calls, so the test still checks that the batch went out in exactly one request while the appender's retries do their job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LogtailAppenderBatchConfigSizeTest.testBatchSizeFromConfiglogs 200 lines so that the batch size fromlogback-batch-test.xmlmakes the appender send the batch on another thread, to the real ingesting endpoint. It then slept a fixed 4 s and required exactly one API call and a 202 response by then.Why it flakes
It failed six attempts in the last 54 Java Build runs (since 2026-07-17), each time passing on a later attempt thanks to the
nick-fields/retrywrapper:testBatchSizeFromConfig:66->isOk:76, bareAssertionErrormaintestBatchSizeFromConfig:64 expected:<1> but was:<2>, onceisOk:76Connection reset/Remote host terminated the handshake, thenRetrying to send 200 logs to Better Stack (1 / 5)So it fails both when a request takes longer than the sleep and when the appender has to retry a failed request, which is the appender doing its job. Apart from 60 s build timeouts, the only other test that failed an attempt and passed on a retry in those runs is
testConnectTimeout(3 jobs), which #36 reworks.Change
Thread.sleep(4000)withLogtailAppenderDecorator.awaitFlushCompletion(). It takes and releases the appender'sflushLock, so it returns once the flush started by the 200th line is done, retries included.acceptedCalls, new in the decorator) instead ofapiCalls == 1. The test still checks that the batch size from the XML sends the batch in one request, but no longer fails when a first attempt was reset and retried. The assertions that nothing is sent before the 200th line keep usingapiCalls.LogtailAppenderShutdownTestandLogtailAppenderIntegrationTestdon't have this pattern, so they're unchanged: the 2 s sleep in the shutdown test is the window in which nothing may be sent (5 lines, batch size 10, 3 s interval), and the integration test already callsawaitFlushCompletion()beforeisOk().Verification
The test needs a real source token, which I don't have locally, so the run against the real endpoint is this PR's CI: run 36562884171 is green on Java 8, 11, 17 and 20. There
testBatchSizeFromConfigtook 3.4 s (11), 3.1 s (17), 2.2 s (20) and 2.8 s / 1.8 s (8), so the flush alone usually takes 2-3.5 s and the old 4 s sleep left as little as 0.6 s of headroom. Build (8) needed a second attempt because oftestConnectTimeout:150, the flake #36 reworks;testBatchSizeFromConfigpassed in both of its attempts.Locally I pointed
BETTER_STACK_INGESTING_HOSTat an HTTPS stand-in:origin/mainisOk:76, bareAssertionError, 4.1 s:64 expected:<1> but was:<2>, 4.1 sThe whole suite against the stand-in passes except
testConnectTimeoutandtestReadTimeout, which expect 1 ms timeouts that a localhost connection doesn't produce.Notes
awaitFlushCompletion()still gives the flush thread 10 ms to take the lock before waiting on it.testBatchDefaultBatchSizerelies on the same timing (it assertsapiCalls == 110 ms after the 1000th line) and didn't fail once in those 54 runs, so I left the helper as it is.isOk()still fails, with the error printed.LogtailAppenderBatchConfigSizeTestandLogtailAppenderDecorator, neither of which the open PRs T-1365 Keep the appender running while the JVM shuts down #34-Explain the ingesting host placeholder in the examples #41 change.🤖 Generated with Claude Code