Exemplo n.º 1
0
def test_changes(full_snapshot):
    source_model = SnapshotModel()

    model = JobListProxyModel(None, 0, 0, 0, 0)
    model.setSourceModel(source_model)

    reporting_mode = qt_api.QtTest.QAbstractItemModelTester.FailureReportingMode.Warning
    tester = qt_api.QtTest.QAbstractItemModelTester(  # noqa, prevent GC
        model, reporting_mode)

    source_model._add_snapshot(SnapshotModel.prerender(full_snapshot), 0)
    assert (model.index(0, _id_to_col(ids.STATUS),
                        QModelIndex()).data() == JOB_STATE_START)

    partial = PartialSnapshot(full_snapshot)
    start_time = datetime.datetime(year=2020, month=10, day=27, hour=12)
    end_time = datetime.datetime(year=2020, month=10, day=28, hour=13)
    partial.update_job(
        "0",
        "0",
        "0",
        job=Job(
            status=JOB_STATE_FAILURE,
            start_time=start_time,
            end_time=end_time,
        ),
    )
    source_model._add_partial_snapshot(SnapshotModel.prerender(partial), 0)
    assert (model.index(0, _id_to_col(DURATION),
                        QModelIndex()).data() == "1 day, 1:00:00")
    assert (model.index(0, _id_to_col(ids.STATUS),
                        QModelIndex()).data() == JOB_STATE_FAILURE)
Exemplo n.º 2
0
def test_realization_job_hint(full_snapshot):
    model = SnapshotModel()
    model._add_snapshot(full_snapshot, 0)

    partial = PartialSnapshot(full_snapshot)
    partial.update_job("0", "0", "0", Job(status=JOB_STATE_RUNNING))
    model._add_partial_snapshot(partial, 0)

    first_real = model.index(0, 0, model.index(0, 0))
    colors = model.data(first_real, RealJobColorHint)
    assert colors[0].name() == QColor(*COLOR_RUNNING).name()
    assert colors[1].name() == QColor(*COLOR_PENDING).name()
Exemplo n.º 3
0
def test_duration(mock_datetime, timezone, full_snapshot):
    source_model = SnapshotModel()

    model = JobListProxyModel(None, 0, 0, 0, 0)
    model.setSourceModel(source_model)

    reporting_mode = qt_api.QtTest.QAbstractItemModelTester.FailureReportingMode.Warning
    tester = qt_api.QtTest.QAbstractItemModelTester(  # noqa, prevent GC
        model, reporting_mode)

    source_model._add_snapshot(SnapshotModel.prerender(full_snapshot), 0)
    assert (model.index(0, _id_to_col(ids.STATUS),
                        QModelIndex()).data() == JOB_STATE_START)

    partial = PartialSnapshot(full_snapshot)
    start_time = datetime.datetime(year=2020,
                                   month=10,
                                   day=27,
                                   hour=12,
                                   tzinfo=timezone)
    # mock only datetime.datetime.now()
    mock_datetime.datetime.now.return_value = datetime.datetime(
        year=2020,
        month=10,
        day=28,
        hour=13,
        minute=12,
        second=11,
        microsecond=5,  # Note that microseconds are intended to be removed
        tzinfo=timezone,
    )
    partial.update_job(
        "0",
        "0",
        "2",
        job=Job(
            status=JOB_STATE_RUNNING,
            start_time=start_time,
        ),
    )
    source_model._add_partial_snapshot(SnapshotModel.prerender(partial), 0)
    assert (model.index(2, _id_to_col(DURATION),
                        QModelIndex()).data() == "1 day, 1:12:11")
    mock_datetime.datetime.now.assert_called_once_with(timezone)
Exemplo n.º 4
0
def test_no_cross_talk(full_snapshot):
    source_model = SnapshotModel()

    model = JobListProxyModel(None, 0, 0, 0, 0)
    model.setSourceModel(source_model)

    reporting_mode = qt_api.QtTest.QAbstractItemModelTester.FailureReportingMode.Warning
    qt_api.QtTest.QAbstractItemModelTester(model,
                                           reporting_mode)  # noqa, prevent GC

    source_model._add_snapshot(SnapshotModel.prerender(full_snapshot), 0)
    source_model._add_snapshot(SnapshotModel.prerender(full_snapshot), 1)

    # Test that changes to iter=1 does not bleed into iter=0
    partial = PartialSnapshot(full_snapshot)
    partial.update_job("0", "0", "0", job=Job(status=JOB_STATE_FAILURE))
    source_model._add_partial_snapshot(SnapshotModel.prerender(partial), 1)
    assert (model.index(0, _id_to_col(ids.STATUS),
                        QModelIndex()).data() == JOB_STATE_START)

    model.set_step(1, 0, 0, 0)
    assert (model.index(0, _id_to_col(ids.STATUS),
                        QModelIndex()).data() == JOB_STATE_FAILURE)
Exemplo n.º 5
0
def test_snapshot_merge(snapshot):
    update_event = PartialSnapshot(snapshot)
    update_event.update_status(status="running")

    snapshot.merge_event(update_event)

    assert snapshot.get_status() == "running"

    update_event = PartialSnapshot(snapshot)
    update_event.update_job(
        real_id="1",
        step_id="0",
        job_id="0",
        job=Job(
            status="Finished",
            start_time=datetime(year=2020, month=10, day=27),
            end_time=datetime(year=2020, month=10, day=28),
            data={"memory": 1000},
        ),
    )
    update_event.update_job(
        real_id="1",
        step_id="0",
        job_id="1",
        job=Job(
            status="Running",
            start_time=datetime(year=2020, month=10, day=27),
        ),
    )
    update_event.update_job(
        real_id="9",
        step_id="0",
        job_id="0",
        job=Job(
            status="Running",
            start_time=datetime(year=2020, month=10, day=27),
        ),
    )

    snapshot.merge_event(update_event)

    assert snapshot.get_status() == "running"

    assert snapshot.get_job(real_id="1", step_id="0", job_id="0") == Job(
        status="Finished",
        start_time=datetime(year=2020, month=10, day=27),
        end_time=datetime(year=2020, month=10, day=28),
        data={"memory": 1000},
        error=None,
        name="job0",
        stderr=None,
        stdout=None,
    )

    assert snapshot.get_job(real_id="1", step_id="0", job_id="1") == Job(
        status="Running",
        start_time=datetime(year=2020, month=10, day=27),
        end_time=None,
        data={},
        error=None,
        name="job1",
        stderr=None,
        stdout=None,
    )

    assert snapshot.get_job(real_id="9", step_id="0",
                            job_id="0").status == "Running"
    assert snapshot.get_job(real_id="9", step_id="0", job_id="0") == Job(
        status="Running",
        start_time=datetime(year=2020, month=10, day=27),
        end_time=None,
        data={},
        error=None,
        name="job0",
        stderr=None,
        stdout=None,
    )
Exemplo n.º 6
0
def partial_snapshot(snapshot) -> PartialSnapshot:
    partial = PartialSnapshot(snapshot)
    partial.update_real("0", Realization(status=JOB_STATE_FINISHED))
    partial.update_job("0", "0", "0", Job(status=JOB_STATE_FINISHED))
    return partial
