My team in the organization works in erlang and we...
# general
p
My team in the organization works in erlang and we have taken an initiative towards using Pact as a contract testing tool for http communication as well as message based communication between services (which can be erlang based or non erlang based). I along with the help of some other folks in my team has done PoC for this as well, and now we want to create a library ‘Pact-erlang’ so that other erlang folks in the community can use this as well !! And for that I would need help from you guys 😃
🙌 2
🎉 2
t
What kind of help do you need?
p
Hey @Timothy Jones, thanks for asking. Firstly, the PoC i have done is on my local machine which is mac, and during consumer side testing (which also will write the pact after all unit tests are complete), i start up the pact-mock-provider service via erlang as part of my unit test initialization and before my unit tests are executed, it should be up and running. I faced issues permission issues when executing the pact-mock-service binary via erlang. I had to manually allow these binaries in system-preferences, and only then i was able to start up the pact-mock-provider. Can you tell me a better way to handle this ?
t
I’m not actually a maintainer any more, but I can give some pointers.
Which library are you using?
It sounds like you might be using the Ruby service, which is to be deprecated
p
https://github.com/pact-foundation/pact-mock_service I am using this as the mock-provider
t
Right, yeah. I would recommend using the Rust implementation, as it has more features
It exposes a C API which you can probably link against. This is what pact-js and pact-net do.
And pact-go too, I think
p
ohh i see, so you are saying I should use FFIs ?
t
That’s the pattern, yeah
I think there’s a guide somewhere
👍 1
Hm, I can’t find the guide
If an example would help, here’s how pact-js does the verification: https://github.com/pact-foundation/pact-js-core/blob/master/src/verifier/nativeVerifier.ts
You’ll also need the ability to create matchers. I don’t believe these are documented, but a good resource for them is pact-js’s matcher code. Let me get you a link
p
I have some experience of js, let me go through this implementation then
t
I had to manually allow these binaries in system-preferences, and only then i was able to start up the pact-mock-provider.
In short, I think you can avoid this by incorporating Pact into your erlang package (module? I don’t know what erlang calls them) instead of invoking a separate binary
The Rust core will do its own spin up and teardown of the server, so you won’t need to muck about in your test harness
I was involved in some (but not all) of the conversion of pact-js to the Rust core, so I should be able to answer some (but not all) of your questions
(if you have them)
p
I see, thanks a lot, much appreciated. I guess my first step should be looking the js implementation and take inspiration from there
as it uses FFIs , which also supports message pacts
👍 1
t
I’m also working on an alternative contract testing framework, that is philosophically compatible with Pact (and definitely compatible with the Pact broker). I’m currently working on the cross-language boundary, which isn’t ready for consumption yet. But, it’s designed to be easier to create wrappers for
👀 2
I would start with Pact, though, as it’s ready today
👍 1
(and has a well established community)
You can follow it here if you’re interested: https://case.contract-testing.io/docs/intro
🙌 1
it works today in JS, but it’s very beta.
m
oh it has a logo - awesome Tim!
Thanks for those tips Tim. @Priyaranjan Mudliar - we are about to kickoff some work around maintainer experience. The key artifacts to emerge from this will be a guide for maintainers, and a BDD suite to use as a basis to test your implementation. In lieu of that, your best bet is to follow a previous implementation (as Tim has suggested) and jump in #C02BXLDJ7JR - we can help. There are a few others on this journey, such as @Tien Vo working on PHP. We’re here to help, it might be a little bumpy given the lack of good maintainer docs. But you’re not the first to do it
👍 1
y
woop woop! pact erlang sound very cool! no overly familiar with erlang but you might want to take a look at https://github.com/elitau/pact_elixir
i haven’t used it or studied the code so your mileage might vary. we’ve had a fair few over the last couple of weeks asking about the ffi implementation, details on how to use it as a consumer and some reference documentation. the code for me has always been the best source of truth, but appreciate its hard if you don’t know where to look. i’m going to look at setting up an bit of an intro / workshop and tutorial, can i assume that you would be interested? cc: @Adam Cox i think you asked about this re pact-cplus-plus
🙌 2
a
@Yousaf Nabi (pactflow.io) yes a few people in my team have been using the ffi in C++ to create sync message pacts. intro / workshop and tutorial with some reference documentation would be much appreciated on our side I think. We have managed to put something together by reading the source code but it has been a bit trial and error
🙌 2
m
Let’s make it happen. Great idea Yousaf
🙌 1
p
I would be very much interested in this if it happens !!
But before that I would want to go through the JS implementation myself, so that i have context before any such session
@Yousaf Nabi (pactflow.io) Any intro/workshop/tutorial for the ffi implementation would be much appreciated
y
solid, will see what we can rustle up. i’ll be sure to cover from the ground up, so you can come in relatively fresh, and we can build it up over a few sessions
i’m out at the moment but will put together some initial pointers on a docs page which shows where the reference code ( the pact ffi library lives ), which platforms we aim to support, how we can test it and which implementations currently use it, and where exactly in the code is it done. it will help us identify gaps between implementations, and hopefully feed into the cores design decisions as anything emergent arises
some architecture details on the ffi https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/ARCHITECTURE.md examples of loading the shared library in various languages https://github.com/YOU54F/hello_ffi the install.md has instructions on how to run on various platforms some raw examples in python and php which call the ffi methods directly https://github.com/pact-foundation/pact-reference/pull/269/files these are normally wrapped in a dsl which is idiomatic for the client language, but ultimately should expose the same feature set across all the client libs. there are some blurred lines as some functionality a ) needs to reside in the client libs to handle talking to the ffi and the user as an intermediary b ) some func is in the client only, and not exposed in the core, which can lead to apparent feature disparity between languages.
thankyou 1
p
Thanks a lot for all the pointers @Yousaf Nabi (pactflow.io), after going through this pr https://github.com/pact-foundation/pact-reference/pull/269/files i think i understood how i would implement something like this in erlang. Its a great resource for the ffi library usage. Now the only part i think i would need to understand is how i will introduce the cbinding thing in erlang.
👍 1