Skip to content

test: fix rpc_setban.py race - #16656

Merged
maflcko merged 1 commit into
bitcoin:masterfrom
jonasschnelli:2019/08/rpc_setban
Aug 21, 2019
Merged

maflcko merged 1 commit into
bitcoin:masterfrom
jonasschnelli:2019/08/rpc_setban

Conversation

@jonasschnelli

Copy link
Copy Markdown
Contributor

The new rpc_setban.py test failes regularly on CIs due to a race between injecting the ban and testing the log "on the other side".

The problem is, that the test immediately after the addnode command on node0 checks for the dropped (banned) entry on node1 (without giving some time).

Adding a 2 seconds sleep seems to solve the race (I guess there is no better event-driven delay).

Example of a failed test: https://bitcoinbuilds.org/index.php?ansilog=bf743910-103f-4b54-9a97-960c471061bd.log#l2906

@maflcko

maflcko commented Aug 19, 2019

Copy link
Copy Markdown
Member

I'd rather do this without a sleep. Wouldn't creating a dummy connection and waiting for it to open synchronize as well?

@jonasschnelli

Copy link
Copy Markdown
Contributor Author

Maybe the better way would be to add a timeout to assert_debug_log and check every second until the timeout is hit

@cvengler

Copy link
Copy Markdown

2 seconds are too much in my opinion.
I don't know the CI performance but I would go for 0.5 seconds

@maflcko

maflcko commented Aug 19, 2019

Copy link
Copy Markdown
Member

Maybe the better way would be to add a timeout to assert_debug_log and check every second until the timeout is hit

I am fine with either. Though, I suggest to set the default timeout for assert_debug_log to 0, as all existing calls to it are already synchronized.

@jonasschnelli
jonasschnelli force-pushed the 2019/08/rpc_setban branch 2 times, most recently from f2a4fea to 53714bd Compare August 20, 2019 09:02
@jonasschnelli

Copy link
Copy Markdown
Contributor Author

Switch to a retry/timeout approach with no delay for existing calls.

@DrahtBot

DrahtBot commented Aug 20, 2019 •

Copy link
Copy Markdown
Contributor

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #16673 (Relog configuration args on debug.log rotation by LarryRuane)
  • #16365 (Log RPC parameters (arguments) if -debug=rpcparams by LarryRuane)
  • #16115 (On bitcoind startup, write config args to debug.log by LarryRuane)

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.

@cvengler

Copy link
Copy Markdown

0.05 seconds are definitely better.
Concept ACK 6bdd6a0
Haven't tested it but the Travis linter is screaming around, you should check that out.

@NicolasDorier

NicolasDorier commented Aug 20, 2019 •

Copy link
Copy Markdown
Contributor

Sorry about that. Concept ACK, just I don't understand the yield part in the try block.

@NicolasDorier

NicolasDorier commented Aug 20, 2019 •

Copy link
Copy Markdown
Contributor

@jonasschnelli the while true and the break conditions must be inside the finally block if the problem is that the log just comes too late.

@jonasschnelli

Copy link
Copy Markdown
Contributor Author

the while true and the break conditions must be inside the finally block if the problem is that the log just comes too late.

Why? I guess we can get a fresh file position as well...

@NicolasDorier

NicolasDorier commented Aug 20, 2019 •

Copy link
Copy Markdown
Contributor

@jonasschnelli no you don't.

What you want to say is:

  1. Open the log at position prev_size (before try/finally)
  2. Do stuff (yield) the "stuff" is what is inside the with block of the caller.
  3. Starting from prev_size, until the pattern is found in the log, read the rest of logs (finally),
  4. repeat 3 until found or timeout

prev_size should not change at all from the time when the with block get open.

@jonasschnelli

Copy link
Copy Markdown
Contributor Author

@NicolasDorier
Oh. I see your point now. My understanding of pythons yield was incorrect.
Will fix...

@NicolasDorier

Copy link
Copy Markdown
Contributor

just discovered it myself. I wonder why we don't have this in C#... will complain to Microsoft. :p

@fanquake fanquake changed the title QA: fix rpc_setban.py race test: fix rpc_setban.py race Aug 21, 2019
@jonasschnelli

Copy link
Copy Markdown
Contributor Author

Fixed @NicolasDorier's point.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no need for this. python doesn't have scope blocks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will print only the last message

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

maflcko pushed a commit that referenced this pull request Aug 21, 2019
6011c9d QA: fix rpc_setban.py race (Jonas Schnelli)

Pull request description:

  The new `rpc_setban.py` test failes regularly on CIs due to a race between injecting the ban and testing the log "on the other side".

  The problem is, that the test immediately after the `addnode` command on node0 checks for the `dropped (banned)` entry on node1 (without giving some time).

  Adding a 2 seconds sleep seems to solve the race (I guess there is no better event-driven delay).

  Example of a failed test: https://bitcoinbuilds.org/index.php?ansilog=bf743910-103f-4b54-9a97-960c471061bd.log#l2906

Top commit has no ACKs.

Tree-SHA512: 680f8ea3e5ddb07e93f824f1aeff4a459e25e6c14715a39fc7670e50506d7cf25925348672c5c2d8ba3e1243ccf5effbc2456bcd094fb96868349f8d26e008f1
@maflcko
maflcko merged commit 6011c9d into bitcoin:master Aug 21, 2019
@NicolasDorier

Copy link
Copy Markdown
Contributor

ACK

deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 2, 2020
Summary:
This is a backport of Core [[bitcoin/bitcoin#16656 | PR16656]]

Depends on D5935

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D5936
ftrader pushed a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Aug 17, 2020
Summary:
This is a backport of Core [[bitcoin/bitcoin#16656 | PR16656]]

Depends on D5935

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D5936
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Nov 25, 2021
6011c9d QA: fix rpc_setban.py race (Jonas Schnelli)

Pull request description:

  The new `rpc_setban.py` test failes regularly on CIs due to a race between injecting the ban and testing the log "on the other side".

  The problem is, that the test immediately after the `addnode` command on node0 checks for the `dropped (banned)` entry on node1 (without giving some time).

  Adding a 2 seconds sleep seems to solve the race (I guess there is no better event-driven delay).

  Example of a failed test: https://bitcoinbuilds.org/index.php?ansilog=bf743910-103f-4b54-9a97-960c471061bd.log#l2906

Top commit has no ACKs.

Tree-SHA512: 680f8ea3e5ddb07e93f824f1aeff4a459e25e6c14715a39fc7670e50506d7cf25925348672c5c2d8ba3e1243ccf5effbc2456bcd094fb96868349f8d26e008f1
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
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