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
6 changes: 3 additions & 3 deletions openviking/storage/collection_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async def on_dequeue(self, data: Optional[Dict[str, Any]]) -> Optional[Dict[str,
embedding_msg = EmbeddingMsg.from_dict(queue_data)
inserted_data = embedding_msg.context_data

if getattr(self._vikingdb, "is_closing", False):
if self._vikingdb.is_closing:
logger.debug("Skip embedding dequeue during shutdown")
self.report_success()
return None
Expand Down Expand Up @@ -219,15 +219,15 @@ async def on_dequeue(self, data: Optional[Dict[str, Any]]) -> Optional[Dict[str,
)
except CollectionNotFoundError as db_err:
# During shutdown, queue workers may finish one dequeued item.
if getattr(self._vikingdb, "is_closing", False):
if self._vikingdb.is_closing:
logger.debug(f"Skip embedding write during shutdown: {db_err}")
self.report_success()
return None
logger.error(f"Failed to write to vector database: {db_err}")
self.report_error(str(db_err), data)
return None
except Exception as db_err:
if getattr(self._vikingdb, "is_closing", False):
if self._vikingdb.is_closing:
logger.debug(f"Skip embedding write during shutdown: {db_err}")
self.report_success()
return None
Expand Down
5 changes: 5 additions & 0 deletions openviking/storage/viking_vector_index_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@ async def get_stats(self) -> Dict[str, Any]:
"error": str(e),
}

@property
def is_closing(self) -> bool:
"""Whether the backend is in shutdown flow. Always False for the base class."""
return False

@property
def mode(self) -> str:
return self._mode
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ test = [
"pytest-asyncio>=0.21.0",
"boto3>=1.42.44",
"pytest-cov>=4.0.0",
"ragas>=0.1.0",
"datasets>=2.0.0",
"pandas>=2.0.0",
]
dev = [
"mypy>=1.0.0",
Expand Down
3 changes: 3 additions & 0 deletions tests/agfs/test_fs_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ async def viking_fs_binding_instance():
# Initialize VikingFS with client
vfs = init_viking_fs(agfs=agfs_client)

# Ensure test directory exists
await vfs.mkdir("viking://temp/", exist_ok=True)

yield vfs


Expand Down
27 changes: 19 additions & 8 deletions tests/cli/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ def openviking_server(tmp_path_factory: pytest.TempPathFactory) -> Generator[str
conf_data["server"]["port"] = port

conf_data.setdefault("storage", {})
conf_data["storage"]["workspace"] = str(storage_dir)
conf_data["storage"].setdefault("vectordb", {})
conf_data["storage"]["vectordb"]["backend"] = "local"
conf_data["storage"]["vectordb"]["path"] = str(storage_dir)
conf_data["storage"].setdefault("agfs", {})
conf_data["storage"]["agfs"]["backend"] = "local"
conf_data["storage"]["agfs"]["path"] = str(storage_dir)

# Write temporary ov.conf
tmp_conf = storage_dir / "ov.conf"
Expand Down Expand Up @@ -92,10 +91,22 @@ def openviking_server(tmp_path_factory: pytest.TempPathFactory) -> Generator[str
try:
_wait_for_health(url)
yield url
except RuntimeError:
# Capture server output for debugging
stdout, stderr = "", ""
if proc.poll() is not None:
stdout, stderr = proc.communicate(timeout=5)
else:
proc.terminate()
stdout, stderr = proc.communicate(timeout=10)
raise RuntimeError(
f"OpenViking server failed to start.\nstdout:\n{stdout}\nstderr:\n{stderr}"
)
finally:
proc.terminate()
try:
proc.wait(timeout=10)
except subprocess.TimeoutExpired:
proc.kill()
proc.wait(timeout=10)
if proc.poll() is None:
proc.terminate()
try:
proc.wait(timeout=10)
except subprocess.TimeoutExpired:
proc.kill()
proc.wait(timeout=10)
2 changes: 1 addition & 1 deletion tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_cli_real_requests(openviking_server, tmp_path):
_run_cli(["overview", "viking://resources"], server_url)

# -- search --
_run_cli(["grep", root_uri, "OpenViking"], server_url)
_run_cli(["grep", "OpenViking", "--uri", root_uri], server_url)
_run_cli(["glob", "*.txt", "--uri", root_uri], server_url)
_run_cli(["search", "OpenViking", "--uri", root_uri], server_url)

Expand Down
7 changes: 6 additions & 1 deletion tests/misc/test_port_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ def test_occupied_port_no_resource_warning(self):

mgr = _make_manager(port)
try:
# Flush any ResourceWarnings accumulated from previous tests
with warnings.catch_warnings(record=True):
warnings.simplefilter("always", ResourceWarning)
gc.collect()

with pytest.raises(RuntimeError):
mgr._check_port_available()

# Force GC and check for ResourceWarning about unclosed socket
# Now check only for new ResourceWarnings from _check_port_available
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always", ResourceWarning)
gc.collect()
Expand Down
12 changes: 7 additions & 5 deletions tests/server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@

@pytest.fixture(scope="function")
def temp_dir():
"""Create temp directory, auto-cleanup."""
shutil.rmtree(TEST_TMP_DIR, ignore_errors=True)
TEST_TMP_DIR.mkdir(parents=True, exist_ok=True)
yield TEST_TMP_DIR
shutil.rmtree(TEST_TMP_DIR, ignore_errors=True)
"""Create a unique temp directory per test, auto-cleanup."""
import uuid

unique_dir = TEST_TMP_DIR / uuid.uuid4().hex[:8]
unique_dir.mkdir(parents=True, exist_ok=True)
yield unique_dir
shutil.rmtree(unique_dir, ignore_errors=True)


@pytest.fixture(scope="function")
Expand Down
Loading
Loading