forked from kenzuya/unshackle
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
import pytest
|
|
|
|
from unshackle.core.downloaders.requests import SPEED_ROLLING_WINDOW, SpeedWindow
|
|
|
|
|
|
def test_rate_reflects_recent_window_not_full_history():
|
|
"""After a slow start (shared bucket), the display must show the current rate."""
|
|
win = SpeedWindow(0.0)
|
|
total = 0
|
|
for t in range(0, 60):
|
|
total += 5_000_000
|
|
win.rate(float(t), total)
|
|
for t in range(60, 120):
|
|
total += 10_000_000
|
|
rate = win.rate(float(t), total)
|
|
assert rate == pytest.approx(10_000_000, rel=0.01)
|
|
|
|
|
|
def test_first_report_is_the_since_start_average():
|
|
"""Bytes are credited in lumps; the first lump must not read as a whole window's worth."""
|
|
win = SpeedWindow(0.0)
|
|
assert win.rate(2.5, 25_000_000) == pytest.approx(10_000_000)
|
|
|
|
|
|
def test_stall_returns_none():
|
|
"""Once the seed ages out, a total that stops growing has no delta to report."""
|
|
win = SpeedWindow(0.0)
|
|
for t in range(0, SPEED_ROLLING_WINDOW + 6):
|
|
rate = win.rate(float(t), 1_000_000)
|
|
assert rate is None
|