fix(container): fix flaky test temp directory cleanup race
Use manual temp directory management with time.Sleep before cleanup to avoid race condition where state file writes race with t.TempDir's automatic cleanup. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
80fd39f2d8
commit
74c1b46f78
1 changed files with 11 additions and 1 deletions
|
|
@ -49,8 +49,18 @@ func (m *MockHypervisor) BuildCommand(ctx context.Context, image string, opts *H
|
|||
}
|
||||
|
||||
// newTestManager creates a LinuxKitManager with mock hypervisor for testing.
|
||||
// Uses manual temp directory management to avoid race conditions with t.TempDir cleanup.
|
||||
func newTestManager(t *testing.T) (*LinuxKitManager, *MockHypervisor, string) {
|
||||
tmpDir := t.TempDir()
|
||||
tmpDir, err := os.MkdirTemp("", "linuxkit-test-*")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Manual cleanup that handles race conditions with state file writes
|
||||
t.Cleanup(func() {
|
||||
// Give any pending file operations time to complete
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
_ = os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
statePath := filepath.Join(tmpDir, "containers.json")
|
||||
|
||||
state, err := LoadState(statePath)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue