fix(test): attempt to fix HTTP audit functional test flake and artifact log writer bug#3337
Conversation
📝 WalkthroughWalkthroughModified buffered log artifact flushing to close files immediately after writing and added framework initialization to one HTTP forwarder functional test entry. ChangesTest infrastructure fixes
Estimated code review effort: 2 (Simple) | ~10 minutes Related Issues: None specified. Related PRs: None specified. Suggested labels: test, bugfix Suggested reviewers: None specified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/framework/common/log/buffered_log_writer.go (1)
44-52: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueUnsynchronized mutation of
w.outalongside a mutex-protectedFlush().
w.outis reassigned directly at Lines 47 and 50, outsidew.mtx, whileFlush()(Lines 59-66) readsw.outunder lock. If any concurrent writer (e.g., another goroutine callingWrite/Flushon the same instance) races with this reassignment, it's an unsynchronized access to shared state thatgo test -racewould flag. Low practical risk given typical single-goroutine test-cleanup usage, but worth guarding for consistency with the rest of the type's locking discipline.🔒 Suggested fix: guard `w.out` mutation with the mutex
if file, err := os.Create(fullPath); err != nil { w.log.Error(err, fmt.Sprintf("Unable to flush logs to file: %s", fullPath)) } else { + w.mtx.Lock() w.out = file - w.Flush() + w.mtx.Unlock() + w.Flush() errors.LogIfError(file.Close()) + w.mtx.Lock() w.out = os.Stdout + w.mtx.Unlock() return }🤖 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 `@test/framework/common/log/buffered_log_writer.go` around lines 44 - 52, The `bufferedLogWriter` mutates shared state unsafely: `w.out` is reassigned in the `os.Create` success path while `Flush()` uses `w.mtx` to protect access, so update the `Write`/flush path to guard every `w.out` read and write with the same mutex. Use the `bufferedLogWriter` methods (`Write` and `Flush`) as the coordination point so the temporary switch to the file and the restoration back to `os.Stdout` happen under lock, matching the type’s existing locking discipline.
🤖 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 `@test/framework/common/log/buffered_log_writer.go`:
- Around line 44-52: The `bufferedLogWriter` mutates shared state unsafely:
`w.out` is reassigned in the `os.Create` success path while `Flush()` uses
`w.mtx` to protect access, so update the `Write`/flush path to guard every
`w.out` read and write with the same mutex. Use the `bufferedLogWriter` methods
(`Write` and `Flush`) as the coordination point so the temporary switch to the
file and the restoration back to `os.Stdout` happen under lock, matching the
type’s existing locking discipline.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 8def264e-926a-4059-9666-016d04fea379
📒 Files selected for processing (2)
test/framework/common/log/buffered_log_writer.gotest/functional/outputs/http/forward_to_http_test.go
…ct log writer bug
e5997d8 to
dc1a01f
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/framework/common/log/buffered_log_writer.go (1)
60-65: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider documenting the locking precondition on
flushLocked.The name implies the caller must hold
w.mtx, but there's no comment enforcing that contract for future maintainers who might add new call sites.📝 Suggested doc comment
+// flushLocked writes the buffer to w.out and resets it. +// Callers must hold w.mtx before invoking this method. func (w *BufferedLogWriter) flushLocked() { if _, err := w.out.Write(w.buffer); err != nil {🤖 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 `@test/framework/common/log/buffered_log_writer.go` around lines 60 - 65, Add a doc comment to BufferedLogWriter.flushLocked that clearly states it must only be called while w.mtx is already held. Keep the contract explicit for future call sites, and make sure the comment sits on the flushLocked method so the locking precondition is easy to find alongside write and flush behavior.
🤖 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 `@test/framework/common/log/buffered_log_writer.go`:
- Around line 60-65: Add a doc comment to BufferedLogWriter.flushLocked that
clearly states it must only be called while w.mtx is already held. Keep the
contract explicit for future call sites, and make sure the comment sits on the
flushLocked method so the locking precondition is easy to find alongside write
and flush behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 3c78c5a2-43f3-4e48-bc09-c9e098cf6d96
📒 Files selected for processing (2)
test/framework/common/log/buffered_log_writer.gotest/functional/outputs/http/forward_to_http_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- test/functional/outputs/http/forward_to_http_test.go
|
/lgtm |
|
/retest-required |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Clee2691, jcantrill The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest |
|
@Clee2691: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
6c2ec7a
into
openshift:master
Description
BufferedLogWriter.FlushToArtifactsDirthat silently prevented test failure artifact logs from being writtenNO-JIRA
/cc @vparfonov
/assign @jcantrill
Summary by CodeRabbit