Skip to content
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

qa: Check return code when stopping nodes #9824

Merged
merged 1 commit into from
Feb 23, 2017

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Feb 22, 2017

We had a segfault slip through recently (#9817) because the test framework just ignores the return code.

@laanwj laanwj added the Tests label Feb 22, 2017
@laanwj
Copy link
Member

laanwj commented Feb 22, 2017

Yes, makes sense to check that. utACK fac3af7 (also for 0.14)

@laanwj laanwj added this to the 0.14.0 milestone Feb 22, 2017
Copy link

@shyii shyii left a comment

Choose a reason for hiding this comment

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

Hey

@laanwj
Copy link
Member

laanwj commented Feb 22, 2017

@shyii I'm not sure what you're trying to do, but please don't abuse the code review system for sending idle messages.

@jnewbery
Copy link
Contributor

Concept ACK. We should definitely assert the return code on shutdown.

This causes at least the following two tests to fail:

  • fundrawtransaction.py
  • rpcbind_test.py

fundrawtransaction is failing because it's calling stop_nodes() on a subset of the running nodes:

        self.nodes[1].encryptwallet("test")
        self.nodes.pop(1)
        stop_nodes(self.nodes)

The encryptwallet() RPC actually stops bitcoind. That means that node 1 is still in the util module's global bitcoind_processes dictionary, so a call to stop_nodes() hits your assert.

It can be fixed by just calling stop_node() for each of the nodes individually.

The failure in rpcbind_test.py is due to this:

        try:
            # connect to node through non-loopback interface
            node = get_rpc_proxy(rpc_url(0, "%s:%d" % (rpchost, rpcport)), 0)
            node.getnetworkinfo()
        finally:
            node = None # make sure connection will be garbage collected and closed
            stop_nodes(self.nodes)

I don't think we need to wrap those calls in try/finallys since the BitcoinTestFramework.main() method takes care of cleaning up the nodes for us.

I've pushed fixes for both of those failures to jnewbery@cbebbcf. Feel free to squash into your commit if you're happy with the changes.

Generally, tracking bitcoin_processes as a global dictionary in util.py smells (any global variables in util.py smells). The nodes should be members of TestFramework, and it should be the test framework's responsibility to clean them up (and assert return codes) at the end of the test run.

And one question on code style: I know that assert_equal() is used all over the qa test directory. Why? Why is
assert_equal(ret, 0)
preferred over
assert ret == 0, "unexpected return code %s" % ret?

Why is
assert_equal(len(bitcoind_processes.values()), 0)
preferred over
assert not bitcoind_processes, "bitcoind processes still running: %s" % str(bitcoind_processes)?

In generally, assert seems to be treated as a function throughout the qa directory instead of a statement. It would be nice if we could change that.

@laanwj
Copy link
Member

laanwj commented Feb 22, 2017

In generally, assert seems to be treated as a function throughout the qa directory instead of a statement. > It would be nice if we could change that.

I think the idea on the longer run is to move away from using bare assert everywhere and to something that resembles a real testing framework (maybe unittest). Testing frameworks provide helper functions such as assert_equal because those can automatically print the expected and passed-in value, without having to provide a custom message everywhere.

@maflcko
Copy link
Member Author

maflcko commented Feb 22, 2017 via email

@jnewbery
Copy link
Contributor

@laanwj @MarcoFalke thanks. Makes sense.

assert as a statement should only be used with a single variable of
type boolean as expression or with an additional string that provides
further debug infos

Sounds sensible. We're quite a long way off that though!

→ cat qa/rpc-tests/*py | grep -c "assert("
364

This includes work by jnewbery
laanwj pushed a commit that referenced this pull request Feb 23, 2017
This includes work by jnewbery

Github-Pull: #9824
Rebased-From: fa4cd2e
@laanwj laanwj merged commit fa4cd2e into bitcoin:master Feb 23, 2017
laanwj added a commit that referenced this pull request Feb 23, 2017
fa4cd2e qa: Check return code when stopping nodes (MarcoFalke)
@maflcko maflcko deleted the Mf1702-qaRet branch February 23, 2017 11:22
jnewbery added a commit to jnewbery/bitcoin that referenced this pull request Mar 23, 2017
codablock pushed a commit to codablock/dash that referenced this pull request Jan 26, 2018
fa4cd2e qa: Check return code when stopping nodes (MarcoFalke)
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
fa4cd2e qa: Check return code when stopping nodes (MarcoFalke)
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Feb 27, 2019
fa4cd2e qa: Check return code when stopping nodes (MarcoFalke)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 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.

4 participants