-
Notifications
You must be signed in to change notification settings - Fork 137
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
Fix existing examples #387
Conversation
80420b2
to
be4f1ed
Compare
docker not available on macos runners in cirrus ci or github actions. licensing reasons on gha and because of apple virtulization restrictions for cirrus ci, which doesn't permit nested virtualization. I took a trip down ruby executable package lane, to look at packaging up the pact broker, as part of our pact-ruby-standalone bundle - can we make a pact broker available in the CI workflows, easily without docker. (we could just install ruby and pull down the pact broker which would be the easiest thing, but I do like a random adventure that scratches a few itches) It worked well for linux and macos, but for windows, is a no go, as it relies on natives gems for the pact broker, of which the traveling-ruby package doesn't provide. There are some windows projects that support packaging windows apps, with native extensions pact-foundation/pact-ruby-standalone#118 and also package into a single file. I thought it would be nice for macos and linux as well. That lead me to fixing up ruby-packer Mmm that was okay but there were issues loading native gems, which cropped up occasionally and I couldn't pin it down, so ended up thinking, why not try to roll my own. In doing so, I stumbled across a random SO post here I documented all my findings here https://gist.github.com/YOU54F/3775e66e6090e0371c11601e6b75c305 note if we got some hardware for self hosted runners, we could runner docker natively on mac, and not be using macos in a vm (with cirrus) |
I also made changes in my PR to support switching between using a hosted OSS broker that PactFlow provides (for ci/testing/poking around) I was hitting rate limits as the CI tests would run against x python versions on 3 OS's, and 2 arches, whilst using fix app version and branches, and the same consumer/provider names. We would be limited cos we are smashing the same endpoint with the same data xD adding the commit and branch from the actual branch/commit of the repo along with an identifier for --<ci_system> would be useful to avoid clashing, rate limiting and identification, back, in case of discrepancies between any of the generated artefacts (pact files in the examples case) |
Odd error in CI on Cirrus for MacOS and Linux on python 3.8 (which I can't replicate locally)
_multicall
res = hook_impl.function(*args)
File "/tmp/cirrus-ci-build/examples/conftest.py", line 24, in pytest_addoption
action=argparse.BooleanOptionalAction,
AttributeError: module 'argparse' has no attribute 'BooleanOptionalAction' seems to relate to https://nono.ma/attribute-error-module-argparse-has-no-attribute-boolean-optional-action odd how we don't see it in github actions! oh right this will make sense, we aren't running the examples on anythign other than the latest version, whereas we are running it across all the versions in cirrus https://github.com/pact-foundation/pact-python/actions/runs/6233729823/workflow#L56 Might just want to conditionally pass in diff args based on the python version note i get the same results with That's cool though, I can help you work out why that isn't working (it's probably something simple) timing wise, its really good compared to before. I've not dug into the example code setup too much today, just getting it running from the command line 👍🏾 Python 3.9 errors in macos / linux on cirrus ci
3.10 and 3.11 failing because they need docker. cirrus ci can support docker for linux workflows, macos can't though. https://cirrus-ci.org/guide/docker-builder-vm/#under-the-hood |
be4f1ed
to
fa68610
Compare
This PR is now ready for review. A note about merging this: It is built on top of #371 and therefore requires the latter to be merged before this one can be merged. I will be rebase this PR onto the new Thanks @YOU54F for all of the comments so far! With regards to the examples not running on Cirrus, I have opted to just disable them there. The test suite should detect regressions, unlike the example only serves to illustrate the use of |
cac28c0
to
8bb0bc2
Compare
For the purposes of showcasing an example, the previous `docker-compose` was rather excessive running the Pact Broker behind a Nginx proxy with a PostgreSQL backend. This simplifies the containers to just use the core Pact broker image and uses `sqlite` for the database. This commit also drops SSL/TLS from the example as it does not meaningfully contribute to the example. Signed-off-by: JP-Ellis <josh@jpellis.me>
This migrates the Pact FastAPI provider from the old standalone examples, and merges it with the new combined examples. The consumer tests are executed first which publishes the contracts with the broker. The provider test is then executed against the broker to verify compliance with the published contracts. This does, at this stage, create an unusual interdependence between tests which typically should be avoided. I plan to fix this at a later stage. Signed-off-by: JP-Ellis <josh@jpellis.me>
Following the changes to the FastAPI example, this migrates the Flask provider example to the new structure. The example relies on the consumer having published contracts, and the flask provider is verified against those contracts. Signed-off-by: JP-Ellis <josh@jpellis.me>
Update the README for the examples to match the new structure of the examples. Signed-off-by: JP-Ellis <josh@jpellis.me>
d3ceb98
to
e6ba7a9
Compare
Migrate the old isolated example and combine the test with the other examples so that they can all be run at once. Massive thanks to @YOU54F for identifying the switch up between the `given` and `expected`! Signed-off-by: JP-Ellis <josh@jpellis.me>
e6ba7a9
to
4d20c11
Compare
Try splitting the CI workflow to make use of services Signed-off-by: JP-Ellis <josh@jpellis.me>
4d20c11
to
c8e0e7f
Compare
In the latest changes:
This should be all good to merge 🥳 |
Initially, when having the tests completely separate, the examples were scoped to their own space and required setting `PYTHONPATH` to work. This is not needed if we change `import src.{mod}` to `import examples.src.{mod}`. Signed-off-by: JP-Ellis <josh@jpellis.me>
Philosophically, this makes sense to me. Especially as we look to introduce the BDD suite - making the examples be "regression" tests seems an abuse of them. |
I think I would like to test them x-plat/x-arch but its not a deal-breaker for me on this PR (it was only recently introduced by myself) - assuming they aren't covering anything already covered by the existing test suite. (They almost serve at integration/regression tests for me of the main code base, which may mark its own homework with its unit test suite)
I don't see why they can't be both. If they aren't full examples that someone can copy and paste, and they aren't regression tests, what are they then? What purpose are they trying to solve? Living documentation? Then I'd prefer they were tested against all supported platforms. I do think the BDD suite will be a great way of unifying examples across the different codebases, but I would see them both as serving as both examples and regression suites. |
Hey hey, Makefile consistencyFew comments around the Makefile, to help existing contributors, as it's in a bit of a limbo state post hatch.
.PHONY: test
test:
hatch run all
hatch run test:all
coverage report -m --fail-under=100 Example testing coveragePersonally I would prefer to see the examples tested against all the supported versions of Python. Currently this PR proposes only testing against the latest which isn't sufficient in my opinion. I think the code as proposed fails to run on 3.7/3.8 in the examples. This should be noted explicitly if we don't intend on testing this, as we are aware of it. DockerfileI needed to add broker:
image: pactfoundation/pact-broker:latest-multi
depends_on:
- postgres
ports:
- "9292:9292"
restart: always Machine deets 🕙17:55:45 ❯ sw_vers
ProductName: macOS
ProductVersion: 13.6
BuildVersion: 22G120
🕙17:58:59 ❯ uname -m
arm64
🕙17:59:05 ❯ python --version
Python 3.11.4
🕙17:59:10 ❯ docker --version
Docker version 24.0.6, build ed223bc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on the documenting in the examples, just reviewed all the comments and added some feedback / suggestions / typos.
Some comments above RE: the Makefile, would love just to have commands (make test/make example - out the box as part of this PR and we can make improvements down the line) so its not in a partially working state
Signed-off-by: JP-Ellis <josh@jpellis.me>
Thanks @YOU54F for the amazing review! I've addressed the inline comments and have fixed the Makefile. I've also made sure the examples run on Python 3.8. I still think that the e2e examples need not be run in the CI for all platforms, primarily because it relies on pulling and setting up a Docker image which slows things down a fair bit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for the update, looks great
This PR resolves #370.
When first picking up
pact-python
, I immediately ran into some issues with running the examples.This PR migrates the examples into a single test suite to be executed with
hatch run example
. This will (optionally) spin up the pact broker container, and maintain it across all consumer and provider examples.The idea for this example is to have the consumer run first and publish the contracts, and then to verify the providers against these contracts.
In doing so, I have also attempted to document rather explicitly the way the examples are written and how they might be used. It is not designed to replace the docs in any way, but hopefully will provide a much more hand-lead introduction for
pact-python
.