Katerina Foniok
08/25/2023, 1:25 PMafterEach
method. But in the logs I can see:
2023-08-25T13:18:39.954253Z INFO ThreadId(13) pact_verifier: Running teardown provider state change handler <mystate> for <mygiven>
LOG: createAppAndComponents method was executed
2023/08/25 15:18:39 http: panic serving [::1]:52442:
Your test failed.
The LOG
here is logged from the function that is supposed to be run just for the setup of provider. I'm a bit confused with that. Is there some documentation/example that I can check?
I'll put a snippet of my code to the thread. Thank you!Katerina Foniok
08/25/2023, 1:27 PMverifyRequest.StateHandlers = models.StateHandlers{
"App myapp exists and has component gh-component and quay-component": <-createAppAndComponents(HASAppNamespace),
}
and the function in the second file (will shorten it for better readability)
func createAppAndComponents(HASAppNamespace string) <-chan models.StateHandler {
stateHandler := make(chan models.StateHandler)
go func() {
defer close(stateHandler)
stateHandler <- func(setup bool, s models.ProviderState) (models.ProviderStateResponse, error) {
println("LOG: createAppAndComponents method was executed")
<my logic there>
return nil, nil
}
}()
return stateHandler
}
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Katerina Foniok
08/28/2023, 1:34 PMverifyRequest.StateHandlers = models.StateHandlers{
"App myapp exists and has component gh-component and quay-component": createAppAndComponents(HASAppNamespace),
}
and the method itself:
func createAppAndComponents(HASAppNamespace string) models.StateHandler {
var stateHandler = func(setup bool, s models.ProviderState) (models.ProviderStateResponse, error) {
<some logic>
}
return stateHandler
}
and this is log from the run:
023-08-28T13:30:06.724217Z INFO ThreadId(13) pact_verifier: Running provider verification for 'Get app with its components.'
2023-08-28T15:30:06+02:00 INFO Stopping and waiting for webhooks
2023-08-28T15:30:06+02:00 INFO Wait completed, proceeding to shutdown the manager
2023-08-28T13:30:06.724298Z INFO ThreadId(13) pact_verifier::provider_client: Sending request to provider at <http://localhost:44835/>
2023-08-28T13:30:06.724307Z INFO ThreadId(13) pact_verifier::provider_client: Sending request HTTP Request ( method: GET, path: /apis/appstudio.redhat.com/v1alpha1/namespaces/default/applications/myapp, query: None, headers: Some({"Content-type": ["application/json"]}), body: Missing )
2023-08-28T13:30:06.728033Z INFO ThreadId(13) pact_verifier::provider_client: Received response: HTTP Response ( status: 200, headers: Some({"content-length": ["1990"], "content-type": ["application/json"], "audit-id": ["1661d23b-781f-4cb2-b6ce-8c0483154de9"], "date": ["Mon, 28 Aug 2023 13:30:06 GMT"], "cache-control": ["no-cache", "private"], "x-kubernetes-pf-prioritylevel-uid": ["ad80173c-8794-407b-b8e8-4832c173cd9f"], "x-kubernetes-pf-flowschema-uid": ["c0ea09c8-f75f-416a-a4e9-f5bc9e03116b"]}), body: Present(1990 bytes, application/json) )
2023-08-28T13:30:06.728067Z INFO ThreadId(13) pact_matching: comparing to expected response: HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(1063 bytes) )
2023-08-28T13:30:06.728824Z INFO ThreadId(13) pact_verifier: Running teardown provider state change handler 'App myapp exists and has component gh-component and quay-component' for 'Get app with its components.'
LOG: createAppAndComponents method was executed
2023/08/28 15:30:06 http: panic serving [::1]:33954:
Your test failed.
Ginkgo panics to prevent subsequent assertions from running.
Normally Ginkgo rescues this panic so you shouldn't see it.
But, if you make an assertion in a goroutine, Ginkgo can't capture the panic.
To circumvent this, you should call
defer GinkgoRecover()
at the top of the goroutine that caused this panic.
goroutine 705 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1825 +0xbf
panic({0x2285b20, 0x2da9290})
/usr/local/go/src/runtime/panic.go:844 +0x258
<http://github.com/onsi/ginkgo.Fail(|github.com/onsi/ginkgo.Fail(>{0xc000cbda40, 0x13f}, {0xc000ca4568?, 0xc000cbda40?, 0xc000e5b680?})
/home/katka/go/pkg/mod/github.com/onsi/ginkgo@v1.16.5/ginkgo_dsl.go:291 +0xdd
<http://github.com/onsi/gomega/internal.(*Assertion).match(0xc00030df80|github.com/onsi/gomega/internal.(*Assertion).match(0xc00030df80>, {0x2dc48e0, 0x437e1c8}, 0x1, {0x0, 0x0, 0x0})
/home/katka/go/pkg/mod/github.com/onsi/gomega@v1.24.1/internal/assertion.go:106 +0x1f0
<http://github.com/onsi/gomega/internal.(*Assertion).Should(0xc00030df80|github.com/onsi/gomega/internal.(*Assertion).Should(0xc00030df80>, {0x2dc48e0, 0x437e1c8}, {0x0, 0x0, 0x0})
/home/katka/go/pkg/mod/github.com/onsi/gomega@v1.24.1/internal/assertion.go:50 +0xb5
<http://github.com/redhat-appstudio/application-service/controllers.createAppAndComponents.func1(0x0|github.com/redhat-appstudio/application-service/controllers.createAppAndComponents.func1(0x0>?, {{0xc0012f1590?, 0xc000494c30?}, 0x42?})
/home/katka/hac/application-service/controllers/application_pact_test_state_handlers.go:46 +0x457
<http://github.com/pact-foundation/pact-go/v2/provider.stateHandlerMiddleware.func1.1({0x2dd44b0|github.com/pact-foundation/pact-go/v2/provider.stateHandlerMiddleware.func1.1({0x2dd44b0>, 0xc000a5e8c0}, 0xc0012ed400)
/home/katka/go/pkg/mod/github.com/pact-foundation/pact-go/v2@v2.0.0-beta.23/provider/verifier.go:295 +0x6b4
net/http.HandlerFunc.ServeHTTP(0x2db87a0?, {0x2dd44b0?, 0xc000a5e8c0?}, 0x440f76?)
/usr/local/go/src/net/http/server.go:2084 +0x2f
<http://github.com/pact-foundation/pact-go/v2/proxy.chainHandlers.func1.1(|github.com/pact-foundation/pact-go/v2/proxy.chainHandlers.func1.1(>{0x2dd44b0, 0xc000a5e8c0}, 0xc000ac1240?)
/home/katka/go/pkg/mod/github.com/pact-foundation/pact-go/v2@v2.0.0-beta.23/proxy/http.go:68 +0x90
net/http.HandlerFunc.ServeHTTP(0x0?, {0x2dd44b0?, 0xc000a5e8c0?}, 0x413305?)
/usr/local/go/src/net/http/server.go:2084 +0x2f
net/http.serverHandler.ServeHTTP({0x2dc0e78?}, {0x2dd44b0, 0xc000a5e8c0}, 0xc0012ed400)
/usr/local/go/src/net/http/server.go:2916 +0x43b
net/http.(*conn).serve(0xc0009121e0, {0x2dd5b08, 0xc000b13dd0})
/usr/local/go/src/net/http/server.go:1966 +0x5d7
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3071 +0x4db
2023-08-28T13:30:06.730080Z ERROR ThreadId(13) pact_verifier: Provider teardown state change for 'App myapp exists and has component gh-component and quay-component' has failed - MismatchResult::Error("Invalid response: error sending request for url (<http://localhost:44835/__setup>): connection closed before message completed", None)
Katerina Foniok
08/28/2023, 3:04 PMfunc createAppAndComponents(HASAppNamespace string) models.StateHandler {
var stateHandler = func(setup bool, s models.ProviderState) (models.ProviderStateResponse, error) {
if !setup {
println("skipping state handler")
return nil, nil
}
...
}
}
but I would rather know where the hell is that setup bool being setup to false... 😄 Is there some doc about how to use the teardown? I've gone through the pact-go code briefly, but haven't found that yet. ThanksKaterina Foniok
08/28/2023, 3:06 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Katerina Foniok
08/29/2023, 7:59 AMStateHandler (post)
and it basically means the tear down method. I though it is something else. It was also not clear to me from the doc that it is required to have this switch as the same method will run twice. Sorry, it's probably just my misunderstanding. Thank you for your time, help and kindness 🙂