summaryrefslogtreecommitdiffstats
path: root/client/go/internal/vespa/document/throttler_test.go
blob: b386e0d5105f3d24b4e673fa63e7fafae855c7d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package document

import (
	"testing"
	"time"
)

func TestThrottler(t *testing.T) {
	clock := &manualClock{tick: time.Second}
	tr := newThrottler(8, clock.now)

	if got, want := tr.TargetInflight(), int64(16); got != want {
		t.Errorf("got TargetInflight() = %d, but want %d", got, want)
	}
	for i := 0; i < 30; i++ {
		tr.Sent()
		tr.Success()
	}
	if got, want := tr.TargetInflight(), int64(18); got != want {
		t.Errorf("got TargetInflight() = %d, but want %d", got, want)
	}
	tr.Throttled(34)
	if got, want := tr.TargetInflight(), int64(17); got != want {
		t.Errorf("got TargetInflight() = %d, but want %d", got, want)
	}
}