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

Automatically run services in loops #18

Open
wants to merge 1 commit into
base: daniel-starter
Choose a base branch
from

Conversation

changhiskhan
Copy link

Previously you had to manually execute all of the services to "step" through each iteration of scanning, parsing, testing.
This PR converts the test looper services into ODB ServiceBase's with Reactors.

Parser service

Every 10s, scan the repositories we know about for new commits.
Separately, two reactors will be running:
1. When new commits are added from the scan repo operation, parse
   the commits and add TestNodes
2. If there are unexecuted TestNodes, assign them to free workers

Runner service

A RunnerService will run on a test-looper worker. It will look in odb for
assigned TestNode's and execute the tests that are assigned to it. Once
completed it will put TestResults back in ODB then go back to looking for
assignments.

Once every 10s, this runner should send a heartbeat (to ODB), so that bad
workers can be killed by the overall system

For local convenience, added test.sh in the repo root so you don't need to explicitly pass in the markers to skip etc.

@changhiskhan changhiskhan requested a review from dkrasner October 11, 2022 06:11
@changhiskhan changhiskhan changed the base branch from dev to daniel-starter October 11, 2022 06:11
@changhiskhan
Copy link
Author

Run scripts/start_services.py

image

@changhiskhan
Copy link
Author

initialize the test repo:

In [1]: from test_looper.utils.services import init_test_repo

In [2]: init_test_repo()
Initialized empty Git repository in /tmp/0a198894-4a25-4dcf-8d2d-eecea58308a1/_template_repo/.git/
[main (root-commit) 95cee6f] initial commit
 3 files changed, 11 insertions(+)
 create mode 100644 test_looper.json
 create mode 100644 tests/__pycache__/test_cases.cpython-38-pytest-7.1.2.pyc
 create mode 100644 tests/test_cases.py
Out[2]: '/tmp/0a198894-4a25-4dcf-8d2d-eecea58308a1/_template_repo'

nothing should happen yet because this is just the "remote" and TestLooper doesn't know this repo yet.

@changhiskhan
Copy link
Author

connect to odb and test_looper_schema:

from test_looper import test_looper_schema
from object_database import connect
odb = connect('localhost', 8080, 'TOKEN')
odb.subscribeToSchema(test_looper_schema)

registry the repository with test looper:

from test_looper.service import LooperService
looper = LooperService(odb, repo_url='/tmp/test_looper/repos')
looper.add_repo("template_repo", "/tmp/0a198894-4a25-4dcf-8d2d-eecea58308a1/_template_repo")

Now in the terminal that you ran ./start_services.py, you should see:

image

@changhiskhan
Copy link
Author

In a terminal, go to the "remote" repo and add a commit:

echo "foo" > new_commit.txt
git add .
git commit -m "new commit"

In the services window, you should see the tests running again:

[2022-10-11 02:34:10.335-04:00]     INFO               ServiceWorker.py: 142 | 100000108 |   Thread-4 | Starting runloop for service object 100000108
In doWork
Heartbeating
======================================================= test session starts ========================================================
platform linux -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0
rootdir: /tmp/test_looper/repos/template_repo
plugins: json-report-1.5.0, metadata-2.0.2
collected 2 items                                                                                                                  

tests/test_cases.py .F                                                                                                       [100%]

============================================================= FAILURES =============================================================
____________________________________________________________ test_fail _____________________________________________________________

    def test_fail():
>       assert 0 == 1
E       assert 0 == 1

tests/test_cases.py:6: AssertionError
----------------------------------------------------------- JSON report ------------------------------------------------------------
report saved to: .test-looper-report-a6e992ab-de5f-4fc5-915f-74a807e98f8b
===================================================== short test summary info ======================================================
FAILED tests/test_cases.py::test_fail - assert 0 == 1
=================================================== 1 failed, 1 passed in 0.08s ====================================================
Running assign_nodes
Running tests

@changhiskhan
Copy link
Author

Now let's verify ODB state:

We should have 1 repo with 2 commits which means 2 TestNodes and 2 TestResults:

In [6]: with odb.view():
   ...:     for repo in Repository.lookupAll():
   ...:         print(repo)
   ...: 
test_looper.Repository(id=700000000)

In [7]: with odb.view():
   ...:     for c in Commit.lookupAll():
   ...:         print(c)
   ...: 
test_looper.Commit(id=1200000002)
test_looper.Commit(id=2000000002)

In [8]: with odb.view():
   ...:     for t in TestNode.lookupAll():
   ...:         print(t)
   ...: 
test_looper.TestNode(id=1200000005)
test_looper.TestNode(id=2000000005)

In [9]: with odb.view():
   ...:     for rs in TestResults.lookupAll():
   ...:         print(rs)
   ...: 
test_looper.TestResults(id=1300000003)
test_looper.TestResults(id=2100000003)

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.

1 participant