Skip to content

Tests: Run Couchbase container on Docker-assigned ports#127

Merged
amotl merged 1 commit into
panodata:mainfrom
hampsterx:fix/couchbase-test-container-dynamic-ports
Jul 1, 2026
Merged

Tests: Run Couchbase container on Docker-assigned ports#127
amotl merged 1 commit into
panodata:mainfrom
hampsterx:fix/couchbase-test-container-dynamic-ports

Conversation

@hampsterx

Copy link
Copy Markdown
Contributor

What

The Couchbase test container binds host ports 1:1 (8091, 11210...), so test_couchbase_source_local clashes with any Couchbase Server already running on the workstation and can fail outright. The pending testcontainers-python Couchbase support binds the same ports 1:1, so adopting it as-is would not remove the conflict.

This switches the container to Docker-assigned host ports and advertises them to SDK clients via Couchbase alternate addresses, so the integration test runs alongside a local Couchbase instead of requiring you to stop it first.

Changes

  • CouchbaseContainer now uses with_exposed_ports(8091, 8092, 8093, 11210) instead of fixed 1:1 binds.
  • After bucket creation it configures Couchbase alternate addresses with couchbase-cli setting-alternate-address for the mapped mgmt/kv/n1ql/capi ports.
  • Connection strings use the mapped KV port with network=external, so the SDK bootstraps through the alternate addresses rather than the container-internal ones.
  • CouchbaseSource.dlt_source() preserves non-ssl URI query parameters (so network=external reaches the SDK) while still consuming ssl=true internally to upgrade couchbase:// to couchbases://.
  • Adds Docker-free unit tests for the URI query-parameter handling.
  • Updates the integration-test docstring, which no longer requires stopping a local Couchbase Server.

Test plan

  • ruff format --check and ruff check clean on touched files
  • ty check omniload clean
  • Docker-free unit tests: pytest tests/main/test_sources.py::CouchbaseSourceTest (2 passed
  • Integration test green against a real local Couchbase running on 8091: pytest tests/warehouse/db/test_couchbase.py::test_couchbase_source_local[duckdb]) 1 passed

Closes #82

The Couchbase test container bound host ports 1:1 (8091, 11210, ...),
which clashes with any Couchbase Server already running on the
workstation and could fail test_couchbase_source_local outright. The
pending testcontainers-python Couchbase support binds the same ports
1:1, so it would not remove the conflict either.

Switch CouchbaseContainer to Docker-assigned host ports via
with_exposed_ports() and advertise those mapped ports to SDK clients
through Couchbase alternate addresses (couchbase-cli
setting-alternate-address for mgmt/kv/n1ql/capi). Connection strings now
use the mapped KV port with network=external, so the SDK bootstraps
through the alternate addresses instead of the container-internal ones.

To make network=external reach the SDK, CouchbaseSource.dlt_source() now
preserves non-ssl URI query parameters when building the connection
string, while still consuming ssl=true internally to upgrade couchbase://
to couchbases://.

Adds Docker-free unit tests for the URI query-parameter handling and
updates the integration-test docstring, which no longer requires stopping
a local Couchbase Server.

@amotl amotl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wonderful, thank you for cleaning this up. Did you use the testcontainers implementation from this patch by @amithkoujalgi, or did you just strip away the static port assignments of the existing implementation?

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.28%. Comparing base (f74d292) to head (e7c4db5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #127      +/-   ##
==========================================
+ Coverage   50.22%   50.28%   +0.06%     
==========================================
  Files         188      188              
  Lines        8948     8951       +3     
==========================================
+ Hits         4494     4501       +7     
+ Misses       4454     4450       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@amotl amotl merged commit e78d0b2 into panodata:main Jul 1, 2026
14 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.

[Tests] Exception: Couchbase did not become ready after 30 attempts -- Bind for 0.0.0.0:8091 failed: port is already allocated

2 participants