tests: runtime: wait for tail truncate output#11810
Conversation
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
📝 WalkthroughWalkthroughThis PR adds a new test polling utility ChangesTest utility enhancement for truncation test reliability
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/runtime/in_tail.c (1)
343-370: ⚡ Quick winConsider consolidating the wait helper functions.
There are now three nearly identical wait functions (
wait_with_timeout,wait_num_with_timeout, andwait_expected_num_with_timeout) that differ only in their exit conditions. The shared timeout polling logic could be extracted into a common helper or parameterized to reduce duplication.♻️ Example consolidation approach
One approach is to add a callback parameter for the exit condition:
typedef int (*wait_condition_fn)(void *data); void wait_with_timeout_generic(uint32_t timeout_ms, wait_condition_fn should_stop, void *data) { struct flb_time start_time; struct flb_time end_time; struct flb_time diff_time; uint64_t elapsed_time_flb = 0; flb_time_get(&start_time); while (true) { if (should_stop(data)) { break; } flb_time_msleep(100); flb_time_get(&end_time); flb_time_diff(&end_time, &start_time, &diff_time); elapsed_time_flb = flb_time_to_nanosec(&diff_time) / 1000000; if (elapsed_time_flb > timeout_ms) { flb_warn("[timeout] elapsed_time: %ld", elapsed_time_flb); break; } } }Then each specific wait function would become a thin wrapper that provides the appropriate condition callback.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/runtime/in_tail.c` around lines 343 - 370, The three near-duplicate functions wait_with_timeout, wait_num_with_timeout, and wait_expected_num_with_timeout repeat the same polling/timeout logic; extract that common logic into a single generic helper (e.g., wait_with_timeout_generic) that accepts a callback typedef (e.g., wait_condition_fn or similar) and a void* data pointer for the condition, then rewrite wait_with_timeout, wait_num_with_timeout, and wait_expected_num_with_timeout as thin wrappers that pass their specific stop-condition functions (and data) into the generic helper; ensure the generic helper preserves the existing timing, sleep, elapsed logging (flb_time_get/ flb_time_msleep/ flb_time_diff/ flb_time_to_nanosec and flb_warn) so behavior remains identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/runtime/in_tail.c`:
- Around line 343-370: The three near-duplicate functions wait_with_timeout,
wait_num_with_timeout, and wait_expected_num_with_timeout repeat the same
polling/timeout logic; extract that common logic into a single generic helper
(e.g., wait_with_timeout_generic) that accepts a callback typedef (e.g.,
wait_condition_fn or similar) and a void* data pointer for the condition, then
rewrite wait_with_timeout, wait_num_with_timeout, and
wait_expected_num_with_timeout as thin wrappers that pass their specific
stop-condition functions (and data) into the generic helper; ensure the generic
helper preserves the existing timing, sleep, elapsed logging (flb_time_get/
flb_time_msleep/ flb_time_diff/ flb_time_to_nanosec and flb_warn) so behavior
remains identical.
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.
Summary by CodeRabbit