Hi! Is it possible to run pact consumer mocks insi...
# pact-js
c
Hi! Is it possible to run pact consumer mocks inside a pact provider test? When I do it, I’m getting an
ECONNREFUSED
error when my code tries to contact the consumer (but if I have a dedicated test that is just loading the consumer, everything works as expected).
consumer-provider.js
m
Why do you want to do this?
y
Agreed, what is your use case here?
c
Right. I figured I might need to answer that. I’m trying to establish contracts around our graphql server. I’ve successfully put contracts up for things that are depending on it, but I wanted to use the opportunity provided by the provider tests on the graphql server side to establish contracts on the providers that the graphql server uses, so that if a requirement for a particular API disappeared from the graphql consumer, and that implied that we no longer needed a contract with a provider, that contract would disappear.
I understand the recommendations not to put contracts on passthough services, but graphql is doing a bunch of data reformulation, so it’s not a strict passthrough. I could mock out the providers used by the graphql server during its own provider tests, but using the consumer wire mocks instead seemed to give an extra advantage (as outlined above)
m
You can definitely test GraphQL, I wouldn’t think that’s an issue
I can’t see where you are setting up the mock expectations though?
In any case, it’s going to be hard to use the mock service, because you won’t be able to target the mocks at a very granular level. You could do it, but I see it being a difficult setup to maintain
c
I elided the interactions out (line 36). My issue is that I’m getting
ECONNREFUSED
from the consumer mock while running my provider tests. If I just manually use the same interactions, and manually set up a single consumer test, I can get it to work. So either I have something wrong w/ the consumer-inside-provider-test setup (around ordering, maybe, or correct `await`s), or there’s something in the FFI libs that’s preventing me from running both provider driver and consumer driver at the same time
My supposition, at the moment, is that the upstream states will give me enough info to correctly set the downstream state expectations. That will really only be borne out one way another w/ time, but I have to get past this technical issue first
👍 1
m
or there’s something in the FFI libs that’s preventing me from running both provider driver and consumer driver at the same
it’s possible, albeit I think it should be able to work. It’s not a use case we have really considered in supporting
If you were able to put together a small repro for us to look into, we could take a look into it. It looks like a clever setup, that’s for sure
c
I’ll try to extract a minimal example out (may end up solving my problem while doing so, if I figure out what the minimal requirements are)
Ok, finally got back to this. https://github.com/pact-foundation/pact-js/compare/master...cale-at-reify:pact-js:provider-provider-test is the changes I made to the graphql test case in the pact-js repo to reproduce the error.
provider test error log.txt
Hopefully the problem is something easy, like I’m not waiting in the correct place for the upstream provider to start. But I think maybe the provider and consumer are fighting over the ffi, or something like that