Skip to content

Commit

Permalink
basic predictor test
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Jun 28, 2024
1 parent 70f08c1 commit 65865a7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions certexchange/polling/predictor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package polling

import (
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestPredictor(t *testing.T) {
p := newPredictor(time.Second, 30*time.Second, 120*time.Second)

// Progress of 1 shouldn't update anything.
require.Equal(t, 30*time.Second, p.update(1))
require.Equal(t, 30*time.Second, p.update(1))

// Progress of 0 should predict the same interval, then twice that, etc.
require.Equal(t, 30*time.Second, p.update(0))
require.Equal(t, 60*time.Second, p.update(0))

// After that, the intervalA should increase slightly.
intervalA := p.update(1)
require.Less(t, 30*time.Second, intervalA)
require.Greater(t, 40*time.Second, intervalA)

// If the interval is too large, it should decrease, but not by as much because we're
// switching direction.
intervalB := p.update(2)
require.Less(t, 30*time.Second, intervalB)
require.Greater(t, intervalA, intervalB)

// It should keep getting smaller.
intervalC := p.update(2)
require.Greater(t, intervalB, intervalC)

// Until we stabilize.
require.Equal(t, intervalC, p.update(1))
}

0 comments on commit 65865a7

Please sign in to comment.