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

pyln: Migrate testing utilities and fixtures into pyln-testing #3218

Merged
merged 9 commits into from
Nov 12, 2019

Conversation

cdecker
Copy link
Member

@cdecker cdecker commented Oct 28, 2019

I've been planning to do this for a while now, but I didn't know how clever to get, so this is the blunt version that just moves all the pieces over while keeping the surface stable.

The goal is to split out the testing framework, including fixtures and utilities to setup and manage nodes, into its own package, so we can reuse them in other related projects. Currently we have copy-paste versions of this code in https://github.com/cdecker/lnet and https://github.com/cdecker/lightning-integration, and some people have expressed interest in setting up tests for their plugins in https://github.com/lightningd/plugins as well.

The copy in https://github.com/cdecker/lightning-integration is likely the hardest to retro-fit to use pyln-testing, since it manages multiple parametrizable implementations, but I plan to add runners for those other projects eventually as well. One step at a time :-)

@@ -5,7 +5,7 @@
import socket
import warnings

__version__ = "0.0.7.4"
__version__ = "0.7.4"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not 0.7.3 to be in sync with the release ? 0.7.3 > 0.0.7.4 anyway

@darosior
Copy link
Collaborator

Running

PYTHONPATH=`pwd`/contrib/pyln-client:`pwd`/contrib/pyln-testing:$PYTHONPATH TEST_DEBUG=1 DEVELOPER=1 VALGRIND=1 pytest tests/ -v --timeout=550 --timeout_method=thread -p no:logging -n=24

Gives me an error on the first test (test_deprecated_closing_compat) because

with pytest.raises(RpcError, match=r"......."):
     the_call()

Does not seem to catch the error.

Looking forward to use pyln-testing for plugins ! :-)

@cdecker
Copy link
Member Author

cdecker commented Oct 28, 2019

Yep, should have marked this as WIP since it clearly has some edge-cases. For example outside of this repo we want to use the lightningd from the $PATH while here we explicitly want the one in lightningd/lightningd, so I'll need to create a way to customize the nodes we run.

This should not affect any consumer of the API since we just shift the actual
implementation from one side to the other, and keep aliases in place so
scripts don't break.

We also bump the version number from 0.0.7.3 to 0.7.4 which allows us to be in
sync with c-lightning itself, and remove the superfluous `0` in front.
We'll rewrite the tests to use this infrastructure in the next commit.

Changelog-Added: The new `pyln-testing` package now contains the testing infrastructure so it can be reused to test against c-lighting in external projects
We use `env()` to look up configuration variables and allow them to be
overridden by the environment.
We'll start relying on the in-tree version pretty soon, so we better make
sure we find it.
`DEVELOPER=1` assumes that the binary has been compiled with developer set to
true, which might not be the case for plugin developers. Setting this to 0 by
default has no effect in c-lightning since we always at least set it in
`config.vars` but may prevent some issues outside.
We were relying heavily on NodeFactory to do some magic before instantiating
the Node with rpc and daemon initialized, that meant that we'd have to replace
all 3 classes when customizing the node to our needs. Moving that
initialization into the node itself means that the LightningNode class now can
be swapped out and customized, without having to wire everything else through.
Quite a few of the things in the LightningNode class are tailored to their use
in the c-lightning tests, so I decided to split those customizations out into
a sub-class, and adding one more fixture that just serves the class. This
allows us to override the LightningNode implementation in our own tests, while
still having sane defaults for other users.
@cdecker
Copy link
Member Author

cdecker commented Nov 11, 2019

Running

PYTHONPATH=`pwd`/contrib/pyln-client:`pwd`/contrib/pyln-testing:$PYTHONPATH TEST_DEBUG=1 DEVELOPER=1 VALGRIND=1 pytest tests/ -v --timeout=550 --timeout_method=thread -p no:logging -n=24

Gives me an error on the first test (test_deprecated_closing_compat) because

with pytest.raises(RpcError, match=r"......."):
     the_call()

Does not seem to catch the error.

Looking forward to use pyln-testing for plugins ! :-)

I'm afraid I was not able to reproduce this issue in any of my runs. Is there anything special about your setup? Does make pytest work as expected (you can instrument make pytest using a number of env vars such as PYTEST_PAR and TEST_DB_PROVIDER if that's why your running the tests manually)?

Other than that I think this PR is pretty much ready to go ^^

Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

Ack 169019e

@cdecker cdecker merged commit 9378be7 into ElementsProject:master Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants