Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ jobs:
# Needed for some checks.
fetch-depth: 0

- name: Clean up runner space
uses: ./.github/actions/cleanup-space
# Uncomment this step if you want to enable cleanup of runner space.
#- name: Clean up runner space
# uses: ./.github/actions/cleanup-space

- name: Setup Go ${{ env.GO_VERSION }}
uses: ./.github/actions/setup-go
Expand Down Expand Up @@ -190,3 +191,28 @@ jobs:
flag-name: 'unit'
format: 'golang'
parallel: true

- name: Fix artifact permissions
if: always()
run: |
# Fix permissions for test artifacts (created in package directories)
find . -type d -name "test-artifacts" -exec sudo chown -R "$(id -u):$(id -g)" {} + || true
find . -type d -name "test-artifacts" -exec sudo chmod -R a+r {} + || true

- name: Set artifact name
if: failure()
id: artifact-name
run: |
# Sanitize matrix.unit_type for use in artifact name
SAFE_NAME=$(echo "${{ matrix.unit_type }}" | sed 's/[^a-zA-Z0-9_-]/_/g')
echo "name=test-artifacts-${SAFE_NAME}-${{ github.run_id }}" >> $GITHUB_OUTPUT

- name: Upload test artifacts on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifact-name.outputs.name }}
path: |
**/test-artifacts/
retention-days: 5
if-no-files-found: ignore
30 changes: 26 additions & 4 deletions harness/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (

// networkPrefix is the prefix for private Docker networks created
// for each harness instance to ensure isolation between test runs.
networkPrefix = "ark-itest-"
networkPrefix = "ark-harness-"

// bitcoindRPCUser is the RPC username for bitcoind in regtest mode.
bitcoindRPCUser = "admin1"
Expand Down Expand Up @@ -440,14 +440,31 @@ func (h *Harness) setupDockerEnvironment() {
h.pool, err = dockertest.NewPool("")
require.NoError(h.T, err, "failed to init docker pool")

h.pruneStaleHarnessNetworks()
// Note: We used to call pruneStaleHarnessNetworks() here to clean up
// networks from previous failed runs, but it caused race conditions
// with parallel tests. Each harness now only cleans up its own
// network during shutdown. Stale networks from truly failed runs can
// be cleaned up with: docker network prune
//
// If automatic cleanup is needed, it should run with a large grace
// period (5+ minutes) to avoid interfering with active tests.

// Per-run isolation.
h.Log("Creating docker network...")
h.network, err = h.createNetworkUnique()
require.NoError(h.T, err, "failed to create network")
h.Logf("Docker network created: %s (id=%s)", h.network.Network.Name,
h.network.Network.ID)

// Verify network is actually accessible before proceeding. This helps
// catch race conditions where Docker reports success but the network
// isn't fully ready yet.
require.NoError(h.T, h.pool.Retry(func() error {
_, err := h.pool.Client.NetworkInfo(h.network.Network.ID)
return err
}), "failed to verify network exists")

h.Log("Docker network verified")
}

// createDataDirectories creates the necessary data directories for bitcoind,
Expand Down Expand Up @@ -679,8 +696,13 @@ func (h *Harness) createNetworkUnique() (*dockertest.Network, error) {
return nil, lastErr
}

func (h *Harness) pruneStaleHarnessNetworks() {
// Best-effort, ignore errors.
// PruneStaleHarnessNetworks performs best-effort cleanup of stale harness
// Docker networks that are empty.
//
// NOTE: This function is no longer called automatically during tests to avoid
// race conditions. It's kept here for manual cleanup if needed.
func (h *Harness) PruneStaleHarnessNetworks() {
// Best-effort cleanup of empty harness networks.
nets, err := h.pool.Client.ListNetworks()
if err != nil {
h.Logf("[DEBUG] Failed to list networks for pruning: %v", err)
Expand Down
Loading