-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ratelimiter returns resource exhausted error
This is necessary so that when it is used with the backoff retry it will allow for the backoff to continue to work as expected. Signed-off-by: Nathan Zender <github@nathanzender.com>
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package grpcclient_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/cortexproject/cortex/pkg/util/grpcclient" | ||
) | ||
|
||
func TestRateLimiterFailureResultsInResourceExhaustedError(t *testing.T) { | ||
config := grpcclient.Config{ | ||
RateLimitBurst: 0, | ||
RateLimit: 0, | ||
} | ||
conn := grpc.ClientConn{} | ||
invoker := func(currentCtx context.Context, currentMethod string, currentReq, currentRepl interface{}, currentConn *grpc.ClientConn, currentOpts ...grpc.CallOption) error { | ||
return nil | ||
} | ||
|
||
limiter := grpcclient.NewRateLimiter(&config) | ||
err := limiter(context.Background(), "methodName", "", "expectedReply", &conn, invoker) | ||
|
||
if se, ok := err.(interface { | ||
GRPCStatus() *status.Status | ||
}); ok { | ||
assert.Equal(t, se.GRPCStatus().Code(), codes.ResourceExhausted) | ||
assert.Equal(t, se.GRPCStatus().Message(), "rate: Wait(n=1) exceeds limiter's burst 0") | ||
} else { | ||
assert.Fail(t, "Could not convert error into expected Status type") | ||
} | ||
} |