Exemplo n.º 1
0
  def test_windowing(self):
    TEN_SECONDS = Amount(10, Time.SECONDS).as_(Time.SECONDS)

    clock = TestClock()
    gauge = FakeGauge('test').supplies([100, 0, 50, 100, 150, 100, 50])
    rate = Rate("foo", gauge, window = Amount(30, Time.SECONDS), clock=clock)

    assert rate.read() == 0

    clock.advance(TEN_SECONDS)
    assert -100.0 / 10 == rate.read()

    clock.advance(TEN_SECONDS)
    assert -50.0 / 20 == rate.read()

    clock.advance(TEN_SECONDS)
    assert 0 == rate.read()

    clock.advance(TEN_SECONDS)
    assert 150.0 / 30 == rate.read()

    clock.advance(TEN_SECONDS)
    assert 50.0 / 30 == rate.read()

    clock.advance(TEN_SECONDS)
    assert -50.0 / 30 == rate.read()
Exemplo n.º 2
0
 def test_empty(self):
   clock = TestClock()
   gauge = FakeGauge('test').supplies([100000])
   rate = Rate("foo", gauge, window = Amount(30, Time.SECONDS), clock=clock)
   assert rate.read() == 0