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

Create core Agent integration tests #231

Merged
merged 30 commits into from
Nov 5, 2021

Conversation

BrianJKoopman
Copy link
Member

Description

This creates integration tests for the Tasks and Processes for the core OCS Agents. The Host Master Agent still lacks a bit of testing, however. This is building on the work in #230 on unit tests. (Since this builds on #230 I've PR'd onto that branch as well for ease of reading. #230 should be merged first, this'll redirect to develop then.)

The early integration tests that tested robustness to crossbar server reboots relied on pytest-docker-compose, which starts up a set of docker containers running Agents and other components needed on the network (i.e. the crossbar server, InfluxDB). We've reduced the number of containers these tests need, and in the future will continue to do so.

The CI pipeline will run almost all of these tests. There is a small set of integration tests that depend on a dockerized crossbar container and spt3g/so3g, which is a complicated environment to setup on GitHub actions at the moment due to the need to either install spt3g+so3g (long compile times) or run within and so3g based container (where we can't use pytest-docker-compose). There are several paths forward there, and I leave that for later PRs while noting the coverage missing from these tests is minimal.

Motivation and Context

This is largely motivated by the need for automated testing, working towards #28. The fact that this starts up every core Agent and interacts with them via a Client means we're largely there too. With some additional coverage of important parts of the core library I think we'll be ready to close #28 soon.

How Has This Been Tested?

I ran the complete test suite, locally, in an environment that has Docker/Docker Compose and spt3g/so3g:

$ python3 -m pytest --cov --cov-report html
===================================================================== test session starts =====================================================================
platform linux -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
rootdir: /home/koopman/git/ocs/tests, configfile: pytest.ini
plugins: dependency-0.5.1, twisted-1.13.4, env-0.6.2, docker-compose-3.2.0, cov-2.10.1
collected 115 items

test_aggregator.py ..................                                                                                                                   [ 15%]
test_influxdb_publisher.py ...                                                                                                                          [ 18%]
test_matched_client.py .                                                                                                                                [ 19%]
test_ocs_agent.py ............................                                                                                                          [ 43%]
test_ocs_feed.py ................                                                                                                                       [ 57%]
test_ocs_twisted.py ...                                                                                                                                 [ 60%]
test_rename.py ....                                                                                                                                     [ 63%]
test_site_config.py .....                                                                                                                               [ 67%]
agents/test_aggregator_agent.py .....                                                                                                                   [ 72%]
agents/test_fakedata.py ......                                                                                                                          [ 77%]
agents/test_host_master.py .                                                                                                                            [ 78%]
agents/test_influxdb_publisher_agent.py .....                                                                                                           [ 82%]
agents/test_ocs_plugin_standard.py .                                                                                                                    [ 83%]
agents/test_registry_agent.py .....                                                                                                                     [ 87%]
integration/test_aggregator_agent_integration.py .                                                                                                      [ 88%]
integration/test_crossbar_integration.py ......                                                                                                         [ 93%]
integration/test_fake_data_agent_integration.py ....                                                                                                    [ 97%]
integration/test_host_master_agent_integration.py .                                                                                                     [ 98%]
integration/test_influxdb_publisher_integration.py .                                                                                                    [ 99%]
integration/test_registry_agent_integration.py .                                                                                                        [100%]

====================================================================== warnings summary =======================================================================
../../spt3g_software/build/spt3g/core/load_pybindings.py:19
  /home/koopman/git/spt3g_software/build/spt3g/core/load_pybindings.py:19: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp, sys

-- Docs: https://docs.pytest.org/en/stable/warnings.html

----------- coverage: platform linux, python 3.9.7-final-0 -----------
Coverage HTML written to dir htmlcov

========================================================= 115 passed, 1 warning in 307.60s (0:05:07) ==========================================================
2021-10-20T17:34:08-0400 Main loop terminated.
[koopman@vesper tests]$ coverage report
Name                                                                    Stmts   Miss  Cover
-------------------------------------------------------------------------------------------
/home/koopman/git/ocs/agents/aggregator/aggregator_agent.py                67      4    94%
/home/koopman/git/ocs/agents/fake_data/fake_data_agent.py                 133      7    95%
/home/koopman/git/ocs/agents/host_master/host_master.py                   218     99    55%
/home/koopman/git/ocs/agents/influxdb_publisher/influxdb_publisher.py      64      0   100%
/home/koopman/git/ocs/agents/ocs_plugin_standard.py                         5      0   100%
/home/koopman/git/ocs/agents/registry/registry.py                          86      3    97%
/home/koopman/git/ocs/ocs/__init__.py                                       5      0   100%
/home/koopman/git/ocs/ocs/agent/__init__.py                                 0      0   100%
/home/koopman/git/ocs/ocs/agent/aggregator.py                             299     22    93%
/home/koopman/git/ocs/ocs/agent/influxdb_publisher.py                      95     16    83%
/home/koopman/git/ocs/ocs/base.py                                          17      0   100%
/home/koopman/git/ocs/ocs/checkdata.py                                    122    106    13%
/home/koopman/git/ocs/ocs/client_cli.py                                   150    127    15%
/home/koopman/git/ocs/ocs/client_http.py                                   31      6    81%
/home/koopman/git/ocs/ocs/client_t.py                                      66     35    47%
/home/koopman/git/ocs/ocs/matched_client.py                                88     21    76%
/home/koopman/git/ocs/ocs/ocs_agent.py                                    472     77    84%
/home/koopman/git/ocs/ocs/ocs_feed.py                                     114      9    92%
/home/koopman/git/ocs/ocs/ocs_twisted.py                                   69     32    54%
/home/koopman/git/ocs/ocs/ocsbow.py                                       337    312     7%
/home/koopman/git/ocs/ocs/rename.py                                        49      0   100%
/home/koopman/git/ocs/ocs/site_config.py                                  273     32    88%
-------------------------------------------------------------------------------------------
TOTAL                                                                    2760    908    67%

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Unless I am preparing a release, I have opened this PR onto the develop branch.

Copy link
Member

@mhasself mhasself left a comment

Choose a reason for hiding this comment

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

Very interesting! Comments below pertain to the work as a whole, rather than this add-on.

I ran into docker conflicts when trying to run these ... would it help to give fixed container names that were a little less generic? I already had an "influxdb" running ... presumably these could all be called ocs-tests-influxdb and so on?

I had intermittent test failures for:
test_fake_data_after_crossbar_restart
test_aggregator_after_crossbar_restart

To debug I tried to docker-compose up in the tests directory and look at logs; at that point I realized the crossbar entry in default.yaml was causing fake-data-1 to not start up (#224). Can that just be removed from default.yaml here?

test_crossbar_integration.py is full of hard-coded sleeps. I think those intervals should be declared as variables at the top of the script -- i.e. the time to wait for agents to come back online; the time to wait for an agent to exit due to crossbar downness.

The "no gaps in the data" test was failing for me (I think I saw you'd commented this out in the other PR, or something?). Instead of looking at timestamps, you could invent a data stream in fake_data_agent that simply records an incrementing counter [0, 1, 2 ...]. That's very easy to check for problems!

@BrianJKoopman BrianJKoopman mentioned this pull request Nov 3, 2021
7 tasks
Base automatically changed from agent-unit-tests to develop November 4, 2021 19:58
@BrianJKoopman
Copy link
Member Author

I ran into docker conflicts when trying to run these ... would it help to give fixed container names that were a little less generic? I already had an "influxdb" running ... presumably these could all be called ocs-tests-influxdb and so on?

Mhm, good point. I've updated container names and ports to avoid conflicts.

I had intermittent test failures for: test_fake_data_after_crossbar_restart test_aggregator_after_crossbar_restart

To debug I tried to docker-compose up in the tests directory and look at logs; at that point I realized the crossbar entry in default.yaml was causing fake-data-1 to not start up (#224). Can that just be removed from default.yaml here?

Strange, I removed the crossbar entry in default.yaml already, were you on an old commit? (These crossbar integration tests have been around for a while.)

test_crossbar_integration.py is full of hard-coded sleeps. I think those intervals should be declared as variables at the top of the script -- i.e. the time to wait for agents to come back online; the time to wait for an agent to exit due to crossbar downness.

I've moved the wait time before crossbar comes up. The other time out, waiting for an Agent to exit only exists in one test, so I'll leave it locally for now.

The "no gaps in the data" test was failing for me (I think I saw you'd commented this out in the other PR, or something?). Instead of looking at timestamps, you could invent a data stream in fake_data_agent that simply records an incrementing counter [0, 1, 2 ...]. That's very easy to check for problems!

Mhm, I like that idea. But yeah, that test is not good. That final assert is commented out now, probably I should remove more of that test. It came about after I saw some behavior that isn't reliably reproduced (though I didn't realize that at the time.)

On a related note, I've removed some of the other tests which aren't really needed, like the test_testing test which just runs the "wait_for_crossbar" fixture, and the empty influxdb test (test_influxdb_publisher_after_crossbar_restart). This should save ~10 seconds or so from not needlessly bringing up the containers a couple more times.

This env var was being retained between tests otherwise.
Following the second recommendation in [1]. Note we avoid the pitfall the
documentation points out since we run our tests from the tests/ directory and
not from the root of the repo.

[1] - https://docs.pytest.org/en/6.2.x/goodpractices.html#tests-outside-application-code
Note this was squashed from many debugging commits to trigger the CI workflow
and debug workflow issues.
Also clean up some of the debugging in the github workflow.
Also session scope integration tests that depend on so3g.
The Client fixture now attempts reconnects up to a certain timeout, which is a
faster way of waiting for the Agent to come up, since we can just check
rapidly, rather than way some time that fluctuates given the load of the
system for the Agent to finish starting up.
If an OCS system is already running on the machine running the tests we would
collide with in use ports and container names. This avoids that, allowing tests
to run on the same system.
`test_testing` was just neede initially when figuring out the wait_for_crossbar
fixture. And `test_influxdb_publisher_after_crossbar_restart` is just a pass at
this time. Commenting these out will save some time.
@BrianJKoopman
Copy link
Member Author

BrianJKoopman commented Nov 5, 2021

Had to rebase and force push (after rebasing the unit test branch...learning a lesson at the moment...) Will merge when checks complete.

From mistyped keyboard shortcut.
@BrianJKoopman BrianJKoopman merged commit 7681985 into develop Nov 5, 2021
@BrianJKoopman BrianJKoopman deleted the koopman/agent-integration-tests branch November 5, 2021 20:49
@BrianJKoopman BrianJKoopman mentioned this pull request Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create tests which verify functionality of OCS
2 participants