Skip to content

Commit 136b4ba

Browse files
committed
extract outside of all loops in bench mark server_test
1 parent d76f29c commit 136b4ba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ func (s) TestStreamContext(t *testing.T) {
177177
}
178178

179179
func BenchmarkChainUnaryInterceptor(b *testing.B) {
180+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
181+
defer cancel()
180182
for _, n := range []int{1, 3, 5, 10} {
181183
n := n
182184
b.Run(strconv.Itoa(n), func(b *testing.B) {
@@ -192,8 +194,6 @@ func BenchmarkChainUnaryInterceptor(b *testing.B) {
192194
s := NewServer(ChainUnaryInterceptor(interceptors...))
193195
b.ReportAllocs()
194196
b.ResetTimer()
195-
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
196-
defer cancel()
197197
for i := 0; i < b.N; i++ {
198198
if _, err := s.opts.unaryInt(ctx, nil, nil,
199199
func(ctx context.Context, req any) (any, error) {

0 commit comments

Comments
 (0)