Skip to content

An exception occurs when adding multiple proto definitions in the TestContainer. #1404

@Allen0117

Description

@Allen0117

Describe the bug

I found that when only one proto definition is added, my test case passes successfully; however, once more than one is added, the following error occurs.
When reporting the issue, I found the behavior to be quite unstable—it sometimes passes and sometimes fails.

Exception Detail

[testcontainers.org 00:00:04.18] Error adding ProtoDefinition 'gifting'.
System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.Net.Http.HttpIOException: The response ended prematurely. (ResponseEnded)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at RestEase.Implementation.Requester.SendRequestAsync(IRequestInfo requestInfo, Boolean readBody)
   at RestEase.Implementation.Requester.RequestAsync[T](IRequestInfo requestInfo)
   at WireMock.Net.Testcontainers.WireMockContainer.CallAdditionalActionsAfterStartedAsync()
[testcontainers.org 00:00:04.19] Error adding ProtoDefinition 'gifting'.
System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.
 ---> System.Net.Sockets.SocketException (54): Connection reset by peer
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
   at System.Net.Http.HttpConnection.InitialFillAsync(Boolean async)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at RestEase.Implementation.Requester.SendRequestAsync(IRequestInfo requestInfo, Boolean readBody)
   at RestEase.Implementation.Requester.RequestAsync[T](IRequestInfo requestInfo)
   at WireMock.Net.Testcontainers.WireMockContainer.CallAdditionalActionsAfterStartedAsync()
[testcontainers.org 00:00:04.19] Error adding ProtoDefinition 'gifting'.
System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.
 ---> System.Net.Sockets.SocketException (54): Connection reset by peer
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
   at System.Net.Http.HttpConnection.InitialFillAsync(Boolean async)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at RestEase.Implementation.Requester.SendRequestAsync(IRequestInfo requestInfo, Boolean readBody)
   at RestEase.Implementation.Requester.RequestAsync[T](IRequestInfo requestInfo)
   at WireMock.Net.Testcontainers.WireMockContainer.CallAdditionalActionsAfterStartedAsync()
[testcontainers.org 00:00:04.19] Error adding ProtoDefinition 'gifting'.
System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.
 ---> System.Net.Sockets.SocketException (54): Connection reset by peer
   --- End of inner exception stack trace ---

Test code

_wireMockContainer = new WireMockContainerBuilder()
            .AddUrl("http://*:1081")
            .AddUrl("grpc://*:1082")
            .AddProtoDefinition("transfer", transferSource, customDatetimeSource, customDecimalSource, requestSource, responseSource)
            .AddProtoDefinition("gifting", giftingSource, customDatetimeSource, customDecimalSource, requestSource, responseSource)
            .WithPortBinding(10801, 1081)
            .WithPortBinding(10802, 1082)
            .WithHttp2()
            .Build();

await _wireMockAdminApi.PostMappingAsync(new MappingModel
        {
            Guid = Guid.NewGuid(),
            Request = new RequestModel
            {
                Path = new PathModel()
                {
                    Matchers =
                    [
                        new MatcherModel()
                        {
                            Name = "WildcardMatcher",
                            Pattern = "/transfer.Transfer/TransferBonus",
                            IgnoreCase = false,
                        }
                    ]
                },
                Methods = ["POST"],
                Body = new BodyModel()
                {
                    Matcher = new MatcherModel()
                    {
                        ProtoBufMessageType = "TransferBonusRequest",
                        Name = "ProtoBufMatcher",
                    }
                }
            },
            Response = new ResponseModel
            {
                BodyAsJson = new { ErrorCode = 101 },
                UseTransformer = true,
                TransformerType = "Handlebars",
                TransformerReplaceNodeOptions = "EvaluateAndTryToConvert",
                Headers = new Dictionary<string, object>
                {
                    { "Content-Type", "application/grpc" }
                },
                TrailingHeaders = new Dictionary<string, object>
                {
                    { "grpc-status", StatusCode.OK.ToString("D") }
                },
                ProtoBufMessageType = "TransferBonusResponse",
            },
            ProtoDefinition = "transfer"
        });
        
        
        var transferClient = new Transfer.Transfer.TransferClient(_grpcChannel);
        

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions