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

provider is not evaluating expression for 'application/x-thrift' protocol in 4.2.2 version #1330

Closed
iankurrathi opened this issue Mar 23, 2021 · 9 comments

Comments

@iankurrathi
Copy link
Contributor

iankurrathi commented Mar 23, 2021

With 4.2.2 version of pact, noticed that provider is not evaluating expression for 'application/x-thrift' protocol.

To provide background info, we pushed a PR as part of issue #1298 which allows to use json matcher for application/x-thrift protocol. In version 4.1.17 this change was working fine and expression were evaluating properly - getting value from state method.

In another issue #1318, array matching issue related to arrayContaining() was fixed in version 4.2.2.

However after upgrading pact version to 4.2.2, we have noticed that expressions are not getting value from state method for 'application/x-thrift' protocol.
With application/json or application/x-thrift+json protocol, expressions are fine.

I can see that json matcher is being used for 'application/x-thrift' protocol so code for issue 1298 is being merged into 4.2.2 (i can also verify this in git 4.2.x branch).

In terms of debug, I can see that invokeStateChangeMethods() function of PactVerificationStateChangeExtension calls my state method which sets expression value into map, then in beforeTestExecution() function provider state is set to testContext:
testContext.executionContext = mapOf("providerState" to providerStateContext)

after that when flow comes to context.verifyInteraction(); method of my provider test class, i can see request still having example parameter set by consumer instead of provider's state method parameter.

Logs also say that state method is invoked:

23 Mar 2021 12:26:50,485 DEBUG PactVerificationStateChangeExtension:33 [main] beforeEach for interaction 'test request'
23 Mar 2021 12:27:04,659  INFO PactVerificationStateChangeExtension:103 [main] Invoking state change method 'test request':SETUP

Verifying a pact between test-consumer and test-provider for tag test-tag

@uglyog
Copy link
Member

uglyog commented Mar 27, 2021

With the change applied to fix #1314 you can now set the type for the content type with the pact.content_type.override.application/x-thrift system property set to json.

See https://github.com/pact-foundation/pact-jvm/blob/master/provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/ThriftStateInjectedProviderTest.groovy#L38 for an example.

@iankurrathi
Copy link
Contributor Author

Thanks Ronald.
I have this property set in both my consumer and producer test. Its also using json body matcher because of this property, however doesn't replace the expression value from state method.

@uglyog
Copy link
Member

uglyog commented Mar 30, 2021

@keeping-it-up can you have a look at the test I posted above, that works when I run it.

@iankurrathi
Copy link
Contributor Author

iankurrathi commented Apr 12, 2021

@uglyog, I have run the test your referenced and it works.
However I have added a new test which has application/x-thrift content type header in json file and uses expression in request body - this test doesn't work. In this draft PR: #1340
It doesn't replace id value to abc and hence request doesn't match.

If I remove header part from request section of json file:

"headers": {
          "Content-Type": ["application/x-thrift"]
        }

then it starts to work.

Thanks.

@iankurrathi
Copy link
Contributor Author

hi @uglyog, we have put a fix for this issue and a test case which now works after the fix: #1340

can you please review and merge if you are happy? please also release a new version so we can unblock our story.
Thanks.

@uglyog
Copy link
Member

uglyog commented Apr 21, 2021

PR has been merged

@iankurrathi
Copy link
Contributor Author

thanks @uglyog, can you let me know if you have done a release and release number please? thanks.

@uglyog
Copy link
Member

uglyog commented May 9, 2021

4.2.5 has been released

@iankurrathi
Copy link
Contributor Author

Works now, cheers.

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