Skip to content

Commit

Permalink
Fix last remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashao committed May 11, 2024
1 parent 962c29f commit 09aa6f3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
7 changes: 5 additions & 2 deletions tests/backends/test_cli_mini_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@


def test_cli_mini_exp_doesnt_error_out_with_dev_build(
prepare_db,
local_db,
test_dir,
monkeypatch,
Expand All @@ -57,9 +58,11 @@ def test_cli_mini_exp_doesnt_error_out_with_dev_build(
to ensure that it does not accidentally report false positive/negatives
"""

db = prepare_db(local_db).orchestrator

@contextmanager
def _mock_make_managed_local_orc(*a, **kw):
(client_addr,) = local_db.get_address()
(client_addr,) = db.get_address()
yield smartredis.Client(False, address=client_addr)

monkeypatch.setattr(
Expand All @@ -68,7 +71,7 @@ def _mock_make_managed_local_orc(*a, **kw):
_mock_make_managed_local_orc,
)
backends = installed_redisai_backends()
(db_port,) = local_db.ports
(db_port,) = db.ports

smartsim._core._cli.validate.test_install(
# Shouldn't matter bc we are stubbing creation of orc
Expand Down
5 changes: 5 additions & 0 deletions tests/on_wlm/test_symlinking.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
import pathlib
import time

import pytest

from smartsim import Experiment

if pytest.test_launcher not in pytest.wlm_options:
pytestmark = pytest.mark.skip(reason="Not testing WLM integrations")


def test_batch_model_and_ensemble(test_dir, wlmutils):
exp_name = "test-batch"
Expand Down
8 changes: 5 additions & 3 deletions tests/test_collector_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,13 @@ async def test_collector_manager_collect_filesink(

@pytest.mark.asyncio
async def test_collector_manager_collect_integration(
test_dir: str, mock_entity: MockCollectorEntityFunc, local_db, mock_sink
test_dir: str, mock_entity: MockCollectorEntityFunc, prepare_db, local_db, mock_sink
) -> None:
"""Ensure that all collectors are executed and some metric is retrieved"""
entity1 = mock_entity(port=local_db.ports[0], name="e1", telemetry_on=True)
entity2 = mock_entity(port=local_db.ports[0], name="e2", telemetry_on=True)

db = prepare_db(local_db).orchestrator
entity1 = mock_entity(port=db.ports[0], name="e1", telemetry_on=True)
entity2 = mock_entity(port=db.ports[0], name="e2", telemetry_on=True)

# todo: consider a MockSink so i don't have to save the last value in the collector
sinks = [mock_sink(), mock_sink(), mock_sink()]
Expand Down
16 changes: 12 additions & 4 deletions tests/test_collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
# The tests in this file belong to the group_a group
pytestmark = pytest.mark.group_a

PrepareDB = t.Callable[[dict], smartsim.experiment.Orchestrator]


@pytest.mark.asyncio
async def test_dbmemcollector_prepare(
Expand Down Expand Up @@ -171,12 +173,15 @@ async def test_dbmemcollector_collect(
async def test_dbmemcollector_integration(
mock_entity: MockCollectorEntityFunc,
mock_sink: MockSink,
local_db: smartsim.experiment.Orchestrator,
prepare_db: PrepareDB,
local_db: dict,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Integration test with a real orchestrator instance to ensure
output data matches expectations and proper db client API uage"""
entity = mock_entity(port=local_db.ports[0], telemetry_on=True)

db = prepare_db(local_db).orchestrator
entity = mock_entity(port=db.ports[0], telemetry_on=True)

sink = mock_sink()
collector = DBMemoryCollector(entity, sink)
Expand Down Expand Up @@ -268,12 +273,15 @@ async def test_dbconn_count_collector_collect(
async def test_dbconncollector_integration(
mock_entity: MockCollectorEntityFunc,
mock_sink: MockSink,
local_db: smartsim.experiment.Orchestrator,
prepare_db: PrepareDB,
local_db: dict,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Integration test with a real orchestrator instance to ensure
output data matches expectations and proper db client API uage"""
entity = mock_entity(port=local_db.ports[0], telemetry_on=True)

db = prepare_db(local_db).orchestrator
entity = mock_entity(port=db.ports[0], telemetry_on=True)

sink = mock_sink()
collector = DBConnectionCollector(entity, sink)
Expand Down
9 changes: 5 additions & 4 deletions tests/test_orc_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
pytestmark = pytest.mark.group_b


def test_config_methods(dbutils, local_db):
def test_config_methods(dbutils, prepare_db, local_db):
"""Test all configuration file edit methods on an active db"""
db = prepare_db(local_db).orchestrator

# test the happy path and ensure all configuration file edit methods
# successfully execute when given correct key-value pairs
configs = dbutils.get_db_configs()
for setting, value in configs.items():
config_set_method = dbutils.get_config_edit_method(local_db, setting)
config_set_method = dbutils.get_config_edit_method(db, setting)
config_set_method(value)

# ensure SmartSimError is raised when Orchestrator.set_db_conf
Expand All @@ -57,15 +58,15 @@ def test_config_methods(dbutils, local_db):
for key, value_list in ss_error_configs.items():
for value in value_list:
with pytest.raises(SmartSimError):
local_db.set_db_conf(key, value)
db.set_db_conf(key, value)

# ensure TypeError is raised when Orchestrator.set_db_conf
# is given either a key or a value that is not a string
type_error_configs = dbutils.get_type_error_db_configs()
for key, value_list in type_error_configs.items():
for value in value_list:
with pytest.raises(TypeError):
local_db.set_db_conf(key, value)
db.set_db_conf(key, value)


def test_config_methods_inactive(dbutils):
Expand Down

0 comments on commit 09aa6f3

Please sign in to comment.