Fix flaky t.TempDir cleanup race in webhook tests (closes #198)
Check / check (pull_request) Skipped
Check / check (pull_request) Skipped
HandleWebhook starts a deployment in a detached goroutine that keeps writing under the app data dir (the test's t.TempDir). The webhook tests slept 100ms and returned, racing Go's automatic TempDir cleanup and intermittently failing with "RemoveAll: directory not empty". Track those goroutines in a sync.WaitGroup on the webhook Service and expose WaitForDeployments; the tests now wait on it instead of sleeping. Deploy joins its own sub-goroutines before returning, so the wait covers every temp-dir write. Production behavior is unchanged apart from making completion observable. Model: opus-4-8
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -828,8 +827,9 @@ func TestExtractBranch(testingT *testing.T) {
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Allow async deployment goroutine to complete before test cleanup
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
// Wait for the async deployment goroutine to finish so its
|
||||
// writes under the temp dir complete before test cleanup.
|
||||
svc.WaitForDeployments()
|
||||
|
||||
events, err := app.GetWebhookEvents(context.Background(), 10)
|
||||
require.NoError(t, err)
|
||||
@@ -867,8 +867,9 @@ func TestHandleWebhookMatchingBranch(t *testing.T) {
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Allow async deployment goroutine to complete before test cleanup
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
// Wait for the async deployment goroutine to finish so its writes
|
||||
// under the temp dir complete before test cleanup.
|
||||
svc.WaitForDeployments()
|
||||
|
||||
events, err := app.GetWebhookEvents(context.Background(), 10)
|
||||
require.NoError(t, err)
|
||||
@@ -962,8 +963,9 @@ func assertHandleWebhookDeploys(
|
||||
err := svc.HandleWebhook(context.Background(), app, source, pushEventType, payload)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Allow async deployment goroutine to complete before test cleanup
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
// Wait for the async deployment goroutine to finish so its writes
|
||||
// under the temp dir complete before test cleanup.
|
||||
svc.WaitForDeployments()
|
||||
|
||||
events, err := app.GetWebhookEvents(context.Background(), 10)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user