pact-foundation / pact-go

Golang version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
http://pact.io
MIT License
860 stars 109 forks source link

Transport error when running gRPC provider verification in 2.x.x branch #260

Open jasonltaylor opened 1 year ago

jasonltaylor commented 1 year ago

Software versions

Expected behaviour

Pact provider verification for gRPC contract runs successfully.

Actual behaviour

Provider verification fails with transport error.

Steps to reproduce

Run gRPC contract tests with latest 2.x.x codebase. The tests pass when pinned to v2.0.0-beta.17 tag but fail if using the tip of the 2.x.x branch.

Relevent log files

2023/01/04 15:40:41 [ERROR] net/http: HTTP/1.x transport connection broken: malformed HTTP status code "\x00\xfe\x03\x00\x00\x00\x01\x00\x00\x04\b\x00\x00\x00\x00\x00\x00?\x00\x00"
2023/01/04 15:40:41 http: proxy error: net/http: HTTP/1.x transport connection broken: malformed HTTP status code "\x00\xfe\x03\x00\x00\x00\x01\x00\x00\x04\b\x00\x00\x00\x00\x00\x00?\x00\x00"
mefellows commented 1 year ago

Thanks Jason. Do you have a particular setup you could share that produces this issue? We run gRPC examples as part of the build and I haven't seen this, so I'm guessing it's perhaps the use of request filters causing the proxy issues?

jasonltaylor commented 1 year ago

Was able to narrow it down today. I wasn't explicitly passing the Transports to VerifyProvider which up until now had been working ok. If I add that in my provider verification is passing. Can get the pact-go example gRPC provider to fail with the same error by commenting that out:

$ git diff grpc_provider_test.go
diff --git a/examples/grpc/grpc_provider_test.go b/examples/grpc/grpc_provider_test.go
index 8b8c873..34d47ef 100644
--- a/examples/grpc/grpc_provider_test.go
+++ b/examples/grpc/grpc_provider_test.go
@@ -1,6 +1,3 @@
-//go:build provider
-// +build provider
-
 package grpc

 import (
@@ -30,12 +27,12 @@ func TestGrpcProvider(t *testing.T) {

        err := verifier.VerifyProvider(t, provider.VerifyRequest{
                ProviderBaseURL: "http://localhost:8222",
-               Transports: []provider.Transport{
-                       provider.Transport{
-                               Protocol: "grpc",
-                               Port:     8222,
-                       },
-               },
+               // Transports: []provider.Transport{
+               //      provider.Transport{
+               //              Protocol: "grpc",
+               //              Port:     8222,
+               //      },
+               // },
                Provider: "grpcprovider",
                PactFiles: []string{
                        filepath.ToSlash(fmt.Sprintf("%s/../pacts/grpcconsumer-grpcprovider.json", dir))
YOU54F commented 1 year ago

hmmm, I think I noticed this or something similar, where the transports are actually being picked up from the pact file, (in which the interaction specifies the protocol and plugin/plugin version)

not directly in testing pact-go, but generally testing the plugin framework

mefellows commented 1 year ago

Thanks Jason. I think some documentation will help this, and possibly there is something we can do to guard in Pact Go.

Basically, the core will attempt to use the same transport for all plugins if others aren't given to it. That might be sensible, but the errors aren't exactly clear.

jasonltaylor commented 1 year ago

ok - wasn't sure if just a regresssion since the client contract has the transport defined in it.