Beispiel #1
0
def test_ping_upload_worker_single_process(safe_httpserver):
    safe_httpserver.serve_content(b"", code=200)
    Glean._configuration.server_endpoint = safe_httpserver.url

    pings_dir = PingUploadWorker.storage_directory()
    pings_dir.mkdir()

    for i in range(100):
        with (pings_dir / str(uuid.uuid4())).open("wb") as fd:
            fd.write(b"/data/path/\n")
            fd.write(b"{}\n")

    # Fire off two PingUploadWorker processing tasks at the same time. If
    # working correctly, p1 should finish entirely before p2 starts.
    # If these actually run in parallel, one or the other will try to send
    # deleted queued ping files and fail.
    p1 = PingUploadWorker._process()
    p2 = PingUploadWorker._process()

    p1.wait()
    assert p1.returncode == 0

    p2.wait()
    assert p2.returncode == 0

    assert 100 == len(safe_httpserver.requests)
Beispiel #2
0
def test_invalid_content():
    pings_dir = PingUploadWorker.storage_directory()
    pings_dir.mkdir()

    with (pings_dir / str(uuid.uuid4())).open("wb") as fd:
        fd.write(b"\n")

    assert not PingUploadWorker.process()

    assert 0 == len(list(pings_dir.iterdir()))
Beispiel #3
0
def test_invalid_filename():
    pings_dir = PingUploadWorker.storage_directory()
    pings_dir.mkdir()

    with (pings_dir / "ping").open("wb") as fd:
        fd.write(b"\n")

    assert PingUploadWorker._test_process_sync()

    assert 0 == len(list(pings_dir.iterdir()))
Beispiel #4
0
def test_unknown_scheme():
    Glean._configuration.server_endpoint = "ftp://example.com/"

    pings_dir = PingUploadWorker.storage_directory()
    pings_dir.mkdir()

    with (pings_dir / str(uuid.uuid4())).open("wb") as fd:
        fd.write(b"/data/path/\n")
        fd.write(b"{}\n")

    assert False is PingUploadWorker._test_process_sync()
Beispiel #5
0
def test_unknown_scheme():
    Glean._configuration.server_endpoint = "ftp://example.com/"

    pings_dir = PingUploadWorker.storage_directory()
    pings_dir.mkdir()

    with (pings_dir / str(uuid.uuid4())).open("wb") as fd:
        fd.write(b"/data/path/\n")
        fd.write(b"{}\n")

    with pytest.raises(ValueError):
        PingUploadWorker.process()
Beispiel #6
0
def test_500_error(safe_httpserver):
    safe_httpserver.serve_content(b"", code=500)
    Glean._configuration.server_endpoint = safe_httpserver.url

    pings_dir = PingUploadWorker.storage_directory()
    pings_dir.mkdir()

    with (pings_dir / str(uuid.uuid4())).open("wb") as fd:
        fd.write(b"/data/path/\n")
        fd.write(b"{}\n")

    assert not PingUploadWorker._test_process_sync()

    assert 1 == len(list(pings_dir.iterdir()))

    assert 1 == len(safe_httpserver.requests)
Beispiel #7
0
def test_tempdir_is_cleared_multiprocess(safe_httpserver):
    safe_httpserver.serve_content(b"", code=200)
    Glean._configuration.server_endpoint = safe_httpserver.url

    pings_dir = PingUploadWorker.storage_directory()
    pings_dir.mkdir()

    for i in range(100):
        with (pings_dir / str(uuid.uuid4())).open("wb") as fd:
            fd.write(b"/data/path/\n")
            fd.write(b"{}\n")

    # Make sure that resetting while the PingUploadWorker is running doesn't
    # delete the directory out from under the PingUploadWorker.
    p1 = PingUploadWorker._process()
    Glean._reset()

    p1.wait()
    assert p1.returncode == 0

    assert 100 == len(safe_httpserver.requests)