(t *testing.T)
| 329 | } |
| 330 | |
| 331 | func (s) TestChainStreamServerInterceptor(t *testing.T) { |
| 332 | callCounts := make([]atomic.Int32, 4) |
| 333 | |
| 334 | firstInt := func(srv any, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error { |
| 335 | if callCounts[0].Load() != 0 { |
| 336 | return status.Errorf(codes.Internal, "callCounts[0] should be 0, but got=%d", callCounts[0].Load()) |
| 337 | } |
| 338 | if callCounts[1].Load() != 0 { |
| 339 | return status.Errorf(codes.Internal, "callCounts[1] should be 0, but got=%d", callCounts[1].Load()) |
| 340 | } |
| 341 | if callCounts[2].Load() != 0 { |
| 342 | return status.Errorf(codes.Internal, "callCounts[2] should be 0, but got=%d", callCounts[2].Load()) |
| 343 | } |
| 344 | if callCounts[3].Load() != 0 { |
| 345 | return status.Errorf(codes.Internal, "callCounts[3] should be 0, but got=%d", callCounts[3].Load()) |
| 346 | } |
| 347 | callCounts[0].Add(1) |
| 348 | return handler(srv, stream) |
| 349 | } |
| 350 | |
| 351 | secondInt := func(srv any, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error { |
| 352 | if callCounts[0].Load() != 1 { |
| 353 | return status.Errorf(codes.Internal, "callCounts[0] should be 1, but got=%d", callCounts[0].Load()) |
| 354 | } |
| 355 | if callCounts[1].Load() != 0 { |
| 356 | return status.Errorf(codes.Internal, "callCounts[1] should be 0, but got=%d", callCounts[1].Load()) |
| 357 | } |
| 358 | if callCounts[2].Load() != 0 { |
| 359 | return status.Errorf(codes.Internal, "callCounts[2] should be 0, but got=%d", callCounts[2].Load()) |
| 360 | } |
| 361 | if callCounts[3].Load() != 0 { |
| 362 | return status.Errorf(codes.Internal, "callCounts[3] should be 0, but got=%d", callCounts[3].Load()) |
| 363 | } |
| 364 | callCounts[1].Add(1) |
| 365 | return handler(srv, stream) |
| 366 | } |
| 367 | |
| 368 | lastInt := func(srv any, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error { |
| 369 | if callCounts[0].Load() != 1 { |
| 370 | return status.Errorf(codes.Internal, "callCounts[0] should be 1, but got=%d", callCounts[0].Load()) |
| 371 | } |
| 372 | if callCounts[1].Load() != 1 { |
| 373 | return status.Errorf(codes.Internal, "callCounts[1] should be 1, but got=%d", callCounts[1].Load()) |
| 374 | } |
| 375 | if callCounts[2].Load() != 0 { |
| 376 | return status.Errorf(codes.Internal, "callCounts[2] should be 0, but got=%d", callCounts[2].Load()) |
| 377 | } |
| 378 | if callCounts[3].Load() != 0 { |
| 379 | return status.Errorf(codes.Internal, "callCounts[3] should be 0, but got=%d", callCounts[3].Load()) |
| 380 | } |
| 381 | callCounts[2].Add(1) |
| 382 | return handler(srv, stream) |
| 383 | } |
| 384 | |
| 385 | sopts := []grpc.ServerOption{ |
| 386 | grpc.ChainStreamInterceptor(firstInt, secondInt, lastInt), |
| 387 | } |
| 388 |
nothing calls this directly
no test coverage detected