Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api, performance-metrics): clean up performance-metrics tracking #15289

Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
tests: no unit tests because they have to be hacked to be written
missed something
  • Loading branch information
DerekMaggio committed Jun 3, 2024
commit 70017cd989c6dfad9d467ba15bafb3b8dda2856e
61 changes: 0 additions & 61 deletions robot-server/tests/protocols/test_protocol_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Tests for the ProtocolAnalyzer."""
from dataclasses import replace
from typing import Iterator
import pytest
from decoy import Decoy
from datetime import datetime
Expand Down Expand Up @@ -28,50 +26,6 @@

from opentrons_shared_data.errors import EnumeratedError, ErrorCodes

from opentrons_shared_data.performance.dev_types import (
RobotContextState,
)
from opentrons.util.performance_helpers import _get_robot_context_tracker

# Enable tracking for the RobotContextTracker
# This must come before the import of the analyze CLI
context_tracker = _get_robot_context_tracker()

# Ignore the type error for the next line, as we're setting a private attribute for testing purposes
context_tracker._should_track = True # type: ignore[attr-defined]


@pytest.fixture
def override_data_store(tmp_path: Path) -> Iterator[None]:
"""Override the data store metadata for the RobotContextTracker."""
old_store = context_tracker._store # type: ignore[attr-defined]
old_metadata = old_store.metadata
new_metadata = replace(old_metadata, storage_dir=tmp_path)
context_tracker._store = old_store.__class__(metadata=new_metadata) # type: ignore[attr-defined]
context_tracker._store.setup() # type: ignore[attr-defined]
yield
context_tracker._store = old_store # type: ignore[attr-defined]


@pytest.fixture
def monkeypatch_set_store_each_to_true(monkeypatch: pytest.MonkeyPatch) -> None:
"""Override the STORE_EACH flag for the RobotContextTracker."""
context_tracker._store_each = True # type: ignore[attr-defined]


def verify_metrics_store_file(file_path: Path, expected_length: int) -> None:
"""Verify that the metrics store file contains the expected number of lines."""
with open(file_path, "r") as f:
stored_data = f.readlines()
stored_data = [line.strip() for line in stored_data if line.strip()]
assert len(stored_data) == expected_length
for line in stored_data:
state_id, start_time, duration = line.strip().split(",")
assert state_id.isdigit()
assert state_id == str(RobotContextState.ANALYZING_PROTOCOL.state_id)
assert start_time.isdigit()
assert duration.isdigit()


@pytest.fixture(autouse=True)
def patch_mock_map_unexpected_error(
Expand Down Expand Up @@ -114,7 +68,6 @@ def subject(
)


@pytest.mark.usefixtures("override_data_store", "monkeypatch_set_store_each_to_true")
async def test_analyze(
decoy: Decoy,
analysis_store: AnalysisStore,
Expand Down Expand Up @@ -207,18 +160,12 @@ async def test_analyze(
)
)

store = context_tracker._store # type: ignore[attr-defined]

verify_metrics_store_file(store.metadata.data_file_location, 0)

await subject.analyze(
protocol_resource=protocol_resource,
analysis_id="analysis-id",
run_time_param_values=None,
)

verify_metrics_store_file(store.metadata.data_file_location, 1)

decoy.verify(
await analysis_store.update(
analysis_id="analysis-id",
Expand All @@ -233,14 +180,6 @@ async def test_analyze(
),
)

await subject.analyze(
protocol_resource=protocol_resource,
analysis_id="analysis-id",
run_time_param_values=None,
)

verify_metrics_store_file(store.metadata.data_file_location, 2)


async def test_analyze_updates_pending_on_error(
decoy: Decoy,
Expand Down
Loading