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

[IMP] CONTRIBUTING.rst: Improve testing flow for external API calls #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rousseldenis
Copy link
Sponsor

@rousseldenis
Copy link
Sponsor Author

@sbidoul

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating repositories is not an option. You are not going to have a delivery-carrier-ctt or similar repository. That's a nonsense. And the interference is minimal. We have way more problems due to library versions, architecture things, glitches, etc, than this.

So I don't agree with this.

@rousseldenis
Copy link
Sponsor Author

Separating repositories is not an option

If you want to do integration tests, that's the only viable one.

And the interference is minimal

That's a point of view. I don't agree on that.

Tests should be always reproducible. That's not the case with your implementation.

We have way more problems due to library versions, architecture things, glitches, etc, than this.

Maybe but that is more global problems that are fixed once. Here, this is very very random.

@pedrobaeza
Copy link
Member

Here we have a philosophical debate, as you consider different things from us for tests. We consider that tests should check the real thing as expected by the user. You consider an ideal thing that may not be the same as the reality.

And the random thing, it's true, but it's very unfrequent, which is the key. And when happens, it serves for notifying/taking other actions. Unrelated contributors receive a bit of inconvenience, but it's very transient, and you know that I'm not a passive agent that don't react quickly.

@rousseldenis
Copy link
Sponsor Author

you know that I'm not a passive agent that don't react quickly.

You are lucky to be able to act on external providers...

but it's very unfrequent,

At each time I touch something in delivery-carrier repository it happens (almost all build since yesterday are red...). So I'm very unfortunate...

@pedrobaeza
Copy link
Member

It's not red right now since this morning.

@rousseldenis
Copy link
Sponsor Author

It's not red right now since this morning.

Are you sure ?

https://github.com/OCA/delivery-carrier/actions/runs/7288283480/job/19860574284?pr=643

Copy link

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @pedrobaeza here. It's a tradeoff :

  • with mock :

    • tests works allways. 👍
    • Tests doesn't test if the module works. The API can totally fail and the test are still green. 👎
  • without mock :

    • test fails if API is not available / is unstable. 👎
    • test fails if API changed. 👍
    • less work to develop 👍

If a module make test failing because of API calls. 2 options :

  • fix module quickly.
  • if not, disable test, and let maintainers fix the issue.

@pedrobaeza
Copy link
Member

It's not red right now since this morning.

Are you sure ?

https://github.com/OCA/delivery-carrier/actions/runs/7288283480/job/19860574284?pr=643

Ouch, I have merged this morning one PR: OCA/delivery-carrier#746, so they are still performing changes, but the goal is achieved: we check this for possible API changes. I'm looking to see if we need to make changes in the module, as it seems now there's a required parameter.

@rousseldenis
Copy link
Sponsor Author

@legalsylvain If module is alone in its repo it does not harm anything, so I agree in that condition.

The problem appears when it impeach the flows of others.

Two major drawbacks I see:

  • Some contributors will see the red tests caused by another module. They don't come back as they consider the other module make tests red.
  • The red tests PR's are not considered from reviewers.

Such behavior refrain contributions and should be avoided.

@lmignon
Copy link
Sponsor

lmignon commented Dec 21, 2023

IMO, the goal is not achieved since it prevent a smooth review process of PR not related to randomly failing addons.

We can argue at length about whether or not it's appropriate to depend on an external api for a test. In my opinion, however, it's important to ensure that whatever the decision, it doesn't introduce additional constraints for developers of other modules in the same repository. In this sense, I think that isolating these modules in separate repos would offer a number of advantages. In addition to avoiding this Russian roulette at every PR or merge attempt, it would then be possible to set up a mechanism periodically testing the module even if no changes are made to it. This would enable maintainers to be notified as soon as the api used is no longer compatible with the module using it, without causing problems for developers of other modules.

@rousseldenis
Copy link
Sponsor Author

Indeed. @sbidoul I don't know if it is possible on github to have some crons to test an API ?

@legalsylvain
Copy link

Could you point real PR(s) where such problem occures ?
Thanks !

@rousseldenis
Copy link
Sponsor Author

rousseldenis commented Jan 25, 2024

@florian-dacosta
Copy link

I can only agree with the additional repo, on my side, It is not rare that I meet this issue when working on delivery-carrier repo.
Which does not make loose too much time once you know about it, but each new contributor that hits the problem loose a certain amount of time to understand what is wrong...

In a ideal world it is nice to test the real external api of course, but in reality the most frequent issue when tests fail is the unavailability of such api, who does it really help ? The failing tests don't point to any issue than need fixing, they just need to be re-run and have some luck !

@rvalyi
Copy link
Member

rvalyi commented Jan 29, 2024

Hello, for information in OCA/l10n-brazil we had a lot of issues external API's like this. A pragmatic way we worked around it is with this test decorator: https://github.com/OCA/l10n-brazil/blob/14.0/l10n_br_fiscal/tests/test_ibpt.py#L32

So as you can see (here for instance https://github.com/OCA/l10n-brazil/blob/14.0/l10n_br_fiscal/tests/test_ibpt_service.py#L35 ) we have a bit of the best worlds: we test against the external API only once a week (can be configured) and mock the tests the other days. Thus we never get the tests stuck for days but we still get a warning in just a few days if there is a change in the external service.

The only issue we have is that the test coverage will change bit from days to days. That is often have PR's which aren't entirely green because there is say 0.05% less test coverage (and of course we merge them anyway in this case).

Not sure it is the silver bullet, but may be this kind of work around can cut in for some of your use cases.

@rousseldenis
Copy link
Sponsor Author

Hello, for information in OCA/l10n-brazil we had a lot of issues external API's like this. A pragmatic way we worked around it is with this test decorator: https://github.com/OCA/l10n-brazil/blob/14.0/l10n_br_fiscal/tests/test_ibpt.py#L32

That's an optimistic decorator that implies API does not fail at least once a day 😅

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

Successfully merging this pull request may close these issues.

None yet

6 participants