Skip to content

test: Replace threading with concurrent.futures - #27287

Merged
fanquake merged 1 commit into
bitcoin:masterfrom
maflcko:2303-test-check-return-value-😝
Mar 23, 2023

Hidden character warning

The head ref may contain hidden characters: "2303-test-check-return-value-\ud83d\ude1d"
Merged

fanquake merged 1 commit into
bitcoin:masterfrom
maflcko:2303-test-check-return-value-😝

Conversation

@maflcko

@maflcko maflcko commented Mar 21, 2023

Copy link
Copy Markdown
Member

threading has no easy way to get the return value or exception once the target function stops. Not checking the return value or exception can make tests more fragile and failures harder to debug.

Fix this by checking the return value (or exception) by wrapping the function execution into a future and calling result() on it.

Can be reviewed with --ignore-all-space.

(There are still some uses of threading around, because some tests do expect an exception to be thrown and caught in the target function)

@DrahtBot

DrahtBot commented Mar 21, 2023 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ishaanam, stickies-v

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #22838 (descriptors: Be able to specify change and receiving in a single descriptor string by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@ishaanam ishaanam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK fa0696e
Thanks for working on this, these changes should help figure out the occasional failures.

@stickies-v stickies-v left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK fa0696e


encrypted_wallet.walletpassphrase("passphrase", 99999)
t = threading.Thread(target=encrypted_wallet.importdescriptors, args=([descriptor],))
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as thread:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I think thread is a misnomer, even with just 1 worker it's still a pool or executor.

@fanquake
fanquake merged commit 483fb8d into bitcoin:master Mar 23, 2023
@maflcko
maflcko deleted the 2303-test-check-return-value-😝 branch March 23, 2023 17:00
@bitcoin bitcoin locked and limited conversation to collaborators Mar 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants