Ejemplo n.º 1
0
def test_recording_upload_errors_doesnt_clobber_database(
        tmpdir, safe_httpserver, monkeypatch):
    """
    Test that running the ping uploader subprocess doesn't clobber the
    database. If, under some bug, the subprocess had "upload_enabled" set to
    True, it could record upload errors in the database, clobbering any metrics
    that might have meanwhile been recorded in the main process.

    This test is known to fail if "upload_enabled" is set to `True` in the
    subprocess.
    """
    tmpdir = Path(tmpdir)

    Glean._reset()
    Glean.initialize(
        application_id=GLEAN_APP_ID,
        application_version=glean_version,
        upload_enabled=True,
        data_dir=tmpdir,
    )

    counter_metric = CounterMetricType(
        disabled=False,
        category="telemetry",
        lifetime=Lifetime.PING,
        name="counter_metric",
        send_in_pings=["baseline"],
    )
    counter_metric.add(10)

    safe_httpserver.serve_content(b"", code=400)

    # Force the ping upload worker into a separate process
    monkeypatch.setattr(PingUploadWorker, "process", PingUploadWorker._process)
    Glean._configuration._server_endpoint = safe_httpserver.url
    Glean._submit_ping_by_name("baseline")
    ProcessDispatcher._wait_for_last_process()

    assert 1 == len(safe_httpserver.requests)

    # Force a reload of the database from disk
    Glean._reset()
    Glean.initialize(
        application_id=GLEAN_APP_ID,
        application_version=glean_version,
        upload_enabled=True,
        data_dir=tmpdir,
    )

    metric = get_upload_failure_metric()
    assert not metric["status_code_4xx"].test_has_value()
Ejemplo n.º 2
0
def test_400_error_submit(safe_httpserver, monkeypatch):
    safe_httpserver.serve_content(b"", code=400)

    # Force the ping upload worker into a separate process
    monkeypatch.setattr(PingUploadWorker, "process", PingUploadWorker._process)
    Glean._configuration._server_endpoint = safe_httpserver.url
    Glean._submit_ping_by_name("baseline")
    ProcessDispatcher._wait_for_last_process()

    assert 1 == len(safe_httpserver.requests)

    metric = get_upload_failure_metric()
    assert 1 == metric["status_code_4xx"].test_get_value()
    assert not metric["status_code_5xx"].test_has_value()
Ejemplo n.º 3
0
def test_500_error_submit(safe_httpserver, monkeypatch):
    safe_httpserver.serve_content(b"", code=500)

    # Force the ping upload worker into a separate process
    monkeypatch.setattr(PingUploadWorker, "process", PingUploadWorker._process)
    Glean._configuration._server_endpoint = safe_httpserver.url
    Glean._submit_ping_by_name("baseline")
    ProcessDispatcher._wait_for_last_process()

    # This kind of recoverable error will be tried 10 times
    # The number of retries is defined on glean-core
    assert 3 == len(safe_httpserver.requests)

    metric = get_upload_failure_metric()
    assert not metric["status_code_4xx"].test_has_value()
    assert 3 == metric["status_code_5xx"].test_get_value()
Ejemplo n.º 4
0
def test_module_path_working(tmpdir):
    """
    Test that running a subprocess task works under normal circumstances
    (without monkeying with PYTHONPATH).
    """

    tmpdir = Path(tmpdir)
    (tmpdir / "glean").mkdir()
    with open(tmpdir / "glean" / "__init__.py", "w") as fd:
        fd.write("\n")
    (tmpdir / "foo").mkdir()

    ProcessDispatcher.dispatch(_rmtree, (str(tmpdir / "foo"), ))

    returncode = ProcessDispatcher._last_process.wait()

    assert returncode == 0

    assert not (tmpdir / "foo").exists()
Ejemplo n.º 5
0
def test_module_path_change_pythonpath(tmpdir, monkeypatch):
    """
    If PYTHONPATH gets set to a place with a broken installation of Glean,
    running a subprocess task should still work.
    """

    tmpdir = Path(tmpdir)
    (tmpdir / "glean").mkdir()
    with open(tmpdir / "glean" / "__init__.py", "w") as fd:
        fd.write("\n")
    (tmpdir / "foo").mkdir()

    monkeypatch.setenv("PYTHONPATH", str(tmpdir))

    ProcessDispatcher.dispatch(_rmtree, (str(tmpdir), ))

    returncode = ProcessDispatcher._last_process.wait()

    assert returncode == 0

    assert not (tmpdir / "foo").exists()