Skip to content
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 hook is executed before each state handler rather than just once per provider test #288

Closed
nsfrias opened this issue May 2, 2023 · 3 comments

Comments

@nsfrias
Copy link

nsfrias commented May 2, 2023

Software versions

  • OS: Mac OSX 13.0.1
  • Consumer Pact library: Pact go v2.0.0-beta.18
  • Golang Version: go1.19.8 darwin/arm64

Expected behaviour

The BeforeEach hook should execute once per provider test, before any of the provider state handlers are executed (and definitely not on clear down).

Actual behaviour

The BeforeEach hook is executed before each provider state both on setup and cleanup.

Steps to reproduce

Run the TestV3HTTPProvider from v2.x.x branch link here, and check that [DEBUG] HOOK before each log line appears before each log line denoting the provider state handler execution: [INFO] executing state handler middleware .

Relevent log files

https://gist.github.com/nsfrias/f4007fc681bbd1b0d33e9f1a6d4bdd44

@github-actions
Copy link

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-1175). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

@mefellows
Copy link
Member

The order should now be fixed, with the caveat that because there are now the possibility of multiple states, and the execution of the Before/After hooks is tied to the state handlers (for technical reasons which I don't think we can change), the sequence would look like this:

  • Before All hook (started by state handler 1)
  • State handler 1 - setup
  • Before All hook (started by state handler n)
  • State handler 1...n - setup
  • Request filter (if HTTP)
  • Actual test
  • State handler n - teardown
  • After hook (started by state handler n)
  • State handler n..1 - teardown
  • After hook (started by state handler 1)

I've updated the docs to reflect this.

@mefellows
Copy link
Member

Fixed in v2.0.0-beta.23.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants