gateway tests: TestRestingKeyReadAgainInAnOrderedGroup lets the key be back already once the relay has answered with its limit raised (red on ubuntu CI at fb9d1a4c, run 37540375720: "resting: ko first, its rest <nil>") — since ee2588c2 a reading of the key's windows still out as it refused for quota is followed by another at once. When that second reading reaches the relay after the test raises the limit, it lifts the rest before the test plans again, which is right; the test asked for the rest to still stand there. It now accepts ko first and not resting when a reading saw the raised limit, and still wants kx first and ko resting otherwise. With the first reading held 100 ms and 200 ms between raising the limit and planning (a loaded CI runner), the old test fails as CI did and the new one passes. With ee2588c2's re-read taken out and the second reading held 300 ms, the new test still fails 2 of 2 ("still rests by window"). go test -race -count=40 -cpu 1,2,4 -run 'TestRestingKey|TestKey|Lone|Allowance' ./internal/gateway and go vet pass.
This commit is contained in:
1 parent
d688a8b43c
commit
3e38bd76dc
1 file changed
+12
-3
@@ -273,11 +273,14 @@ func TestRestingKeyReadAgainInAnOrderedGroup(t *testing.T) {
|
|||||||
t.Cleanup(func() { keyAllowance = old })
|
t.Cleanup(func() { keyAllowance = old })
|
||||||
week := time.Now().Add(72 * time.Hour).Truncate(time.Second).Format(time.RFC3339)
|
week := time.Now().Add(72 * time.Hour).Truncate(time.Second).Format(time.RFC3339)
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
limit, reads := 800, 0
|
limit, reads, raised := 800, 0, 0
|
||||||
relay := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
relay := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
l := limit
|
l := limit
|
||||||
reads++
|
reads++
|
||||||
|
if l > 800 {
|
||||||
|
raised++
|
||||||
|
}
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
fmt.Fprintf(w, `{"isValid":true,"mode":"quota_limited","status":"active","rate_limits":[{"window":"7d","limit":%d,"used":800,"remaining":%d,"reset_at":%q}]}`, l, l-800, week)
|
fmt.Fprintf(w, `{"isValid":true,"mode":"quota_limited","status":"active","rate_limits":[{"window":"7d","limit":%d,"used":800,"remaining":%d,"reset_at":%q}]}`, l, l-800, week)
|
||||||
}))
|
}))
|
||||||
@@ -324,8 +327,14 @@ func TestRestingKeyReadAgainInAnOrderedGroup(t *testing.T) {
|
|||||||
mu.Lock()
|
mu.Lock()
|
||||||
limit = 1000
|
limit = 1000
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
if at, r := first(); at != "kx" || r == nil {
|
// a reading out as the key refused is followed by another at once,
|
||||||
t.Fatalf("resting: %s first, its rest %v", at, r)
|
// which may have seen the limit raised and brought it back already
|
||||||
|
at, r := first()
|
||||||
|
mu.Lock()
|
||||||
|
seen := raised
|
||||||
|
mu.Unlock()
|
||||||
|
if (at != "kx" || r == nil) && (at != "ko" || r != nil || seen == 0) {
|
||||||
|
t.Fatalf("resting: %s first, its rest %v, the raised limit read %d times", at, r, seen)
|
||||||
}
|
}
|
||||||
for deadline := time.Now().Add(5 * time.Second); ; time.Sleep(10 * time.Millisecond) {
|
for deadline := time.Now().Add(5 * time.Second); ; time.Sleep(10 * time.Millisecond) {
|
||||||
r, ok := restOf(a.restKey())
|
r, ok := restOf(a.restKey())
|
||||||
|
|||||||
Reference in new issue
Block a user