Skip to content

Conversation

@yanivagman
Copy link
Collaborator

The Close() methods for jsonEventPrinter, templateEventPrinter, and tableEventPrinter were empty stubs that never closed the underlying io.WriteCloser. This caused intermittent test failures when OS write buffers weren't flushed before process termination, resulting in lost events in the output files.

Now all printer types properly close their output files, ensuring buffers are flushed and all events are written to disk.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical bug where printer Close() methods were not closing their underlying output files, causing intermittent data loss when write buffers weren't flushed before process termination.

Key Changes:

  • Implemented proper file closing logic in Close() methods for three printer types (tableEventPrinter, templateEventPrinter, jsonEventPrinter)
  • Added nil checks and error logging when closing output files

@codecov
Copy link

codecov bot commented Oct 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@0b8ac82). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4998   +/-   ##
=======================================
  Coverage        ?   29.69%           
=======================================
  Files           ?      234           
  Lines           ?    26086           
  Branches        ?        0           
=======================================
  Hits            ?     7745           
  Misses          ?    17802           
  Partials        ?      539           
Flag Coverage Δ
unit 29.69% <100.00%> (?)
Files with missing lines Coverage Δ
pkg/cmd/printer/printer.go 19.60% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yanivagman yanivagman force-pushed the fix_intermittent_test_failures branch from f58226f to 75d2681 Compare October 26, 2025 17:19
Printer Close() methods now call Sync() to flush OS buffers before
process exit. This fixes intermittent test failures where buffered
events weren't written to disk during graceful shutdown.
@yanivagman yanivagman force-pushed the fix_intermittent_test_failures branch from 75d2681 to dbe2a1c Compare October 28, 2025 15:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

assert.Contains(t, output, `1234567890`, "timestamp should be included")
}

// TestPrinterCloseFlusheData tests that Close() calls Sync() to flush buffered data to disk
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'FlushesData' in function name (typo in comment: 'FlusheData').

Suggested change
// TestPrinterCloseFlusheData tests that Close() calls Sync() to flush buffered data to disk
// TestPrinterCloseFlushesData tests that Close() calls Sync() to flush buffered data to disk

Copilot uses AI. Check for mistakes.

func (p tableEventPrinter) Close() {
// Sync flushes buffered data, ensuring events aren't lost on process exit
if f, ok := p.out.(*os.File); ok && f != nil {
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nil check f != nil is redundant after a successful type assertion. If the type assertion succeeds, f cannot be nil. Consider simplifying to if f, ok := p.out.(*os.File); ok {.

Suggested change
if f, ok := p.out.(*os.File); ok && f != nil {
if f, ok := p.out.(*os.File); ok {

Copilot uses AI. Check for mistakes.

func (p templateEventPrinter) Close() {
// Sync flushes buffered data, ensuring events aren't lost on process exit
if f, ok := p.out.(*os.File); ok && f != nil {
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nil check f != nil is redundant after a successful type assertion. If the type assertion succeeds, f cannot be nil. Consider simplifying to if f, ok := p.out.(*os.File); ok {.

Suggested change
if f, ok := p.out.(*os.File); ok && f != nil {
if f, ok := p.out.(*os.File); ok {

Copilot uses AI. Check for mistakes.

func (p jsonEventPrinter) Close() {
// Sync flushes buffered data, ensuring events aren't lost on process exit
if f, ok := p.out.(*os.File); ok && f != nil {
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nil check f != nil is redundant after a successful type assertion. If the type assertion succeeds, f cannot be nil. Consider simplifying to if f, ok := p.out.(*os.File); ok {.

Suggested change
if f, ok := p.out.(*os.File); ok && f != nil {
if f, ok := p.out.(*os.File); ok {

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@josedonizetti josedonizetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Feel free to merge after fixing the suggestion from copilot. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants