Example #1
0
def test_tracking_progress(
    monitor_events: List[CloudEvent],
    brm_mutations: List[Tuple[str, Any]],
    expected_progress: float,
    make_mock_ee_monitor,
):
    """Tests progress by providing a list of CloudEvent and a list of
    arguments to apply to setattr(brm) where brm is an actual BaseRunModel
    instance.

    The CloudEvent are provided to the tracker via mocking an Ensemble
    Evaluator Monitor.

    All events leading up to the final update event and end event, are
    discarded. The test asserts that the state of the world is correct only for
    the final update event."""
    brm = BaseRunModel(None)
    with patch("ert_shared.status.tracker.evaluator.create_ee_monitor") as mock_ee:
        mock_ee.return_value.__enter__.return_value = make_mock_ee_monitor(
            monitor_events.copy()
        )
        tracker = EvaluatorTracker(
            brm, "host", "port", 0, 0, next_ensemble_evaluator_wait_time=0.1
        )
        for attr, val in brm_mutations:
            setattr(brm, attr, val)
        tracker_gen = tracker.track()
        update_event = None
        for _ in range(len(monitor_events)):
            update_event = next(tracker_gen)
        assert isinstance(update_event, SnapshotUpdateEvent)
        assert update_event.progress == expected_progress
        brm._phase = brm._phase_count
        assert isinstance(next(tracker_gen), EndEvent)
Example #2
0
def test_batching(
    monitor_events: List[CloudEvent],
    expected_types: List[Any],
    make_mock_ee_monitor,
):
    """Test that monitor_events, when passed through this tracker, produces the
    expected event types. The contents of the events are ignored."""
    brm = BaseRunModel(None, phase_count=1)
    with patch("ert_shared.status.tracker.evaluator.create_ee_monitor"
               ) as mock_ee:
        mock_ee.return_value.__enter__.return_value = make_mock_ee_monitor(
            monitor_events)
        tracker = EvaluatorTracker(brm,
                                   "host",
                                   "port",
                                   0.1,
                                   1,
                                   next_ensemble_evaluator_wait_time=0.1)
        tracker_gen = tracker.track()
        for i, type_ in enumerate(expected_types):
            if type_ == EndEvent:
                brm._phase = 1
            event = next(tracker_gen)
            assert isinstance(event, type_), f"unexpected type at index {i}"
Example #3
0
def create_tracker(
    model,
    general_interval=5,
    detailed_interval=10,
    num_realizations=None,
    ee_config=None,
):
    """Creates a tracker tracking a @model. The provided model
    is updated either purely event-driven, or in two tiers: @general_interval,
    @detailed_interval. Whether updates are continuous or periodic depends on
    invocation. In the case of periodic updates, setting an interval to <=0
    disables update.

    If @num_realizations is defined, then the intervals are scaled
    according to some affine transformation such that it is tractable to
    do tracking. This only applies to periodic updates.

    If @ee_host_port_tuple then the factory will produce something that can
    track an ensemble evaluator and emit events appropriately.
    """
    if num_realizations is not None:
        general_interval, detailed_interval = scale_intervals(num_realizations)

    if FeatureToggling.is_enabled("ensemble-evaluator"):
        return EvaluatorTracker(
            model,
            ee_config.host,
            ee_config.port,
            general_interval,
            detailed_interval,
            token=ee_config.token,
            cert=ee_config.cert,
        )
    return LegacyTracker(
        model,
        general_interval,
        detailed_interval,
    )