-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BeforeEach method runs before every state #359
Comments
This is actually mentioned here: https://github.com/pact-foundation/pact-go/blob/master/docs/provider.md#lifecycle-of-a-provider-verification I'd be open to a PR that can find another way to address this. Also, thank you very much for taking the type to file a report and produce a repro 🙏 |
Ah, I'm sorry I missed that. I probably checked the javascript docs and not the golang. I wanted to create an issue for AfterEach which is not running when a test fails - is it also known or should I create it? |
And just for the record, I was able to workaround the beforeEach "issue" by using env vars like this:
and in stateHandler:
I know it is not nice but at least solved my issue. |
Thanks for confirming. Yes, this is definitely a way around it, albeit it's not nice. I'll leave this issue open, perhaps there is a way we can improve this. @JP-Ellis @uglyog the previous way that hooks were set up in Go (and JS) were attached to the lifecycle of the state handlers. Now that there may be many state handlers per test, it means that these hooks fire more frequently than previously. Is it a bad idea to create some "hook" mechanism in the core that clients can register to? |
The only way to do "hooks" with FFI is storing pointers to callback functions. This is not very safe. If the parameters differ, for instance, between what the caller expects and what the callback function has, it will result in undefined behavior. |
I was actually thinking a simple hook mechanism could be via HTTP, similar to the way provider states are managed. FFI clients could opt-in to the additional communications and the verifier could publish JSON events to it. Possibly it could be done over sockets or another local interface for better performance if needed. |
Software versions
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/katka/.cache/go-build"
GOENV="/home/katka/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/katka/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/katka/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.12"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/katka/hac/application-service/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2914814499=/tmp/go-build -gno-record-gcc-switches"
Expected behaviour
BeforeEach runs before every test/interaction.
Actual behaviour
BeforeEach runs before every state. AFAIK the multiple states during one interaction are supported as stated there.
In my case,
beforeEach
method is doing a cleanup of test environment. So I run into the situation when the first state creates some resource, but it is immediately cleaned before the second state is executed.Steps to reproduce
Provide a repository, gist or reproducable code snippet so that we can test the problem. You may also want to adapt one of the examples in the repository to demonstrate the problem.
https://github.com/Katka92/application-service/tree/non_working_before_each
Relevent log files
pact.json states:
The text was updated successfully, but these errors were encountered: