Skip to content

refactor: use jubilant for main integration tests#1507

Merged
dragomirp merged 17 commits into
16/edgefrom
refactor/16/jubilant
May 21, 2026
Merged

refactor: use jubilant for main integration tests#1507
dragomirp merged 17 commits into
16/edgefrom
refactor/16/jubilant

Conversation

@imanenami
Copy link
Copy Markdown

@imanenami imanenami commented Mar 5, 2026

Issue

Migration of tests to jubilant. All test files in the tests/integration root folder are migrated. HA & new_relations tests are skipped for now, to see how comfortable we are with this approach...

Solution

Experimented with an Adapter-based approach. Quick and easy. Each test file took 5-10 min. to migrate once the adapters module was mature.

Findings:

  • The model.block_until method of python-libjuju is hard to adapt, the current implementation tries to leverage jubilant.Juju.wait, but comes with a performance penalty.

Checklist

  • I have added or updated any relevant documentation.
  • I have cleaned any remaining cloud resources from my accounts.

@github-actions github-actions Bot added the Libraries: OK The charm libs used are OK and in-sync label Mar 5, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.43%. Comparing base (cda19e7) to head (4193ae9).

Additional details and impacted files
@@           Coverage Diff            @@
##           16/edge    #1507   +/-   ##
========================================
  Coverage    70.43%   70.43%           
========================================
  Files           15       15           
  Lines         4282     4282           
  Branches       694      694           
========================================
  Hits          3016     3016           
  Misses        1057     1057           
  Partials       209      209           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@imanenami imanenami added the enhancement New feature, UI change, or workload upgrade label Mar 5, 2026
@imanenami imanenami force-pushed the refactor/16/jubilant branch 6 times, most recently from 5a2b318 to 8ee09c4 Compare March 9, 2026 08:49
@imanenami imanenami changed the title refactor: use jubilant for backup tests refactor: use jubilant for main integration tests Mar 9, 2026
@imanenami imanenami force-pushed the refactor/16/jubilant branch 5 times, most recently from c764515 to cce8959 Compare March 9, 2026 15:12
@imanenami imanenami marked this pull request as ready for review March 10, 2026 09:58
@imanenami imanenami requested a review from a team as a code owner March 10, 2026 09:58
@imanenami imanenami requested review from carlcsaposs-canonical, dragomirp, juju-charm-bot, marceloneppel and taurus-forever and removed request for a team March 10, 2026 09:58
Copy link
Copy Markdown
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

Wow, this is massive, but promising.
LGTM from my side, but some questions first.
The decision here is on @marceloneppel

Comment thread tests/integration/jubilant_helpers.py
Comment thread tests/integration/jubilant_helpers.py
Comment thread tests/integration/jubilant_helpers.py Outdated
@taurus-forever
Copy link
Copy Markdown
Contributor

taurus-forever commented Mar 10, 2026

Also, I have noticed this backups:Restore failed: Unit cannot restore backup as it was not elected the leader unit yet

It looks like we are restoring backup having two units /0 and /1 ... once /1 is a leader the test failed.
The test must scaledown to one unit before restoring backup... is it a bug in test or in Jubilant/fixtures/scale-down? @imanenami , Tnx!

P.S. I do not recall such error in non-Jubilant tests

@marceloneppel
Copy link
Copy Markdown
Member

I suspect the issue @taurus-forever commented about (Unit cannot restore backup as it was not elected the leader unit yet) may be due to a bug in ModelAdapter.block_until (adapters.py:251-257):

def block_until(self, *conditions, timeout=None, wait_period=0.5):
    self._juju.wait(
        lambda status: all(conditions),
        ...
    )

conditions is a tuple of callable objects (due to *conditions packing — see Python docs). The built-in all() checks the truthiness of each element (Python docs), and since function objects are always truthy (Python docs — "By default, an object is considered true")), all(conditions) is always True regardless of what the conditions would actually return.

This would cause juju.wait() to return immediately without ever polling, so the scale-down wait in backup_helpers.py would complete instantly and the restore would run before the second unit is actually removed. The test may still pass sometimes due to incidental latency from Juju API calls and action dispatch giving Patroni enough time to converge, which would explain the flaky behavior.

If that's the case, the fix would be to actually call each condition:

lambda status: all(c() for c in conditions),

@imanenami
Copy link
Copy Markdown
Author

@taurus-forever @marceloneppel

Thanks Alex for spotting that, and special thanks to Marcello for finding the root cause, which I also think is the issue. I'll fix that 👍

@imanenami imanenami force-pushed the refactor/16/jubilant branch from c3cf05b to 1b927b2 Compare March 11, 2026 06:43
@imanenami imanenami marked this pull request as draft March 11, 2026 07:16
@imanenami imanenami marked this pull request as ready for review March 11, 2026 12:40
@imanenami imanenami dismissed stale reviews from dragomirp and marceloneppel via a51998f March 13, 2026 05:51
@imanenami imanenami force-pushed the refactor/16/jubilant branch from fb579ea to a51998f Compare March 13, 2026 05:51
@imanenami
Copy link
Copy Markdown
Author

imanenami commented Mar 13, 2026

@marceloneppel @dragomirp

Sorry for making the reviews stale, I just had to rebase and sign the commits, and did some final, small tidy ups in this commit: 4193ae9

I'd also like to thank all the reviewers who provided valuable input.

No need to mention that the decision to merge this or not is completely on the repo's maintainers, specially @marceloneppel. I have plans to make the migration full and remove pytest-operator dependency altogether in a follow-up PR (The same way I did in this Kafka PR) so I'd highly appreciate if we keep the branch and not delete it ❤️

marceloneppel
marceloneppel previously approved these changes Mar 13, 2026
Copy link
Copy Markdown
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

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

Thanks for the work on this, @imanenami! I've re-reviewed after the rebase, and the changes look good. Approving. Looking forward to the follow-up PR to go fully Jubilant-native, like the Kafka one! If the branch gets auto-deleted after the merge, we can restore it.

dragomirp
dragomirp previously approved these changes Mar 13, 2026
taurus-forever
taurus-forever previously approved these changes Mar 17, 2026
Copy link
Copy Markdown
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

Let's give it a try as 1) it works 2) build more experience and confidence in Jubilant 3) can help us merge PG14+PG16 tests.

We are open for AI tests rewrite to native Jubilant. @tonyandrewmeyer can you help us make it success story?

@tonyandrewmeyer
Copy link
Copy Markdown
Contributor

We are open for AI tests rewrite to native Jubilant. @tonyandrewmeyer can you help us make it success story?

Happy to help. I'll take a closer look tomorrow.

@dragomirp dragomirp dismissed stale reviews from taurus-forever, marceloneppel, and themself via ae49d3b May 17, 2026 09:51
Copy link
Copy Markdown
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

LGTM. Let's give it a try! Thank you Imam!

Comment thread tests/integration/jubilant_helpers.py
@dragomirp dragomirp merged commit 0f4ead3 into 16/edge May 21, 2026
190 of 192 checks passed
@dragomirp dragomirp deleted the refactor/16/jubilant branch May 21, 2026 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature, UI change, or workload upgrade Libraries: OK The charm libs used are OK and in-sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants