Skip to content

Commit

Permalink
some tests, fix sync configs not working during worker addition
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Sep 11, 2024
1 parent 8271696 commit 7e06991
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 5 deletions.
16 changes: 13 additions & 3 deletions pioreactor/cli/pios.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,20 @@ def universal_identifier_to_all_active_workers(workers: tuple[str, ...]) -> tupl
else:
return tuple(u for u in set(workers) if u in active_workers)

def universal_identifier_to_all_workers(workers: tuple[str, ...]) -> tuple[str, ...]:
def universal_identifier_to_all_workers(
workers: tuple[str, ...], filter_out_non_workers=True
) -> tuple[str, ...]:
all_workers = get_workers_in_inventory()

if filter_out_non_workers:
include = lambda u: u in all_workers # noqa: E731
else:
include = lambda u: True # noqa: E731

if workers == (UNIVERSAL_IDENTIFIER,):
return all_workers
else:
return tuple(u for u in set(workers) if u in all_workers)
return tuple(u for u in set(workers) if include(u))

def add_leader(units: tuple[str, ...]) -> tuple[str, ...]:
leader = get_leader_hostname()
Expand Down Expand Up @@ -407,7 +415,9 @@ def sync_configs(shared: bool, specific: bool, skip_save: bool, units: tuple[str
If neither `--shared` not `--specific` are specified, both are set to true.
"""
logger = create_logger("sync_configs", unit=get_unit_name(), experiment=UNIVERSAL_EXPERIMENT)
units = add_leader(universal_identifier_to_all_workers(units))
units = add_leader(
universal_identifier_to_all_workers(units, filter_out_non_workers=False)
) # TODO: why is leader being added if I only specify a subset of units?

if not shared and not specific:
shared = specific = True
Expand Down
4 changes: 2 additions & 2 deletions pioreactor/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def test_pios_run_requests():
assert bucket[0].url == "http://unit1.local:4999/unit_api/jobs/run/job_name/stirring"


def test_pios_run_requests_dedup_and_filter():
units = ("unit1", "unit1", "notaunit")
def test_pios_run_requests_dedup_and_filter_units():
units = ("unit1", "unit1", "notaunitincluster")

with capture_requests() as bucket:
ctx = click.Context(run, allow_extra_args=True)
Expand Down
80 changes: 80 additions & 0 deletions pioreactor/tests/test_temperature_approximation_1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,3 +984,83 @@ def test_temperature_approximation19(self) -> None:
}

assert 55.5 <= self.t.approximate_temperature_1_0(features) <= 56.5

def test_temperature_approximation50(self) -> None:
# this was real data from a bheit

features = {
"previous_heater_dc": 1.3,
"room_temp": 22.0,
"time_series_of_temp": [
27.21875,
26.23958333,
25.52083333,
24.94791667,
24.45833333,
24.0625,
23.73958333,
23.4375,
23.1875,
23.0,
22.8125,
22.63541667,
22.5,
22.41666667,
22.3125,
22.23958333,
22.13541667,
22.0625,
22.0,
21.98958333,
21.9375,
21.875,
21.85416667,
21.8125,
21.80208333,
21.75,
21.75,
21.72916667,
21.6875,
],
}

with pytest.raises(ValueError):
assert 20 <= self.t.approximate_temperature_1_0(features) <= 30

features = {
"previous_heater_dc": 1.3,
"room_temp": 22.0 - 3.0, # here.
"time_series_of_temp": [
27.21875,
26.23958333,
25.52083333,
24.94791667,
24.45833333,
24.0625,
23.73958333,
23.4375,
23.1875,
23.0,
22.8125,
22.63541667,
22.5,
22.41666667,
22.3125,
22.23958333,
22.13541667,
22.0625,
22.0,
21.98958333,
21.9375,
21.875,
21.85416667,
21.8125,
21.80208333,
21.75,
21.75,
21.72916667,
21.6875,
],
}

assert 20 <= self.t.approximate_temperature_1_0(features) <= 30

0 comments on commit 7e06991

Please sign in to comment.