Skip to content

Commit 88ea3ea

Browse files
committed
[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 python/cpython#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` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D15989
1 parent c0fceec commit 88ea3ea

File tree

1 file changed

+7
-1
lines changed
  • electrum/electrumabc/tests/regtest

1 file changed

+7
-1
lines changed

electrum/electrumabc/tests/regtest/util.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import os
23
import platform
34
import shutil
@@ -225,7 +226,12 @@ def fulcrum_service(docker_services: Any) -> Generator[None, None, None]:
225226
yield
226227
stop_ec_daemon(electrum_datadir)
227228
finally:
228-
shutil.rmtree(electrum_datadir)
229+
# Remove the data directory, ignore race conditions caused by tmp wallet files
230+
# created and deleted in WalletStorage._write while the daemon process is
231+
# stopping
232+
# See https://github.com/python/cpython/pull/14064
233+
with contextlib.suppress(FileNotFoundError):
234+
shutil.rmtree(electrum_datadir)
229235

230236

231237
def wait_for_len(json_req, expected_len: int, timeout=DEFAULT_TIMEOUT):

0 commit comments

Comments
 (0)