Skip to content

Fix flaky TestStorageProviderUploadDownload integration test#22

Merged
jrepp merged 2 commits intomainfrom
fix/flaky-storage-integration-test-v2
Nov 9, 2025
Merged

Fix flaky TestStorageProviderUploadDownload integration test#22
jrepp merged 2 commits intomainfrom
fix/flaky-storage-integration-test-v2

Conversation

@jrepp
Copy link
Owner

@jrepp jrepp commented Nov 8, 2025

Summary

Fixes the flaky TestStorageProviderUploadDownload integration test by improving Docker Compose setup and adding an integrated stability testing capability.

Problem

The integration test was failing due to port conflicts when Docker containers from previous test runs hadn't fully cleaned up. Port 5556 (used by the dex service) was being held by gvproxy even after docker compose down, causing subsequent test runs to fail with "address already in use" errors.

Test Results Before Fix:

  • Intermittent failures due to port conflicts
  • No systematic way to verify test stability

Solution

1. Improved Docker Compose Setup (testing/integration_test.go)

  • Added retry logic (3 attempts) with exponential backoff
  • Implemented 2-second wait after cleanup for port release
  • Enhanced logging at each setup step

2. Refactored Storage Test with Stability Testing (testing/storage_integration_test.go)

  • Extracted test logic into reusable helper function
  • Added TestStorageProviderUploadDownloadStability for multi-iteration testing
  • Added 50ms stabilization wait after upload
  • Improved error messages with detailed data comparison
  • Made stability test opt-in via RUN_STABILITY_TESTS environment variable

Test Results After Fix

Regular Test:

go test -v -run TestStorageProviderUploadDownload
# PASS (44s)

Stability Test:

RUN_STABILITY_TESTS=1 STABILITY_TEST_ITERATIONS=3 \
  go test -v -run TestStorageProviderUploadDownloadStability
# PASS - 3/3 iterations successful (45s)

Benefits

  1. Improved Reliability: Retry logic handles transient port conflicts
  2. Better Debugging: Stability test helps identify race conditions
  3. Opt-in Testing: Stability test skipped by default to keep CI fast
  4. Configurable: Can adjust iteration count via environment variable

Usage

# Run regular tests
go test -v ./testing/...

# Enable stability testing with 10 iterations
RUN_STABILITY_TESTS=1 STABILITY_TEST_ITERATIONS=10 \
  go test -v -run TestStorageProviderUploadDownloadStability

jrepp added 2 commits November 8, 2025 14:17
Enhanced the Docker Compose setup for integration tests to handle
transient failures and port conflicts:

- Add retry logic (3 attempts) for starting services
- Implement exponential backoff between retries
- Add 2-second wait after cleanup for port release
- Improve logging at each setup step

This fixes flaky test failures caused by port conflicts when
containers from previous test runs haven't fully cleaned up.
Refactored TestStorageProviderUploadDownload to improve test
reliability and add stability testing capability:

- Extract test logic into reusable helper function
- Add TestStorageProviderUploadDownloadStability for multi-iteration testing
- Add 50ms stabilization wait after upload
- Improve error messages with detailed data comparison
- Make stability test opt-in via RUN_STABILITY_TESTS environment variable
- Support configurable iterations via STABILITY_TEST_ITERATIONS

The stability test helps identify race conditions and timing issues
by running the same test multiple times. It's skipped by default
but can be enabled for debugging flaky test behavior.

Usage:
  # Run regular test
  go test -v -run TestStorageProviderUploadDownload

  # Run stability test with 10 iterations
  RUN_STABILITY_TESTS=1 STABILITY_TEST_ITERATIONS=10 \
    go test -v -run TestStorageProviderUploadDownloadStability
@jrepp jrepp merged commit bd23b03 into main Nov 9, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant