|
| 1 | +import subprocess |
1 | 2 | import time
|
2 | 3 |
|
3 | 4 | from core.rag.datasource.vdb.couchbase.couchbase_vector import CouchbaseConfig, CouchbaseVector
|
|
8 | 9 | )
|
9 | 10 |
|
10 | 11 |
|
| 12 | +def wait_for_healthy_container(service_name="couchbase-server", timeout=300): |
| 13 | + start_time = time.time() |
| 14 | + while time.time() - start_time < timeout: |
| 15 | + result = subprocess.run( |
| 16 | + ["docker", "inspect", "--format", "{{.State.Health.Status}}", service_name], capture_output=True, text=True |
| 17 | + ) |
| 18 | + if result.stdout.strip() == "healthy": |
| 19 | + print(f"{service_name} is healthy!") |
| 20 | + return True |
| 21 | + else: |
| 22 | + print(f"Waiting for {service_name} to be healthy...") |
| 23 | + time.sleep(10) |
| 24 | + raise TimeoutError(f"{service_name} did not become healthy in time") |
| 25 | + |
| 26 | + |
11 | 27 | class CouchbaseTest(AbstractVectorTest):
|
12 | 28 | def __init__(self):
|
13 |
| - time.sleep(20) |
14 | 29 | super().__init__()
|
15 | 30 | self.vector = CouchbaseVector(
|
16 | 31 | collection_name=self.collection_name,
|
17 | 32 | config=CouchbaseConfig(
|
18 |
| - connection_string="127.0.0.1", |
| 33 | + connection_string="couchbase://127.0.0.1", |
19 | 34 | user="Administrator",
|
20 | 35 | password="password",
|
21 | 36 | bucket_name="Embeddings",
|
22 | 37 | scope_name="_default",
|
23 | 38 | ),
|
24 | 39 | )
|
25 | 40 |
|
| 41 | + def search_by_vector(self): |
| 42 | + # brief sleep to ensure document is indexed |
| 43 | + time.sleep(5) |
| 44 | + hits_by_vector = self.vector.search_by_vector(query_vector=self.example_embedding) |
| 45 | + assert len(hits_by_vector) == 1 |
| 46 | + |
26 | 47 |
|
27 | 48 | def test_couchbase(setup_mock_redis):
|
| 49 | + wait_for_healthy_container("couchbase-server", timeout=60) |
28 | 50 | CouchbaseTest().run_all_tests()
|
0 commit comments