Skip to content

Commit 68060d1

Browse files
committed
Await healthcheck for testing
1 parent 7a5edab commit 68060d1

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

api/core/rag/datasource/vdb/couchbase/couchbase_vector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
from flask import current_app
1717
from pydantic import BaseModel, model_validator
1818

19-
from core.rag.datasource.entity.embedding import Embeddings
2019
from core.rag.datasource.vdb.vector_base import BaseVector
2120
from core.rag.datasource.vdb.vector_factory import AbstractVectorFactory
2221
from core.rag.datasource.vdb.vector_type import VectorType
22+
from core.rag.embedding.embedding_base import Embeddings
2323
from core.rag.models.document import Document
2424
from extensions.ext_redis import redis_client
2525
from models.dataset import Dataset

api/tests/integration_tests/vdb/couchbase/test_couchbase.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import subprocess
12
import time
23

34
from core.rag.datasource.vdb.couchbase.couchbase_vector import CouchbaseConfig, CouchbaseVector
@@ -8,21 +9,42 @@
89
)
910

1011

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+
1127
class CouchbaseTest(AbstractVectorTest):
1228
def __init__(self):
13-
time.sleep(20)
1429
super().__init__()
1530
self.vector = CouchbaseVector(
1631
collection_name=self.collection_name,
1732
config=CouchbaseConfig(
18-
connection_string="127.0.0.1",
33+
connection_string="couchbase://127.0.0.1",
1934
user="Administrator",
2035
password="password",
2136
bucket_name="Embeddings",
2237
scope_name="_default",
2338
),
2439
)
2540

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+
2647

2748
def test_couchbase(setup_mock_redis):
49+
wait_for_healthy_container("couchbase-server", timeout=60)
2850
CouchbaseTest().run_all_tests()

dev/pytest/pytest_vdb.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ pytest api/tests/integration_tests/vdb/chroma \
1111
api/tests/integration_tests/vdb/vikingdb \
1212
api/tests/integration_tests/vdb/baidu \
1313
api/tests/integration_tests/vdb/tcvectordb \
14-
api/tests/integration_tests/vdb/upstash
14+
api/tests/integration_tests/vdb/upstash \
1515
api/tests/integration_tests/vdb/couchbase \

docker/couchbase-server/init-cbserver.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ if ! [ -f "$FILE" ]; then
1111
# used to automatically create the cluster based on environment variables
1212
# https://docs.couchbase.com/server/current/cli/cbcli/couchbase-cli-cluster-init.html
1313

14-
echo $COUCHBASE_ADMINISTRATOR_USERNAME ":" $COUCHBASE_ADMINISTRATOR_PASSWORD
14+
echo $COUCHBASE_ADMINISTRATOR_USERNAME ":" $COUCHBASE_ADMINISTRATOR_PASSWORD
1515

16-
sleep 10s
16+
sleep 20s
1717
/opt/couchbase/bin/couchbase-cli cluster-init -c 127.0.0.1 \
1818
--cluster-username $COUCHBASE_ADMINISTRATOR_USERNAME \
1919
--cluster-password $COUCHBASE_ADMINISTRATOR_PASSWORD \
@@ -24,7 +24,7 @@ if ! [ -f "$FILE" ]; then
2424
--cluster-fts-ramsize $COUCHBASE_FTS_RAM_SIZE \
2525
--index-storage-setting default
2626

27-
sleep 2s
27+
sleep 2s
2828

2929
# used to auto create the bucket based on environment variables
3030
# https://docs.couchbase.com/server/current/cli/cbcli/couchbase-cli-bucket-create.html
@@ -41,4 +41,4 @@ if ! [ -f "$FILE" ]; then
4141
fi
4242
# docker compose will stop the container from running unless we do this
4343
# known issue and workaround
44-
tail -f /dev/null
44+
tail -f /dev/null

docker/docker-compose.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ services:
480480
environment:
481481
QDRANT_API_KEY: ${QDRANT_API_KEY:-difyai123456}
482482

483-
# The Couchbase vector store.
483+
# The Couchbase vector store.
484484
couchbase-server:
485485
build: ./couchbase-server
486486
profiles:
@@ -505,6 +505,13 @@ services:
505505
command: sh -c "/opt/couchbase/init/init-cbserver.sh"
506506
volumes:
507507
- ./volumes/couchbase/data:/opt/couchbase/var/lib/couchbase/data
508+
healthcheck:
509+
# ensure bucket was created before proceeding
510+
test: [ "CMD-SHELL", "curl -s -f -u Administrator:password http://localhost:8091/pools/default/buckets | grep -q '\\[{' || exit 1" ]
511+
interval: 10s
512+
retries: 10
513+
start_period: 30s
514+
timeout: 10s
508515

509516
# The pgvector vector database.
510517
pgvector:

0 commit comments

Comments
 (0)