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

test: use pytest-forked lib to run test in forked process #5263

Closed
wants to merge 10 commits into from

Conversation

girishc13
Copy link
Contributor

@girishc13 girishc13 commented Oct 10, 2022

Goals:

  • Run tests in forked process to avoid flakiness and reusing process state for subsequent Flow's. Shutting down a Flow leaves the module space in an inconsistent state so forking multiple Flow in pytest is not so useful.

@girishc13 girishc13 self-assigned this Oct 10, 2022
@github-actions github-actions bot added size/XS area/cicd This issue/PR affects the cicd pipeline area/housekeeping This issue/PR is housekeeping area/setup This issue/PR affects setting up Jina labels Oct 10, 2022
Copy link
Member

@JoanFM JoanFM left a comment

Choose a reason for hiding this comment

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

Apply same change to cd.yml

@JoanFM JoanFM closed this Oct 10, 2022
@JoanFM JoanFM reopened this Oct 10, 2022
@github-actions github-actions bot added size/S area/core This issue/PR affects the core codebase component/resource labels Oct 10, 2022
@codecov
Copy link

codecov bot commented Oct 10, 2022

Codecov Report

Merging #5263 (afc59f9) into master (a8dce57) will increase coverage by 10.29%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           master    #5263       +/-   ##
===========================================
+ Coverage   64.81%   75.11%   +10.29%     
===========================================
  Files          98      100        +2     
  Lines        6387     6433       +46     
