-
Notifications
You must be signed in to change notification settings - Fork 37.7k
test: add wait_for_cookie_credentials() to framework for rpcwait tests #18691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add wait_for_cookie_credentials() to framework for rpcwait tests #18691
Conversation
The error was " Called Process failed with 'error: Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set. See -rpcpassword and -stdinrpcpass. Configuration file: (/home/travis/build/bitcoin/bitcoin/ci/scratch/test_runner/test_runner_₿_🏃_20200417_132645/interface_bitcoin_cli_109/node0/bitcoin.conf) " |
Yes. I'm still looking at it, but since valgrind runs don't work out-of-repo, I wanted to see if the valgrind CI passes with this change while looking further. |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
8854851
to
b726718
Compare
Btw, this happens on cirrus reliably: https://cirrus-ci.com/task/6597545033990144?command=functional_test#L1053 |
Or, if you want to test locally: diff --git a/src/httprpc.cpp b/src/httprpc.cpp
index 60c4d06f12..3dd06c4758 100644
--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -291,6 +291,7 @@ static bool InitRPCAuthentication()
bool StartHTTPRPC()
{
LogPrint(BCLog::RPC, "Starting HTTP RPC server\n");
+ UninterruptibleSleep(std::chrono::seconds{11});
if (!InitRPCAuthentication())
return false;
|
b726718
to
ecafe40
Compare
Thanks @MarcoFalke for your suggestions! Being able to reproduce makes all the difference. I updated the PR title and description and pushed a fix that seems to work. |
ecafe40
to
72a079e
Compare
I see that the CI for the latest merge on master (bump wallet_import timeout) failed for this same reason: https://travis-ci.org/github/bitcoin/bitcoin/jobs/676639823 |
5c7e759
to
83b0379
Compare
Simplified. Edit: FWIW I considered adding the following but don't think it's necessary? IIUC + except OSError as e:
+ if e.errno != errno.ECONNREFUSED: # Port not yet open?
+ raise # Unknown OS error
- except ValueError:
- pass
+ except ValueError as e: # Cookie file not found and no rpcuser or rpcassword; bitcoind still starting.
+ if "No RPC credentials" not in str(e):
+ raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 83b0379
Happy to merge with or without feedback addressed. Just let me know what you prefer.
user, passphrase = get_auth_cookie(self.datadir, self.chain) | ||
self.log.debug("Cookie credentials retrieved: user={}, passphrase={}".format(user, passphrase)) | ||
return | ||
except ValueError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: In a future cleanup the three occurrences of ValueError
can be changed to a self-made error RpcMissingCred
(or so). Not asking you to do this here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: In a future cleanup the three occurrences of
ValueError
can be changed to a self-made errorRpcMissingCred
(or so). Not asking you to do this here.
Good idea. Will look at a follow-up.
83b0379
to
e67a1e2
Compare
Took the suggestions. |
e67a1e2
to
790fb95
Compare
to be able to ensure the cookie file is written and auth credentials available when testing CLI/RPC commands before the RPC connection is up.
by calling wait_for_cookie_credentials() to ensure the cookie file is written and auth credentials available for testing the CLI -rpcwait option before the RPC connection is up.
790fb95
to
92fe537
Compare
Rebased and added a docstring to |
…work for rpcwait tests 92fe537 test: fix intermittent race condition in interface_bitcoin_cli.py (Jon Atack) c648e63 test: add wait_for_cookie_credentials() to test framework (Jon Atack) Pull request description: This PR adds a `wait_for_cookie_credentials()` method to the test framework and calls it before the `-rpcwait` tests, to avoid an intermittent race condition on the CI run with Valgrind where the cookie file isn't written yet when the CLI call with `-rpcwait` arrives to `get_auth_cookie()`. To reproduce/test, build with ```diff diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 60c4d06..3dd06c4758 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -291,6 +291,7 @@ static bool InitRPCAuthentication() bool StartHTTPRPC() { LogPrint(BCLog::RPC, "Starting HTTP RPC server\n"); + UninterruptibleSleep(std::chrono::seconds{11}); if (!InitRPCAuthentication()) ``` then run the test normally and with valgrind ``` test/functional/interface_bitcoin_cli.py -l debug valgrind test/functional/interface_bitcoin_cli.py -l debug ``` Thanks to Marco Falke for all the help. Closes bitcoin#18684. Top commit has no ACKs. Tree-SHA512: 1b76635b5b1d6b05138affef7ab788aa3bc3fc75b0c69ba778ecdf81063cfe02a8dd7667cfd63a6c6e19b2dac47d7a8b755e334d8af5c0ab9d4026808ee96c83
…d_cli() in debug log 8f5dc88 test: display command line options passed to send_cli() in debug log (Jon Atack) Pull request description: as per bitcoin#18691 (comment), and revert two cli calls changed in bitcoin#18691 from rpc commands back to command line options (these were the only occurrences). ACKs for top commit: MarcoFalke: ACK 8f5dc88 Tree-SHA512: fcb3eca00aa4099066028c90d5e50a02e074366e09a17f5f5b937d9f7562dd054ff65681aa0ad4c94f6de1e98b1e2b9ac4cd084ddc297010253989a80483b1b9
…d_cli() in debug log 8f5dc88 test: display command line options passed to send_cli() in debug log (Jon Atack) Pull request description: as per bitcoin#18691 (comment), and revert two cli calls changed in bitcoin#18691 from rpc commands back to command line options (these were the only occurrences). ACKs for top commit: MarcoFalke: ACK 8f5dc88 Tree-SHA512: fcb3eca00aa4099066028c90d5e50a02e074366e09a17f5f5b937d9f7562dd054ff65681aa0ad4c94f6de1e98b1e2b9ac4cd084ddc297010253989a80483b1b9
to be able to ensure the cookie file is written and auth credentials available when testing CLI/RPC commands before the RPC connection is up. Github-Pull: bitcoin#18691 Rebased-From: c648e63
by calling wait_for_cookie_credentials() to ensure the cookie file is written and auth credentials available for testing the CLI -rpcwait option before the RPC connection is up. Github-Pull: bitcoin#18691 Rebased-From: 92fe537
Summary: > test: add wait_for_cookie_credentials() to test framework > > to be able to ensure the cookie file is written and auth credentials available > when testing CLI/RPC commands before the RPC connection is up. > test: fix intermittent race condition in interface_bitcoin_cli.py > > by calling wait_for_cookie_credentials() to ensure the cookie file is written > and auth credentials available for testing the CLI -rpcwait option before the > RPC connection is up. This is a backport of Core [[bitcoin/bitcoin#18691 | PR18691]] Test Plan: ``` diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 9e09af5..8301f8cd1 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -453,6 +453,7 @@ static bool InitRPCAuthentication() { bool StartHTTPRPC(HTTPRPCRequestProcessor &httpRPCRequestProcessor) { LogPrint(BCLog::RPC, "Starting HTTP RPC server\n"); + UninterruptibleSleep(std::chrono::seconds{11}); if (!InitRPCAuthentication()) { return false; } ``` `ninja && test/functional/test_runner.py interface_bitcoin_cli` Reviewers: #bitcoin_abc, deadalnix, Fabien Reviewed By: #bitcoin_abc, deadalnix, Fabien Subscribers: Fabien, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D8947
This PR adds a
wait_for_cookie_credentials()
method to the test framework and calls it before the-rpcwait
tests, to avoid an intermittent race condition on the CI run with Valgrind where the cookie file isn't written yet when the CLI call with-rpcwait
arrives toget_auth_cookie()
.To reproduce/test, build with
then run the test normally and with valgrind
Thanks to Marco Falke for all the help. Closes #18684.