Open danhlee329 opened 4 years ago
So, are you saying you've removed the catch
statement from your block of code?
That could explain the issue.
On that line in the verifier, we start a proxy service to perform administration and other stuff to do the verification process. We handle the success and fail case by closing the server, and returning a Promise. If you're not handling the fail
case, it's possible there is an open file handle.
But doing a cursory Google, there are tonnes of issues that suggest Jest can be overly eager and reports "potential" file handles as well as actual.
Can you confirm the file handle is indeed open?
I should clarify that I've added the catch
to the block in my test, which is not present in the e2e source above. My test runs the same with the warning with or without the catch
after the verification. Is there another step required on my end or possible the issue is in the verification logic?
I did a bit of Googling, i'd be interested to know if the common strategy of "added a wait" essentially solves it. That indicates that it's just Jest being overly aggressive. Are you able to provide a reproduceable example people could use to fix/address it?
I will provide a working example later today, thanks!
Here is the example I'm using.
NOTE: this was setup in a PoC, so it may be a bit rough:
const { Verifier } = require("@pact-foundation/pact")
const path = require("path")
// Verify that the provider meets all consumer expectations
describe("Pact Verification", () => {
it("validates the expectations of the Apollo Federation Service", () => {
// let token = "INVALID TOKEN"
let opts = {
provider: "testprovider",
logLevel: "DEBUG",
providerBaseUrl: "http://localhost:3999",
requestFilter: (req, res, next) => {
next()
},
stateHandlers: { },
// Fetch pacts from broker
pactBrokerUrl: "http://localhost:9292/",
// Fetch from broker with given tags
consumerVersionTag: ["master"],
// Tag provider with given tags
providerVersionTag: ["master"],
// Enables "pending pacts" feature
enablePending: true,
publishVerificationResult: true,
providerVersion: "1.0.0",
}
return new Verifier(opts).verifyProvider().then(output => {
console.log("Pact Verification Complete!")
console.log(output)
}).catch(e => console.log(e))
})
})
I am experiencing the same issue, I managed to work around it by running jest --force-exit ...
you could resolve the promise by adding a reference to the function and calling it when is done,
describe("Pact Verification", () => { it("validates the expectations of the Apollo Federation Service", (done) => { return new Verifier(opts).verifyProvider().then(output => { console.log("Pact Verification Complete!") console.log(output) done(); }).catch(e => {console.log(e); done();}) }) })
I'm having the same problem, pact hangs the execution on verifying the pacts and jest does not exit
--force-exit or --forceExit?
I don't think catching the promise result from the verifier is the safest approach - it will return a success promise to jest even in a failure.
If this is still happening, what happens if you run jest with --detectOpenHandles
?
Software versions
I've setup both consumer, provider, and pact broker locally and successfully got the consumer contract verified via the provider test (all tests pass). However, in the provider test, I am running into this Jest warning:
This chunk of code (except the
.catch(e => console.log(e)
) was taking from https://github.com/pact-foundation/pact-js/blob/3d2e7ddc2a06d92d2d8f5a246d014b92cd7331a2/examples/e2e/test/provider.spec.js#L96How do I resolve this warning and is there documentation on this? Possible bug? Couldn't find anything on this warning in the Pact docs. Thanks!