Ejemplo n.º 1
0
def test_setting_a_string_as_none():
    string_metric = metrics.StringMetricType(
        disabled=False,
        category="telemetry",
        lifetime=Lifetime.APPLICATION,
        name="string_metric",
        send_in_pings=["store1", "store2"],
    )

    string_metric.set(None)

    assert not string_metric.test_has_value()
Ejemplo n.º 2
0
def test_disabled_strings_must_not_record_data():
    string_metric = metrics.StringMetricType(
        disabled=True,
        category="telemetry",
        lifetime=Lifetime.APPLICATION,
        name="string_metric",
        send_in_pings=["store1"],
    )

    string_metric.set("value")

    assert not string_metric.test_has_value()
Ejemplo n.º 3
0
def _subprocess():
    # If this runs on a thread, it won't complete before the process is
    # shutdown

    string_metric = metrics.StringMetricType(
        disabled=False,
        category="telemetry",
        lifetime=Lifetime.APPLICATION,
        name="string_metric",
        send_in_pings=["store1"],
    )

    string_metric.set("foo")
Ejemplo n.º 4
0
def test_setting_a_long_string_records_an_error():
    string_metric = metrics.StringMetricType(
        disabled=False,
        category="telemetry",
        lifetime=Lifetime.APPLICATION,
        name="string_metric",
        send_in_pings=["store1", "store2"],
    )

    string_metric.set("0123456789" * 11)

    assert 1 == string_metric.test_get_num_recorded_errors(
        testing.ErrorType.INVALID_OVERFLOW)
Ejemplo n.º 5
0
def test_single_threaded_in_multiprocessing_subprocess():
    import multiprocessing

    p = multiprocessing.Process(target=_subprocess)
    p.start()
    p.join()

    # This must match the definition in _subprocess() above.
    string_metric = metrics.StringMetricType(
        disabled=False,
        category="telemetry",
        lifetime=Lifetime.APPLICATION,
        name="string_metric",
        send_in_pings=["store1"],
    )

    assert string_metric.test_get_value() == "999"
Ejemplo n.º 6
0
def test_the_api_saves_to_its_storage_engine():
    string_metric = metrics.StringMetricType(
        disabled=False,
        category="telemetry",
        lifetime=Lifetime.APPLICATION,
        name="string_metric",
        send_in_pings=["store1"],
    )

    string_metric.set("value")

    assert string_metric.test_has_value()
    assert "value" == string_metric.test_get_value()

    string_metric.set("overriddenValue")

    assert string_metric.test_has_value()
    assert "overriddenValue" == string_metric.test_get_value()