Page MenuHomePhabricator

[electrum] fix flaky tear-down in functional tests
ClosedPublic

Authored by PiRK on Apr 16 2024, 10:52.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC88ea3ea9d12e: [electrum] fix flaky tear-down in functional tests
Summary

When the daemon stop command in called in the fulcrum_service's tear-down, it returns before all the the threads are terminated. In particular the wallet files still need to be saved before the daemon process exits. This causes a race condition when the test fixture deletes the data directory while WalletStorage._write creates a tmp file then deletes it. See https://github.com/python/cpython/pull/14064 for a description of how shutil.rmtree ends up raising a FileNotFoundError.

This issue will go away in Python 3.13 when shutil.rmtree no longer fails because it failed to delete an already deleted file. In the meantime ignore these failures.

I first tried a different approach: wait for the daemon process to actually terminate before deleting the data. However detecting the correct deamon process is not trivial, and if done wrong could cause more flakiness.

Test Plan

pytest electrumabc/tests/regtest

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Apr 16 2024, 10:52
Fabien requested changes to this revision.Apr 16 2024, 11:29
Fabien added a subscriber: Fabien.
Fabien added inline comments.
electrum/electrumabc/tests/regtest/util.py
233 ↗(On Diff #47193)

I think you should mimic what's being done upstream, and only ignore if the missing file is not the root datadir (aka the rmtree arg itself).

This revision now requires changes to proceed.Apr 16 2024, 11:29

Talked offline, there is not much that can be done and we just want to rm the dir which this achieves.

This revision is now accepted and ready to land.Apr 16 2024, 11:38