Skip to content

Conversation

@brunoerg
Copy link
Contributor

@brunoerg brunoerg commented Nov 17, 2021

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.

@fanquake fanquake added the Tests label Nov 17, 2021
@lsilva01
Copy link
Contributor

lsilva01 commented Nov 17, 2021

Concept ACK.

Perhaps the test with valid command can create a file in test or tmp dir and checks if this file was created..

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 17, 2021

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

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
Copy link
Contributor Author

I've tried different valid commands with -startupnotify like: echo (common command for Unix system and Windows), tried a simple ls for Unix and dir for Windows and other ones, but the CI is failing for all of them. Any thoughts about it, @MarcoFalke?

@maflcko
Copy link
Member

maflcko commented Nov 17, 2021

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
Copy link
Contributor Author

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 brunoerg force-pushed the 2021-11-test-startupnotify branch 2 times, most recently from 5f7d252 to b9908fa Compare November 17, 2021 13:21
@theStack
Copy link
Contributor

Concept ACK

@brunoerg
Copy link
Contributor Author

Force-pushed with a update on expected_stderr in stop_node. I just edited the description.

@brunoerg brunoerg force-pushed the 2021-11-test-startupnotify branch 3 times, most recently from 7818542 to 9e94a23 Compare November 18, 2021 14:08
@brunoerg
Copy link
Contributor Author

Win64 has failed:
Screen Shot 2021-11-18 at 10 23 47

I think the problem may be the breaklines. Going to work to fix it.

@brunoerg brunoerg force-pushed the 2021-11-test-startupnotify branch 2 times, most recently from 510919d to e9ebe3b Compare November 18, 2021 23:53
@brunoerg
Copy link
Contributor Author

brunoerg commented Nov 19, 2021

Force-pushed adding os.linesep into expected windows message.

@brunoerg brunoerg force-pushed the 2021-11-test-startupnotify branch 4 times, most recently from 7f462b1 to b0fc9f9 Compare November 24, 2021 12:59
Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

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

Ideally, a test for -startupnotify should 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 brunoerg force-pushed the 2021-11-test-startupnotify branch from b0fc9f9 to 31931a5 Compare December 3, 2021 12:46
@brunoerg
Copy link
Contributor Author

brunoerg commented Dec 3, 2021

Force-pushed addressing the reviews, thanks everyone for them. I just changed the approach for this test (updated the description).

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK 31931a5ab009256bf583025939e6e3ca2f875d9a

A couple of ideas, feel free to ignore/pick/choose:

  • Begin by testing the absence of tmpdir without -startupnotify before 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
Copy link
Member

jonatack commented Dec 7, 2021

Ideally, a test for -startupnotify should 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 brunoerg force-pushed the 2021-11-test-startupnotify branch 2 times, most recently from 506c9ce to 3e2be6f Compare December 7, 2021 21:42
@brunoerg
Copy link
Contributor Author

brunoerg commented Dec 7, 2021

Force-pushed addressing @luke-jr and @jonatack tips. Thanks for the reviews.

@jonatack
Copy link
Member

jonatack commented Dec 8, 2021

ACK, modulo unrelated code that appears to have crept into the last push?

@brunoerg
Copy link
Contributor Author

ACK, modulo unrelated code that appears to have crept into the last push?

omg, didn't understand why it happened, going to check it.

@brunoerg brunoerg force-pushed the 2021-11-test-startupnotify branch from 3e2be6f to 98014c5 Compare December 21, 2021 17:57
@brunoerg
Copy link
Contributor Author

fixed commits! @jonatack

@Davidson-Souza
Copy link

Davidson-Souza commented Dec 22, 2021

tested 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 ./configure options

Tests:
Ran the test alone, it worked!
image
Also, all the tests with test/functional/test_runner.py, again everything is working just fine!
image

@brunoerg brunoerg force-pushed the 2021-11-test-startupnotify branch from 98014c5 to dbdcc78 Compare December 23, 2021 17:15
@brunoerg
Copy link
Contributor Author

force-pushed addressing @luke-jr and @kristapsk reviews (check if the command is executed once).

Copy link
Contributor

@kristapsk kristapsk left a comment

Choose a reason for hiding this comment

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

ACK dbdcc783e39794d54c2f17040d248539b1ca46b0

Copy link
Contributor

@lsilva01 lsilva01 left a comment

Choose a reason for hiding this comment

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

reACK dbdcc78

Nice addition to test coverage.

@maflcko
Copy link
Member

maflcko commented Dec 24, 2021

feature_startupnotify.py                           | ✖ Failed  | 2 s

@brunoerg brunoerg force-pushed the 2021-11-test-startupnotify branch from dbdcc78 to 1268532 Compare December 24, 2021 11:42
@brunoerg
Copy link
Contributor Author

feature_startupnotify.py                           | ✖ Failed  | 2 s

Fixed!

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Tested ACK 1268532
(run on OpenBSD 7.0)

Copy link
Contributor

@kristapsk kristapsk left a comment

Choose a reason for hiding this comment

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

re-ACK 1268532

@maflcko maflcko merged commit 31f385c into bitcoin:master Jan 3, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 4, 2022
1268532 test: add functional test for -startupnotify (Bruno Garcia)

Pull request description:

  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.

ACKs for top commit:
  theStack:
    Tested ACK 1268532
  kristapsk:
    re-ACK 1268532

Tree-SHA512: 5bf3e46124ee5c9d609c9993e6465d5a71a8d2275dcf07c8ce0549f013f7f8863d483b46b7164152f566468a689371ccb87f01cf118c3c9cac5b2be673b61a5c
@seaona
Copy link
Contributor

seaona commented Jan 27, 2022

Concept and approach ACK. Tested and working fine :)
I saw that startupnotify uses 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), startupnotify will not throw?

@bitcoin bitcoin locked and limited conversation to collaborators Jan 27, 2023
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.