Exemple #1
0
def test_clock_running(fake_time):
    c = util.Clock()
    c.start("total")
    fake_time.value += 3
    c.start("read")
    fake_time.value += 4
    c.stop("read")
    assert str(c) == "[total=7.000000/1, read=4.000000/1]"
Exemple #2
0
def test_clock_run(fake_time):
    c = util.Clock()
    with c.run("total"):
        with c.run("a"):
            fake_time.value += 4
        with c.run("b"):
            fake_time.value += 3
    assert str(c) == "[total=7.000000/1, a=4.000000/1, b=3.000000/1]"
Exemple #3
0
def test_clock_stop_returns_elapsed_time(fake_time):
    c = util.Clock()

    c.start("read")
    fake_time.value += 1
    assert c.stop("read") == 1

    c.start("read")
    fake_time.value += 2
    assert c.stop("read") == 2
Exemple #4
0
def test_benchmark():
    c = util.Clock()
    c.start("connection")
    # We have seen 66,000 requests per single upload with virt-v2v.
    for i in range(50000):
        c.start("request")
        c.start("read")
        c.stop("read")
        c.start("write")
        c.stop("write")
        c.stop("request")
    c.stop("connection")
    print(c)
Exemple #5
0
def test_clock_measure(fake_time):
    c = util.Clock()
    c.start("total")
    c.start("read")
    fake_time.value += 1
    c.stop("read")
    c.start("write")
    fake_time.value += 1
    c.stop("write")
    c.start("sync")
    fake_time.value += 1
    c.stop("sync")
    c.stop("total")
    assert str(c) == (
        "[total=3.000000/1, read=1.000000/1, write=1.000000/1, "
        "sync=1.000000/1]")
Exemple #6
0
def test_clock_run_recursive():
    c = util.Clock()
    with c.run("started"):
        with pytest.raises(RuntimeError):
            with c.run("started"):
                pass
Exemple #7
0
def test_clock_stop_missing():
    c = util.Clock()
    with pytest.raises(RuntimeError):
        c.stop("missing")
Exemple #8
0
def test_clock_stop_twice():
    c = util.Clock()
    c.start("stopped")
    c.stop("stopped")
    with pytest.raises(RuntimeError):
        c.stop("stopped")
Exemple #9
0
def test_clock_empty():
    c = util.Clock()
    assert str(c) == "[]"