From a0771faa245ebeb3ca291b646f2e105cb1602984 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 12 Jun 2024 14:25:47 +0200 Subject: [PATCH 1/7] Fix xfail strict --- tests/tests_app/core/test_lightning_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests_app/core/test_lightning_api.py b/tests/tests_app/core/test_lightning_api.py index 65ac6fcab2bf7..9b80d540c17e0 100644 --- a/tests/tests_app/core/test_lightning_api.py +++ b/tests/tests_app/core/test_lightning_api.py @@ -404,7 +404,7 @@ async def test_frontend_routes(path, expected_status_code): assert response.status_code == expected_status_code -@pytest.mark.xfail(sys.platform == "linux", reason="No idea why... need to be fixed") # fixme +@pytest.mark.xfail(sys.platform == "linux", strict=False, reason="No idea why... need to be fixed") # fixme def test_start_server_started(): """This test ensures has_started_queue receives a signal when the REST API has started.""" api_publish_state_queue = mp.Queue() From 947174a293bbb9284ee95f7eff32124026763744 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 12 Jun 2024 14:25:56 +0200 Subject: [PATCH 2/7] wip --- tests/tests_app/utilities/test_network.py | 34 ++++++++++++----------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/tests_app/utilities/test_network.py b/tests/tests_app/utilities/test_network.py index 3a14c0301ef1e..2b9c92480d3a8 100644 --- a/tests/tests_app/utilities/test_network.py +++ b/tests/tests_app/utilities/test_network.py @@ -48,40 +48,42 @@ def test_find_free_network_port_cloudspace(_, patch_constants): @mock.patch("urllib3.connectionpool.HTTPConnectionPool._get_conn") def test_http_client_retry_post(getconn_mock): getconn_mock.return_value.getresponse.side_effect = [ - mock.Mock(status=500, msg=HTTPMessage()), - mock.Mock(status=599, msg=HTTPMessage()), - mock.Mock(status=405, msg=HTTPMessage()), - mock.Mock(status=200, msg=HTTPMessage()), + mock.Mock(status=500, msg=HTTPMessage(), headers={}), + mock.Mock(status=599, msg=HTTPMessage(), headers={}), + mock.Mock(status=405, msg=HTTPMessage(), headers={}), + mock.Mock(status=200, msg=HTTPMessage(), headers={}), ] client = HTTPClient(base_url="http://test.url") + client.session.stream = True r = client.post("/test") r.raise_for_status() assert getconn_mock.return_value.request.mock_calls == [ - mock.call("POST", "/test", body=None, headers=mock.ANY), - mock.call("POST", "/test", body=None, headers=mock.ANY), - mock.call("POST", "/test", body=None, headers=mock.ANY), - mock.call("POST", "/test", body=None, headers=mock.ANY), + mock.call("POST", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), + mock.call("POST", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), + mock.call("POST", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), + mock.call("POST", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), ] @mock.patch("urllib3.connectionpool.HTTPConnectionPool._get_conn") def test_http_client_retry_get(getconn_mock): getconn_mock.return_value.getresponse.side_effect = [ - mock.Mock(status=500, msg=HTTPMessage()), - mock.Mock(status=599, msg=HTTPMessage()), - mock.Mock(status=405, msg=HTTPMessage()), - mock.Mock(status=200, msg=HTTPMessage()), + mock.Mock(status=500, msg=HTTPMessage(), headers={}), + mock.Mock(status=599, msg=HTTPMessage(), headers={}), + mock.Mock(status=405, msg=HTTPMessage(), headers={}), + mock.Mock(status=200, msg=HTTPMessage(), headers={}), ] client = HTTPClient(base_url="http://test.url") + client.session.stream = True r = client.get("/test") r.raise_for_status() assert getconn_mock.return_value.request.mock_calls == [ - mock.call("GET", "/test", body=None, headers=mock.ANY), - mock.call("GET", "/test", body=None, headers=mock.ANY), - mock.call("GET", "/test", body=None, headers=mock.ANY), - mock.call("GET", "/test", body=None, headers=mock.ANY), + mock.call("GET", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), + mock.call("GET", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), + mock.call("GET", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), + mock.call("GET", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), ] From 64f9ec5a3776a3d4e7acafc46c2c27a080121ebf Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 12 Jun 2024 14:26:02 +0200 Subject: [PATCH 3/7] Revert "wip" This reverts commit 947174a293bbb9284ee95f7eff32124026763744. --- tests/tests_app/utilities/test_network.py | 34 +++++++++++------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/tests_app/utilities/test_network.py b/tests/tests_app/utilities/test_network.py index 2b9c92480d3a8..3a14c0301ef1e 100644 --- a/tests/tests_app/utilities/test_network.py +++ b/tests/tests_app/utilities/test_network.py @@ -48,42 +48,40 @@ def test_find_free_network_port_cloudspace(_, patch_constants): @mock.patch("urllib3.connectionpool.HTTPConnectionPool._get_conn") def test_http_client_retry_post(getconn_mock): getconn_mock.return_value.getresponse.side_effect = [ - mock.Mock(status=500, msg=HTTPMessage(), headers={}), - mock.Mock(status=599, msg=HTTPMessage(), headers={}), - mock.Mock(status=405, msg=HTTPMessage(), headers={}), - mock.Mock(status=200, msg=HTTPMessage(), headers={}), + mock.Mock(status=500, msg=HTTPMessage()), + mock.Mock(status=599, msg=HTTPMessage()), + mock.Mock(status=405, msg=HTTPMessage()), + mock.Mock(status=200, msg=HTTPMessage()), ] client = HTTPClient(base_url="http://test.url") - client.session.stream = True r = client.post("/test") r.raise_for_status() assert getconn_mock.return_value.request.mock_calls == [ - mock.call("POST", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), - mock.call("POST", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), - mock.call("POST", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), - mock.call("POST", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), + mock.call("POST", "/test", body=None, headers=mock.ANY), + mock.call("POST", "/test", body=None, headers=mock.ANY), + mock.call("POST", "/test", body=None, headers=mock.ANY), + mock.call("POST", "/test", body=None, headers=mock.ANY), ] @mock.patch("urllib3.connectionpool.HTTPConnectionPool._get_conn") def test_http_client_retry_get(getconn_mock): getconn_mock.return_value.getresponse.side_effect = [ - mock.Mock(status=500, msg=HTTPMessage(), headers={}), - mock.Mock(status=599, msg=HTTPMessage(), headers={}), - mock.Mock(status=405, msg=HTTPMessage(), headers={}), - mock.Mock(status=200, msg=HTTPMessage(), headers={}), + mock.Mock(status=500, msg=HTTPMessage()), + mock.Mock(status=599, msg=HTTPMessage()), + mock.Mock(status=405, msg=HTTPMessage()), + mock.Mock(status=200, msg=HTTPMessage()), ] client = HTTPClient(base_url="http://test.url") - client.session.stream = True r = client.get("/test") r.raise_for_status() assert getconn_mock.return_value.request.mock_calls == [ - mock.call("GET", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), - mock.call("GET", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), - mock.call("GET", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), - mock.call("GET", "/test", body=None, headers=mock.ANY, chunked=False, preload_content=False, decode_content=False, enforce_content_length=True), + mock.call("GET", "/test", body=None, headers=mock.ANY), + mock.call("GET", "/test", body=None, headers=mock.ANY), + mock.call("GET", "/test", body=None, headers=mock.ANY), + mock.call("GET", "/test", body=None, headers=mock.ANY), ] From fa51d27036ac7b8899ad55c9e07320d563b86b70 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 12 Jun 2024 14:27:13 +0200 Subject: [PATCH 4/7] restrict urllib --- requirements/app/app.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/app/app.txt b/requirements/app/app.txt index d2bffc5cecfd3..a59e0b5ca5c28 100644 --- a/requirements/app/app.txt +++ b/requirements/app/app.txt @@ -23,7 +23,7 @@ Jinja2 <3.2.0 PyYAML <=6.0.1 requests <2.32.0 rich >=12.3.0, <13.6.0 -urllib3 <2.1.0 +urllib3 <2.0.0 uvicorn <0.24.0 websocket-client <1.7.0 websockets <11.1.0 From 2dc48f506912a20cf5aa77ba01aa29c7d431b0a7 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 12 Jun 2024 14:33:19 +0200 Subject: [PATCH 5/7] update --- tests/tests_app/utilities/test_network.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/tests_app/utilities/test_network.py b/tests/tests_app/utilities/test_network.py index 3a14c0301ef1e..999c75da57dd7 100644 --- a/tests/tests_app/utilities/test_network.py +++ b/tests/tests_app/utilities/test_network.py @@ -48,10 +48,10 @@ def test_find_free_network_port_cloudspace(_, patch_constants): @mock.patch("urllib3.connectionpool.HTTPConnectionPool._get_conn") def test_http_client_retry_post(getconn_mock): getconn_mock.return_value.getresponse.side_effect = [ - mock.Mock(status=500, msg=HTTPMessage()), - mock.Mock(status=599, msg=HTTPMessage()), - mock.Mock(status=405, msg=HTTPMessage()), - mock.Mock(status=200, msg=HTTPMessage()), + mock.Mock(status=500, msg=HTTPMessage(), headers={}), + mock.Mock(status=599, msg=HTTPMessage(), headers={}), + mock.Mock(status=405, msg=HTTPMessage(), headers={}), + mock.Mock(status=200, msg=HTTPMessage(), headers={}), ] client = HTTPClient(base_url="http://test.url") @@ -69,10 +69,10 @@ def test_http_client_retry_post(getconn_mock): @mock.patch("urllib3.connectionpool.HTTPConnectionPool._get_conn") def test_http_client_retry_get(getconn_mock): getconn_mock.return_value.getresponse.side_effect = [ - mock.Mock(status=500, msg=HTTPMessage()), - mock.Mock(status=599, msg=HTTPMessage()), - mock.Mock(status=405, msg=HTTPMessage()), - mock.Mock(status=200, msg=HTTPMessage()), + mock.Mock(status=500, msg=HTTPMessage(), headers={}), + mock.Mock(status=599, msg=HTTPMessage(), headers={}), + mock.Mock(status=405, msg=HTTPMessage(), headers={}), + mock.Mock(status=200, msg=HTTPMessage(), headers={}), ] client = HTTPClient(base_url="http://test.url") From a9aa1705b222a45dbe8f63aa4e7d50dfcb429a02 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 12 Jun 2024 16:18:22 +0200 Subject: [PATCH 6/7] update --- tests/tests_app/cli/test_cmd_launch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tests_app/cli/test_cmd_launch.py b/tests/tests_app/cli/test_cmd_launch.py index 4b75c08de5dce..167e896fba11c 100644 --- a/tests/tests_app/cli/test_cmd_launch.py +++ b/tests/tests_app/cli/test_cmd_launch.py @@ -7,6 +7,7 @@ from unittest import mock from unittest.mock import ANY, MagicMock, Mock +import pytest from click.testing import CliRunner from lightning.app.cli.lightning_cli_launch import run_flow, run_flow_and_servers, run_frontend, run_server from lightning.app.core.queues import QueuingSystem @@ -189,6 +190,7 @@ def start_processes(**functions): @_RunIf(skip_windows=True) +@pytest.mark.flaky(reruns=3) def test_manage_server_processes_one_process_gets_killed(capfd): functions = {"p1": run_forever_process, "p2": run_for_2_seconds_and_raise} p = Process(target=start_processes, kwargs=functions) From cff7abe05073f1e9bc2e1ced440d3ef5a95f3175 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Wed, 12 Jun 2024 20:09:38 +0200 Subject: [PATCH 7/7] mark flaky test --- tests/tests_app/core/test_lightning_app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tests_app/core/test_lightning_app.py b/tests/tests_app/core/test_lightning_app.py index 08a2d7c641b29..a70cbb853e437 100644 --- a/tests/tests_app/core/test_lightning_app.py +++ b/tests/tests_app/core/test_lightning_app.py @@ -1084,6 +1084,7 @@ def run_once(self): return res +@pytest.mark.flaky(reruns=3) def test_lightning_app_has_updated(): app = TestLightningHasUpdatedApp(FlowPath()) MultiProcessRuntime(app, start_server=False).dispatch()