Page MenuHomePhabricator

[electrum] regtest: refactor poll_for_answer
ClosedPublic

Authored by PiRK on Nov 22 2023, 16:13.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCe27c05152401: [electrum] regtest: refactor poll_for_answer
Summary

Make the function easier to understand and remove a few indentation levels by removing the unnecessary retry flag and reorganizing the code a bit.
There is no change in behavior.

Depends on D14838

Test Plan

pytest electrumabc/tests/regtest

Diff Detail

Repository
rABC Bitcoin ABC
Branch
electrum_flaky_test
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 25707
Build 50994: Build Diffelectrum-tests
Build 50993: arc lint + arc unit

Event Timeline

PiRK requested review of this revision.Nov 22 2023, 16:13
electrum/electrumabc/tests/regtest/util.py
72 ↗(On Diff #43219)

continue skips the rest of this iteration and restarts from the top of the loop's scope.

Fabien requested changes to this revision.Nov 22 2023, 16:33
Fabien added a subscriber: Fabien.
Fabien added inline comments.
electrum/electrumabc/tests/regtest/util.py
66 ↗(On Diff #43219)

Don't put a condition here, move it at the end of the loop (no need to wait unconditionally) and make sure to break before the sleep if the expected state is achieved

This revision now requires changes to proceed.Nov 22 2023, 16:33
electrum/electrumabc/tests/regtest/util.py
66 ↗(On Diff #43219)

The drawback for this is that I will have to repeat the sleep before each exits (continue statements)

move time.sleep to the ends of the iteration instead of gating it on current != start

Fabien requested changes to this revision.Nov 23 2023, 09:19
Fabien added inline comments.
electrum/electrumabc/tests/regtest/util.py
68

You don't update current time, this could be an infinite loop.

You could create a local function to make it simpler.

Too bad there is no goto with python, this is where it is useful.

This revision now requires changes to proceed.Nov 23 2023, 09:19

fix potential infirnite loop

This revision is now accepted and ready to land.Nov 23 2023, 12:20
This revision was automatically updated to reflect the committed changes.