async def test_send_clear(time, debug_worker: DebugWorker, config: Config,
                          global_info: GlobalInfo, server,
                          error_store: ErrorStore):
    config.override(Setting.SEND_ERROR_REPORTS, True)
    config.override(Setting.DRIVE_HOST_NAME, "localhost")

    # Simulate failure
    global_info.failed(Exception("boom"))
    await debug_worker.doWork()

    # And then success
    global_info.success()
    time.advance(days=1)
    await debug_worker.doWork()
    report = error_store.last_error
    assert report['report'] == {'duration': '1 day, 0:00:00'}
Beispiel #2
0
async def test_publish_for_failure(updater: HaUpdater, server, time: FakeTime, global_info: GlobalInfo, supervisor: SimulatedSupervisor):
    global_info.success()
    await updater.update()
    assert supervisor.getNotification() is None

    time.advanceDay()
    global_info.failed(Exception())
    await updater.update()
    assert supervisor.getNotification() is not None

    time.advanceDay()
    global_info.failed(Exception())
    await updater.update()
    assert supervisor.getNotification() is not None

    global_info.success()
    await updater.update()
    assert supervisor.getNotification() is None
async def test_send_error_report(time, debug_worker: DebugWorker,
                                 config: Config, global_info: GlobalInfo,
                                 server, error_store: ErrorStore):
    config.override(Setting.SEND_ERROR_REPORTS, True)
    config.override(Setting.DRIVE_HOST_NAME, "localhost")
    global_info.sync()
    global_info.success()
    global_info.sync()
    global_info.success()
    global_info.sync()
    global_info.failed(Exception())
    await debug_worker.doWork()
    report = error_store.last_error
    assert report['report']['sync_success_count'] == 2
    assert report['report']['sync_count'] == 3
    assert report['report']['failure_count'] == 1
    assert report['report']['sync_last_start'] == time.now().isoformat()
    assert report['report']['failure_time'] == time.now().isoformat()
    assert report['report']['error'] == getLogger("test").formatException(
        Exception())