This PR adds a functional test for -startupnotify. It basically starts the node passing a command on -startupnotify to create a file on tmp and then, we check if the file has been successfully created.
test: add functional test for -startupnotify #23532
pull brunoerg wants to merge 1 commits into bitcoin:master from brunoerg:2021-11-test-startupnotify changing 2 files +42 −0-
brunoerg commented at 12:58 AM on November 17, 2021: member
- fanquake added the label Tests on Nov 17, 2021
-
lsilva01 commented at 2:08 AM on November 17, 2021: contributor
Concept ACK.
Perhaps the test with valid command can create a file in test or
tmpdir and checks if this file was created.. -
DrahtBot commented at 4:29 AM on November 17, 2021: member
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #22776 (rpc/wallet: add optional transaction(s) to getbalances by kallewoof)
- #22751 (rpc/wallet: add simulaterawtransaction RPC by kallewoof)
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.
- brunoerg force-pushed on Nov 17, 2021
- brunoerg force-pushed on Nov 17, 2021
-
brunoerg commented at 11:22 AM on November 17, 2021: member
I've tried different valid commands with -startupnotify like:
echo(common command for Unix system and Windows), tried a simplelsfor Unix anddirfor Windows and other ones, but the CI is failing for all of them. Any thoughts about it, @MarcoFalke? -
MarcoFalke commented at 11:29 AM on November 17, 2021: member
You can find the error in the log:
node0 stderr Error: The experimental syscall sandbox feature (-sandbox=<mode>) is incompatible with -startupnotify (which uses execve). -
brunoerg commented at 11:53 AM on November 17, 2021: member
You can find the error in the log:
node0 stderr Error: The experimental syscall sandbox feature (-sandbox=<mode>) is incompatible with -startupnotify (which uses execve).Sorry, I read that but didn't notice this part of the log. Thanks.
- brunoerg force-pushed on Nov 17, 2021
- brunoerg force-pushed on Nov 17, 2021
-
theStack commented at 1:28 PM on November 17, 2021: member
Concept ACK
-
brunoerg commented at 5:31 PM on November 17, 2021: member
Force-pushed with a update on
expected_stderrinstop_node. I just edited the description. - brunoerg force-pushed on Nov 17, 2021
- brunoerg force-pushed on Nov 18, 2021
- brunoerg force-pushed on Nov 18, 2021
-
brunoerg commented at 6:35 PM on November 18, 2021: member
Win64 has failed: <img width="1060" alt="Screen Shot 2021-11-18 at 10 23 47" src="https://user-images.githubusercontent.com/19480819/142430123-5ed41a77-3173-4442-85ae-6f37654921b6.png">
I think the problem may be the breaklines. Going to work to fix it.
- brunoerg force-pushed on Nov 18, 2021
- brunoerg force-pushed on Nov 18, 2021
-
brunoerg commented at 10:51 AM on November 19, 2021: member
Force-pushed adding
os.linesepinto expected windows message. -
in test/functional/feature_startupnotify.py:31 in e9ebe3b96e outdated
26 | + self.stop_node(0) 27 | + self.log.info("Test the node starts with an invalid command on -startupnotify") 28 | + self.start_node(0, extra_args=[f"-startupnotify={INVALID_COMMAND}"]) 29 | + 30 | + stderrs = [f"sh: {INVALID_COMMAND}: command not found", f"sh: 1: {INVALID_COMMAND}: not found", 31 | + f"AssertionError: Unexpected stderr '{INVALID_COMMAND}' is not recognized as an internal or external command,{os.linesep}operable program or batch file."]
stratospher commented at 6:22 PM on November 20, 2021:In e9ebe3b, shouldn't it be this?
f"'{INVALID_COMMAND}' is not recognized as an internal or external command,{os.linesep}operable program or batch file."]
MarcoFalke commented at 7:31 AM on November 21, 2021:Do we need tests for to check the operating systems exact response to an invalid command? This doesn't increase the test coverage of Bitcoin Core itself and it seems a bit painful to maintain.
brunoerg commented at 11:17 AM on November 21, 2021:I agree it seems a bit painful to maintain, but if we don't pass an expected error message the test will fail. I think the stop_node could have a boolean flag when expecting error without specifing the message it would be helpful. What do you think?
brunoerg commented at 11:38 AM on November 21, 2021:Not sure if the right is:
f"'{INVALID_COMMAND}' is not recognized as an internal or external command,{os.linesep}operable program or batch file."]orf"Unexpected stderr '{INVALID_COMMAND}' is not recognized as an internal or external command,{os.linesep}operable program or batch file."Going to test it, thanks!
brunoerg commented at 11:06 AM on November 22, 2021:Both of them didn't work.
stratospher commented at 12:49 PM on November 24, 2021:
brunoerg commented at 1:01 PM on November 24, 2021:My bad, I hadn't notice this one on L351. Going to test again, thanks!
brunoerg force-pushed on Nov 21, 2021brunoerg force-pushed on Nov 21, 2021brunoerg force-pushed on Nov 21, 2021brunoerg force-pushed on Nov 24, 2021in test/functional/feature_startupnotify.py:31 in b0fc9f9e22 outdated
26 | + self.stop_node(0) 27 | + self.log.info("Test the node starts with an invalid command on -startupnotify") 28 | + self.start_node(0, extra_args=[f"-startupnotify={INVALID_COMMAND}"]) 29 | + 30 | + stderrs = [f"sh: {INVALID_COMMAND}: command not found", f"sh: 1: {INVALID_COMMAND}: not found", 31 | + f"'{INVALID_COMMAND}' is not recognized as an internal or external command,{os.linesep}operable program or batch file."]
luke-jr commented at 7:57 PM on November 30, 2021:This seems shell-specific and not reliable for a test
brunoerg commented at 1:53 PM on December 1, 2021:I am going to re-write this test to not considering this part.
luke-jr changes_requestedluke-jr commented at 7:59 PM on November 30, 2021: memberIdeally, a test for
-startupnotifyshould ensure that the command is executed exactly once, and when it is executed, the node is fully started (which may involve races which make it difficult to deterministically fail).brunoerg force-pushed on Dec 3, 2021brunoerg commented at 12:50 PM on December 3, 2021: memberForce-pushed addressing the reviews, thanks everyone for them. I just changed the approach for this test (updated the description).
in test/functional/feature_startupnotify.py:21 in 31931a5ab0 outdated
16 | + self.extra_args = [["-startupnotify=echo 'test' >> node0/test.txt"]] 17 | + 18 | + def run_test(self): 19 | + tmpdir = os.path.join(self.options.tmpdir, "node0", "test.txt") 20 | + 21 | + self.log.info("When node starts, check if test.txt exists")
jonatack commented at 8:07 PM on December 7, 2021:self.log.info("Test -startupnotify command is run when node starts")
brunoerg commented at 9:23 PM on December 7, 2021:Thank you for the suggestions, they are very relevant, I am going to implement them.
jonatack commented at 8:12 PM on December 7, 2021: memberACK 31931a5ab009256bf583025939e6e3ca2f875d9a
A couple of ideas, feel free to ignore/pick/choose:
- Begin by testing the absence of
tmpdirwithout-startupnotifybefore asserting on its presence with the option - Maybe abstract the magic strings to constants
from test_framework.test_framework import BitcoinTestFramework +NODE_DIR = "node0" +FILE_NAME = "test_123_xyz" class StartupNotifyTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 self.disable_syscall_sandbox = True - self.extra_args = [["-startupnotify=echo 'test' >> node0/test.txt"]] def run_test(self): - tmpdir = os.path.join(self.options.tmpdir, "node0", "test.txt") + tmpdir = os.path.join(self.options.tmpdir, NODE_DIR, FILE_NAME) + assert not os.path.exists(tmpdir) self.log.info("When node starts, check if test.txt exists") + self.restart_node(0, extra_args=[f"-startupnotify=echo '{FILE_NAME}' >> {NODE_DIR}/{FILE_NAME}"]) assert os.path.exists(tmpdir)jonatack commented at 8:24 PM on December 7, 2021: memberIdeally, a test for
-startupnotifyshould ensure that the command is executed exactly once, and when it is executed, the node is fully started (which may involve races which make it difficult to deterministically fail).Maybe checking the expected result of an RPC (like getblockcount) could verify the node is fully up.
brunoerg force-pushed on Dec 7, 2021brunoerg force-pushed on Dec 7, 2021jonatack commented at 12:51 PM on December 8, 2021: memberACK, modulo unrelated code that appears to have crept into the last push?
brunoerg commented at 3:57 PM on December 10, 2021: memberACK, modulo unrelated code that appears to have crept into the last push?
omg, didn't understand why it happened, going to check it.
brunoerg force-pushed on Dec 21, 2021Davidson-Souza commented at 8:02 PM on December 22, 2021: nonetested ACK 98014c5
OS: Arch Linux 64 bits (Linux 5.12.19-hardened1-1-hardened x86_64) System: AMD Ryzen 5 64 bits + AMD VEGA 8 with 12GB RAM Build: Compiled from source with no additional
./configureoptionsTests: Ran the test alone, it worked!
Also, all the tests with test/functional/test_runner.py, again everything is working just fine!
in test/functional/feature_startupnotify.py:29 in 98014c5a88 outdated
24 | + tmpdir = os.path.join(self.options.tmpdir, NODE_DIR, FILE_NAME) 25 | + assert not os.path.exists(tmpdir) 26 | + 27 | + self.log.info("Test -startupnotify command is run when node starts") 28 | + self.restart_node(0, extra_args=[f"-startupnotify=echo '{FILE_NAME}' >> {NODE_DIR}/{FILE_NAME}"]) 29 | + assert os.path.exists(tmpdir)
brunoerg commented at 5:16 PM on December 23, 2021:Done, thanks!
in test/functional/feature_startupnotify.py:24 in 98014c5a88 outdated
19 | + def set_test_params(self): 20 | + self.num_nodes = 1 21 | + self.disable_syscall_sandbox = True 22 | + 23 | + def run_test(self): 24 | + tmpdir = os.path.join(self.options.tmpdir, NODE_DIR, FILE_NAME)
kristapsk commented at 11:06 PM on December 22, 2021:Why the variable is called
tmpdirif it's actually filename?
brunoerg commented at 2:47 PM on December 23, 2021:this is the temporary directory where the file is...
brunoerg force-pushed on Dec 23, 2021brunoerg commented at 5:17 PM on December 23, 2021: memberforce-pushed addressing @luke-jr and @kristapsk reviews (check if the command is executed once).
kristapsk approvedkristapsk commented at 7:16 PM on December 23, 2021: contributorACK dbdcc783e39794d54c2f17040d248539b1ca46b0
lsilva01 approvedlsilva01 commented at 11:35 PM on December 23, 2021: contributorreACK dbdcc78
Nice addition to test coverage.
MarcoFalke commented at 9:29 AM on December 24, 2021: memberfeature_startupnotify.py | ✖ Failed | 2 stest: add functional test for -startupnotify 126853214abrunoerg force-pushed on Dec 24, 2021brunoerg commented at 1:57 PM on December 24, 2021: memberfeature_startupnotify.py | ✖ Failed | 2 sFixed!
theStack approvedtheStack commented at 2:45 AM on December 31, 2021: memberTested ACK 126853214a490ee840e83ca17c717c40cfbe6837 (run on OpenBSD 7.0)
kristapsk approvedkristapsk commented at 6:14 PM on December 31, 2021: contributorre-ACK 126853214a490ee840e83ca17c717c40cfbe6837
MarcoFalke merged this on Jan 3, 2022MarcoFalke closed this on Jan 3, 2022sidhujag referenced this in commit 33f09a2e2a on Jan 4, 2022seaona commented at 4:25 PM on January 27, 2022: contributorConcept and approach ACK. Tested and working fine :) I saw that
startupnotifyuses execve and I was wondering if that could be checked on the test, somehow like: in case of using sandbox (if defined(USE_SYSCALL_SANDBOX),startupnotifywill not throw?DrahtBot locked this on Jan 27, 2023
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 03:14 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me