===========================================
+ Hits         4140     4832      +692     
+ Misses       2247     1601      -646     
Flag Coverage Δ
jina 75.11% <ø> (+10.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...a/orchestrate/deployments/config/docker_compose.py 99.01% <0.00%> (-0.99%) ⬇️
jina/resources/health_check/pod.py 50.00% <0.00%> (ø)
jina/resources/health_check/gateway.py 41.17% <0.00%> (ø)
jina/clients/base/websocket.py 83.80% <0.00%> (+0.95%) ⬆️
jina/clients/base/http.py 91.89% <0.00%> (+1.35%) ⬆️
jina/serve/networking.py 67.53% <0.00%> (+2.81%) ⬆️
jina/clients/base/helper.py 81.88% <0.00%> (+3.14%) ⬆️
jina/clients/base/grpc.py 82.85% <0.00%> (+4.28%) ⬆️
jina/orchestrate/flow/base.py 90.15% <0.00%> (+4.29%) ⬆️
jina/jaml/helper.py 75.18% <0.00%> (+4.37%) ⬆️
... and 39 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@girishc13 girishc13 changed the title test: use pytst-forked lib to run test in forked process test: use pytest-forked lib to run test in forked process Oct 10, 2022
@github-actions github-actions bot added the area/testing This issue/PR affects testing label Oct 10, 2022
@@ -120,6 +120,7 @@ def test_encoder_name_env_replace():


def test_encoder_name_dict_replace():
os.environ['BE_TEST_NAME'] = 'hello123'
Copy link
Member

Choose a reason for hiding this comment

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

can u please use a fixture to set the env variable and reset afterwards? this is done in many other places

JoanFM
JoanFM previously approved these changes Oct 10, 2022
tests/unit/test_yamlparser.py Outdated Show resolved Hide resolved
@girishc13
Copy link
Contributor Author

@JoanFM I haven't added the arguments to the cd.yml yet. One thing to also notice with this change is that the CI logs don't capture the logging of each individual tests. The logs are not available because each test run in its own process. Locally we can remove the --forked argument and obtain the logs but on CI we might need to do some commits in case we want a detailed log.

@JoanFM
Copy link
Member

JoanFM commented Oct 10, 2022

@JoanFM I haven't added the arguments to the cd.yml yet. One thing to also notice with this change is that the CI logs don't capture the logging of each individual tests. The logs are not available because each test run in its own process. Locally we can remove the --forked argument and obtain the logs but on CI we might need to do some commits in case we want a detailed log.

if it guarantees non-flakyness, I would still pay the price, however there must be some way to solve this

@girishc13
Copy link
Contributor Author

Unfortunately the pytest-forked plugin isn't currently maintained. This open issue is causing the tests/unit/orchestrate/pods/ to fail. I'm not sure of an alternative to this test.

@girishc13
Copy link
Contributor Author

girishc13 commented Oct 10, 2022

The whole test code for test_pod.py looks unstable on close inspection and logging. The same pid is being reused across all tests. I added some logging to check the pid of each SlowFakeRuntime. The first runtime Pod@41979 runs throughout all the tests so I'm not sure what the tests are doing.

pytest --suppress-no-test-exit-code -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' tests/unit/orchestrate/pods/test_pod.py | grep -e "creating"
tests/unit/orchestrate/pods/test_pod.py::test_pod_runtime_env_setting DEBUG  Pod@41979 --->creating new pod...                                                                                      [10/10/22 18:08:04]
tests/unit/orchestrate/pods/test_pod.py::test_gateway_args[grpc-GRPCGateway] DEBUG  gateway@41979 --->creating new pod...                                                                                  [10/10/22 18:08:04]
tests/unit/orchestrate/pods/test_pod.py::test_gateway_args[websocket-WebSocketGateway] DEBUG  gateway@41979 --->creating new pod...                                                                                  [10/10/22 18:08:04]
tests/unit/orchestrate/pods/test_pod.py::test_gateway_args[http-HTTPGateway] DEBUG  gateway@41979 --->creating new pod...                                                                                  [10/10/22 18:08:04]
tests/unit/orchestrate/pods/test_pod.py::test_gateway_runtimes[grpc-GRPCGateway] DEBUG  gateway@41979 --->creating new pod...                                                                                  [10/10/22 18:08:04]
tests/unit/orchestrate/pods/test_pod.py::test_gateway_runtimes[websocket-WebSocketGateway] DEBUG  gateway@41979 --->creating new pod...                                                                                  [10/10/22 18:08:04]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:52345 (Press CTRL+C to quit)
INFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
tests/unit/orchestrate/pods/test_pod.py::test_gateway_runtimes[http-HTTPGateway] DEBUG  gateway@41979 --->creating new pod...                                                                                  [10/10/22 18:08:05]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:50697 (Press CTRL+C to quit)
INFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
tests/unit/orchestrate/pods/test_pod.py::test_non_gateway_runtimes[WorkerRuntime] DEBUG  Pod@41979 --->creating new pod...                                                                                      [10/10/22 18:08:05]
tests/unit/orchestrate/pods/test_pod.py::test_non_gateway_runtimes[HeadRuntime] DEBUG  Pod@41979 --->creating new pod...                                                                                      [10/10/22 18:08:05]
tests/unit/orchestrate/pods/test_pod.py::test_failing_executor DEBUG  Pod@41979 --->creating new pod...                                                                                      [10/10/22 18:08:06]
tests/unit/orchestrate/pods/test_pod.py::test_failing_gateway_runtimes[grpc-GRPCGateway] DEBUG  gateway@41979 --->creating new pod...                                                                                  [10/10/22 18:08:06]
tests/unit/orchestrate/pods/test_pod.py::test_failing_gateway_runtimes[websocket-WebSocketGateway] DEBUG  gateway@41979 --->creating new pod...                                                                                  [10/10/22 18:08:06]
tests/unit/orchestrate/pods/test_pod.py::test_failing_gateway_runtimes[http-HTTPGateway] DEBUG  gateway@41979 --->creating new pod...                                                                                  [10/10/22 18:08:06]
tests/unit/orchestrate/pods/test_pod.py::test_failing_head DEBUG  Pod@41979 --->creating new pod...                                                                                      [10/10/22 18:08:06]
tests/unit/orchestrate/pods/test_pod.py::test_close_before_start DEBUG  Pod@41979 --->creating new pod...                                                                                      [10/10/22 18:08:06]
tests/unit/orchestrate/pods/test_pod.py::test_close_before_start_slow_enter DEBUG  Pod@41979 --->creating new pod...                                                                                      [10/10/22 18:08:06]

@girishc13
Copy link
Contributor Author

girishc13 commented Oct 11, 2022

Some tests might still be flaky due to the incompatibility with the pytest-timeout feature.

@JoanFM
Copy link
Member

JoanFM commented Oct 11, 2022

Unfortunately the pytest-forked plugin isn't currently maintained. This open issue is causing the tests/unit/orchestrate/pods/ to fail. I'm not sure of an alternative to this test.

if it is not mantained, I would remove this

@girishc13
Copy link
Contributor Author

The pytest-forked library currently doesn't have a maintainer and the open issue with pytest-timeout prevents us form investing further time.

@girishc13 girishc13 closed this Oct 12, 2022
@girishc13 girishc13 deleted the pytest-forked-v2 branch October 12, 2022 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cicd This issue/PR affects the cicd pipeline area/core This issue/PR affects the core codebase area/housekeeping This issue/PR is housekeeping area/setup This issue/PR affects setting up Jina area/testing This issue/PR affects testing component/resource size/S size/XS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants