This file is indexed.

/usr/share/gocode/src/github.com/influxdb/influxdb/services/hh/limiter_test.go is in golang-github-influxdb-influxdb-dev 0.10.0+dfsg1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package hh

import (
	"testing"
	"time"
)

func TestLimiter(t *testing.T) {
	l := NewRateLimiter(0)
	l.Update(500)
	if l.Delay().Nanoseconds() != 0 {
		t.Errorf("limiter with no limit mismatch: got %v, exp 0", l.Delay())
	}
}

func TestLimiterWithinLimit(t *testing.T) {
	if testing.Short() {
		t.Skip("Shipping TestLimiterWithinLimit")
	}

	l := NewRateLimiter(1000)
	for i := 0; i < 100; i++ {
		// 50 ever 100ms = 500/s which should be within the rate
		l.Update(50)
		l.Delay()
		time.Sleep(100 * time.Millisecond)
	}

	// Should not have any delay
	delay := l.Delay().Seconds()
	if exp := int(0); int(delay) != exp {
		t.Errorf("limiter rate mismatch: got %v, exp %v", int(delay), exp)
	}

}

func TestLimiterExceeded(t *testing.T) {
	l := NewRateLimiter(1000)
	for i := 0; i < 10; i++ {
		l.Update(200)
		l.Delay()
	}
	delay := l.Delay().Seconds()
	if int(delay) == 0 {
		t.Errorf("limiter rate mismatch. expected non-zero delay")
	}
}