Пример #1
0
def test_calc_max_fps():
    # should be able to send at least 100 fps at 1024 bytes
    assert calc_max_fps(1, 1024) > 100
    # should be able to send more frames at 64 than 1024
    assert calc_max_fps(1, 64) > calc_max_fps(1, 1024)
    # should be able to send more frames with 1 stream than 100 streams
    assert calc_max_fps(1, 1024) > calc_max_fps(1000, 1024)
Пример #2
0
def test_check_rate_reasons():
    # starting with a reason should return that reason (maybe with additions)
    assert "foo" in check_rate(10, 1, 64, 1.0, Confidence(reason="foo")).reason
    assert "foo" in check_rate(10, 1, 64, 1.0, Confidence(reason="foo")).reason
    assert "foo" in check_rate(calc_max_fps(1, 1024) + 1, 1, 1024, 1.0,
                               Confidence(reason="foo")).reason

    # no fps should have no effect on reason
    assert check_rate(0, 1, 64, 1.0, Confidence(99.0, "foo")).reason == "foo"
    assert check_rate(0, 1000, 8192, 1.0,
                      Confidence(62.0, "foo")).reason == "foo"

    # oversubscribed means no confidence and a reason
    reason = check_rate(calc_max_fps(1, 1024) + 1, 1, 1024, 1.0,
                        Confidence()).reason
    assert "rate" in reason
    assert "loss" in reason or "lost" in reason

    # undersubscribed means no effect on reason
    assert check_rate(calc_max_fps(1, 1024)/2, 1, 1024, 1.0,
                      Confidence(75.0, "foo")).reason == "foo"

    # in the middle means a reason
    scaled_reason = check_rate(calc_max_fps(1, 1024) *
                               (1 + SAFETY_FACTOR) / 2,
                               1, 1024, 1.0, Confidence()).reason
    assert "rate" in scaled_reason
    assert "loss" in scaled_reason or "lost" in scaled_reason
Пример #3
0
def test_check_profile():
    # just do one check to make sure the plumbing is working
    # test_check_* functions above are more thorough and direct
    port_map = MockPhysicalPortMap()
    profile = {"streamCount": 1, "avgPacketSize": 1024,
               "avgFramesPerSecond": calc_max_fps(1, 1024)}
    confidence = check_profile(profile, port_map, "1.2.3.4/1/1", Confidence())
    assert confidence.percent == 0.0
    assert "reserved" in confidence.reason
Пример #4
0
def test_check_rate():
    # starting with 0 confidence should always return 0 confidence
    assert check_rate(10, 1, 64, 1.0, Confidence(0.0)).percent == 0.0

    # no fps should have no effect on confidence
    assert check_rate(0, 1, 64, 1.0, Confidence(99.0)).percent == 99.0
    assert check_rate(0, 1000, 8192, 1.0, Confidence(62.0)).percent == 62.0

    # oversubscribed means no confidence
    assert check_rate(calc_max_fps(1, 1024) + 1, 1, 1024, 1.0,
                      Confidence(100.0)).percent == 0.0

    # undersubscribed means no change to confidence
    assert check_rate(calc_max_fps(1, 1024)/2, 1, 1024, 1.0,
                      Confidence(75.0)).percent == 75.0

    # in the middle means scaling confidence
    scaled_confidence = check_rate(calc_max_fps(1, 1024) *
                                   (1 + SAFETY_FACTOR) / 2,
                                   1, 1024, 1.0, Confidence(100.0)).percent
    assert round(scaled_confidence, 2) == 50.0

    # 50% baseline factor means less confidence
    assert check_rate(calc_max_fps(1, 1024), 1, 1024, 0.5,
                      Confidence(100.0)).percent < 100.0

    # 50% baseline factor means 50% less performance
    assert check_rate(SAFETY_FACTOR * calc_max_fps(1, 1024) / 2, 1, 1024,
                      0.5, Confidence(100.0)).percent == 100.0

    # 200% baseline factor means double performance (but it will never be 2)
    assert check_rate(SAFETY_FACTOR * calc_max_fps(1, 1024) * 2, 1, 1024,
                      2, Confidence(100.0)).percent == 100.0