Exemplo n.º 7
0
    def _create_partial_snapshot(
        self,
        run_context: ErtRunContext,
        detailed_progress: typing.Tuple[typing.Dict, int],
        iter_: int,
    ) -> typing.Optional[PartialSnapshot]:
        """Create a PartialSnapshot, or None if the sources of data were
        destroyed or had not been created yet. Both run_context and
        detailed_progress needs to be aligned with the stars if job status etc
        is to be produced. If queue_snapshot is set, this means the the differ
        will not be used to calculate changes."""
        queue = self._iter_queue.get(iter_, None)
        if queue is None:
            logger.debug(f"no queue for {iter_}, no partial returned")
            return None
        queue_snapshot = queue.snapshot()

        snapshot = self._iter_snapshot.get(iter_, None)
        if snapshot is None:
            logger.debug(f"no snapshot for {iter_}, no partial returned")
            return None

        partial = PartialSnapshot(snapshot)

        if queue_snapshot is not None:
            for iens, change in queue_snapshot.items():
                change_enum = JobStatusType.from_string(change)
                partial.update_real(
                    str(iens),
                    Realization(
                        status=queue_status_to_real_state(change_enum)),
                )
        iter_to_progress, progress_iter = detailed_progress
        if not iter_to_progress:
            logger.debug(f"partial: no detailed progress for iter:{iter_}")
            return partial
        if iter_ != progress_iter:
            logger.debug(
                f"partial: iter_to_progress iter ({progress_iter}) differed from run_context ({iter_})"
            )

        for iens, _ in _enumerate_run_context(run_context):
            if not _is_iens_active(iens, run_context):
                continue

            progress = iter_to_progress[iter_].get(iens, None)
            if not progress:
                continue

            jobs = progress[0]
            for idx, fm in enumerate(jobs):
                partial.update_job(
                    str(iens),  # real_id
                    "0",
                    str(idx),
                    Job(
                        status=_map_job_state(fm.status),
                        start_time=fm.start_time,
                        end_time=fm.end_time,
                        data={
                            CURRENT_MEMORY_USAGE: fm.current_memory_usage,
                            MAX_MEMORY_USAGE: fm.max_memory_usage,
                        },
                        stdout=fm.std_out_file,
                        stderr=fm.std_err_file,
                        error=fm.error,
                    ),
                )

        return partial
Exemplo n.º 8
0
def test_snapshot_merge():
    snapshot = _create_snapshot()

    update_event = PartialSnapshot()
    update_event.update_status(status="running")

    snapshot.merge_event(update_event)

    assert snapshot.get_status() == "running"

    update_event = PartialSnapshot()
    update_event.update_job(
        real_id="1",
        stage_id="0",
        step_id="0",
        job_id="0",
        status="Finished",
        start_time=datetime(year=2020, month=10, day=27).isoformat(),
        end_time=datetime(year=2020, month=10, day=28).isoformat(),
        data={"memory": 1000},
    )
    update_event.update_job(
        real_id="1",
        stage_id="0",
        step_id="0",
        job_id="1",
        status="Running",
        start_time=datetime(year=2020, month=10, day=27).isoformat(),
    )
    update_event.update_job(
        real_id="9",
        stage_id="0",
        step_id="0",
        job_id="0",
        status="Running",
        start_time=datetime(year=2020, month=10, day=27).isoformat(),
    )

    snapshot.merge_event(update_event)

    assert snapshot.get_status() == "running"

    assert _dict_equal(
        snapshot.get_job(real_id="1", stage_id="0", step_id="0", job_id="0"),
        {
            "status": "Finished",
            "start_time": "2020-10-27T00:00:00",
            "end_time": "2020-10-28T00:00:00",
            "data": {
                "memory": 1000
            },
            "error": None,
            "name": "job0",
            "stderr": None,
            "stdout": None,
        },
    )
    assert snapshot.get_job(real_id="1", stage_id="0", step_id="0",
                            job_id="1") == {
                                "status": "Running",
                                "start_time": "2020-10-27T00:00:00",
                                "end_time": None,
                                "data": {},
                                "error": None,
                                "name": "job1",
                                "stderr": None,
                                "stdout": None,
                            }

    assert (snapshot.get_job(real_id="9",
                             stage_id="0",
                             step_id="0",
                             job_id="0")["status"] == "Running")
    assert snapshot.get_job(real_id="9", stage_id="0", step_id="0",
                            job_id="0") == {
                                "status": "Running",
                                "start_time": "2020-10-27T00:00:00",
                                "end_time": None,
                                "data": {},
                                "error": None,
                                "name": "job0",
                                "stderr": None,
                                "stdout": None,
                            }