From aa43abbf125070f21a45219b69da0a141788a9c9 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 14 Mar 2024 14:50:46 +0100 Subject: [PATCH 1/9] Test for alternative argparse text on py3.10 for test_help_command_line_arg_works_for_supported_commands --- st2client/tests/unit/test_commands.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/st2client/tests/unit/test_commands.py b/st2client/tests/unit/test_commands.py index 929a327e98..b5814ebf54 100644 --- a/st2client/tests/unit/test_commands.py +++ b/st2client/tests/unit/test_commands.py @@ -14,11 +14,13 @@ # limitations under the License. from __future__ import absolute_import + import os import mock import json import logging import argparse +import re import tempfile import unittest from collections import namedtuple @@ -490,8 +492,9 @@ def test_help_command_line_arg_works_for_supported_commands(self): self.assertIn("usage:", stdout) self.assertIn(" ".join(command), stdout) - # self.assertIn('positional arguments:', stdout) - self.assertIn("optional arguments:", stdout) + # argparse on py3.8/py3.9 has a different output to py3.10 so the check for + # optional arguments covers both formats. + assert isinstance(re.search("(optional arguments:|options:)", stdout), re.Match) is True # Reset stdout and stderr after each iteration self._reset_output_streams() @@ -510,8 +513,10 @@ def test_help_command_line_arg_works_for_supported_commands(self): self.assertIn("usage:", stdout) self.assertIn(" ".join(command), stdout) - # self.assertIn('positional arguments:', stdout) - self.assertIn("optional arguments:", stdout) + # argparse on py3.8/py3.9 has a different output to py3.10 so the check for + # optional arguments covers both formats. + assert isinstance(re.search("(optional arguments:|options:)", stdout), re.Match) is True + # Verify that the actual help usage string was triggered and not the invalid # "too few arguments" which would indicate command doesn't actually correctly handle From 70fac7c055fd7ee3b3b13a998f55fc5a63ef27d0 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 14 Mar 2024 23:19:04 +0100 Subject: [PATCH 2/9] fmt --- st2client/tests/unit/test_commands.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/st2client/tests/unit/test_commands.py b/st2client/tests/unit/test_commands.py index b5814ebf54..e8fa417cb9 100644 --- a/st2client/tests/unit/test_commands.py +++ b/st2client/tests/unit/test_commands.py @@ -494,7 +494,12 @@ def test_help_command_line_arg_works_for_supported_commands(self): self.assertIn(" ".join(command), stdout) # argparse on py3.8/py3.9 has a different output to py3.10 so the check for # optional arguments covers both formats. - assert isinstance(re.search("(optional arguments:|options:)", stdout), re.Match) is True + assert ( + isinstance( + re.search("(optional arguments:|options:)", stdout), re.Match + ) + is True + ) # Reset stdout and stderr after each iteration self._reset_output_streams() @@ -515,8 +520,12 @@ def test_help_command_line_arg_works_for_supported_commands(self): self.assertIn(" ".join(command), stdout) # argparse on py3.8/py3.9 has a different output to py3.10 so the check for # optional arguments covers both formats. - assert isinstance(re.search("(optional arguments:|options:)", stdout), re.Match) is True - + assert ( + isinstance( + re.search("(optional arguments:|options:)", stdout), re.Match + ) + is True + ) # Verify that the actual help usage string was triggered and not the invalid # "too few arguments" which would indicate command doesn't actually correctly handle From c7f2772934d4d09adbbec0cd9207cd6e6f6fe5bb Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 18 Mar 2024 23:12:03 +0100 Subject: [PATCH 3/9] typo fixes in docstrings --- st2common/st2common/transport/publishers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/st2common/st2common/transport/publishers.py b/st2common/st2common/transport/publishers.py index ddf5d2f8c9..73596ed70e 100644 --- a/st2common/st2common/transport/publishers.py +++ b/st2common/st2common/transport/publishers.py @@ -43,8 +43,8 @@ class PoolPublisher(object): def __init__(self, urls=None): """ - :param urls: Connection URLs to use. If not provided it uses a default value from th - config. + :param urls: Connection URLs to use. If not provided it uses a default value from + the config. :type urls: ``list`` """ urls = urls or transport_utils.get_messaging_urls() @@ -67,7 +67,7 @@ def publish(self, payload, exchange, routing_key="", compression=None): ) def do_publish(connection, channel): - # ProducerPool ends up creating it own ConnectionPool which ends up + # ProducerPool ends up creating its own ConnectionPool which ends up # completely invalidating this ConnectionPool. Also, a ConnectionPool for # producer does not really solve any problems for us so better to create a # Producer for each publish. From ce2119abdd05ffee181c2fed9fe62747cb47ebd3 Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 19 Mar 2024 09:01:42 +0100 Subject: [PATCH 4/9] Fix bash syntax error in test_pause_resume_with_error --- .../actions/chains/test_pause_resume_with_error.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/st2tests/st2tests/fixtures/packs/action_chain_tests/actions/chains/test_pause_resume_with_error.yaml b/st2tests/st2tests/fixtures/packs/action_chain_tests/actions/chains/test_pause_resume_with_error.yaml index a4d46be55e..c214aa3c30 100644 --- a/st2tests/st2tests/fixtures/packs/action_chain_tests/actions/chains/test_pause_resume_with_error.yaml +++ b/st2tests/st2tests/fixtures/packs/action_chain_tests/actions/chains/test_pause_resume_with_error.yaml @@ -3,7 +3,12 @@ chain: name: task1 ref: core.local params: - cmd: "while [ -e '{{tempfile}}' ]; do sleep 0.1; exit 1" + cmd: | + while [ -e '{{tempfile}}' ]; + do + sleep 0.1 + done + exit 1 timeout: 180 on-failure: task2 - From 8ae7e6528d7d16ed98cd9f4fed3b6a4f8da1ab44 Mon Sep 17 00:00:00 2001 From: guzzijones12 Date: Mon, 9 Sep 2024 13:51:22 -0400 Subject: [PATCH 5/9] Add requests mock to a test --- st2client/tests/unit/test_inquiry.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/st2client/tests/unit/test_inquiry.py b/st2client/tests/unit/test_inquiry.py index 5ae225c79e..c8804dae47 100644 --- a/st2client/tests/unit/test_inquiry.py +++ b/st2client/tests/unit/test_inquiry.py @@ -14,6 +14,7 @@ # limitations under the License. from __future__ import absolute_import + import copy import json import mock @@ -294,6 +295,13 @@ def test_respond_invalid(self): "ERROR: 400 Client Error: Bad Request", self.stdout.getvalue().strip() ) + @mock.patch.object( + requests, + "get", + mock.MagicMock( + return_value=base.FakeResponse(json.dumps({}), 404, "NOT FOUND") + ), + ) def test_respond_nonexistent_inquiry(self): """Test responding to an inquiry that doesn't exist""" inquiry_id = "134234" From 3b98230822fd4dee1585894164a7310404e4ddd4 Mon Sep 17 00:00:00 2001 From: guzzijones12 Date: Mon, 9 Sep 2024 13:51:22 -0400 Subject: [PATCH 6/9] test coordinator usage fix and typo fix --- .../unit/controllers/v1/test_service_registry.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/st2api/tests/unit/controllers/v1/test_service_registry.py b/st2api/tests/unit/controllers/v1/test_service_registry.py index d195c2361e..e9392b3279 100644 --- a/st2api/tests/unit/controllers/v1/test_service_registry.py +++ b/st2api/tests/unit/controllers/v1/test_service_registry.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import tooz + from st2common.service_setup import register_service_in_service_registry from st2common.util import system_info from st2common.services.coordination import get_member_id @@ -22,20 +24,26 @@ from st2tests.api import FunctionalTest -__all__ = ["ServiceyRegistryControllerTestCase"] +__all__ = ["ServiceRegistryControllerTestCase"] -class ServiceyRegistryControllerTestCase(FunctionalTest): +class ServiceRegistryControllerTestCase(FunctionalTest): coordinator = None @classmethod def setUpClass(cls): - super(ServiceyRegistryControllerTestCase, cls).setUpClass() + super(ServiceRegistryControllerTestCase, cls).setUpClass() tests_config.parse_args(coordinator_noop=True) cls.coordinator = coordination.get_coordinator(use_cache=False) + # make sure api group is deleted for test to pass + # there seems to be some dangling groups being created in the unit tests + try: + cls.coordinator.delete_group("api").get() + except tooz.coordination.GroupNotCreated: + pass # NOTE: We mock call common_setup to emulate service being registered in the service # registry during bootstrap phase @@ -47,7 +55,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): - super(ServiceyRegistryControllerTestCase, cls).tearDownClass() + super(ServiceRegistryControllerTestCase, cls).tearDownClass() coordination.coordinator_teardown(cls.coordinator) From 4ca329ea134747ff1889827efbfe0647d45806bd Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sat, 14 Sep 2024 12:16:15 -0500 Subject: [PATCH 7/9] Raise correct tooz error in NoOp Coordinator --- st2common/st2common/services/coordination.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/st2common/st2common/services/coordination.py b/st2common/st2common/services/coordination.py index acd8bb0b1e..8f693f56e5 100644 --- a/st2common/st2common/services/coordination.py +++ b/st2common/st2common/services/coordination.py @@ -138,7 +138,10 @@ def leave_group(cls, group_id): @classmethod def delete_group(cls, group_id): - del cls.groups[group_id] + try: + del cls.groups[group_id] + except KeyError: + raise GroupNotCreated(group_id) return NoOpAsyncResult() @classmethod From 155b74bcd692347af6d65c373eb2d05a9d88fee8 Mon Sep 17 00:00:00 2001 From: guzzijones12 Date: Wed, 11 Sep 2024 13:31:45 -0400 Subject: [PATCH 8/9] extend process execution max time for now --- .../tests/integration/test_python_action_process_wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/runners/python_runner/tests/integration/test_python_action_process_wrapper.py b/contrib/runners/python_runner/tests/integration/test_python_action_process_wrapper.py index 3c609e26b5..c1aa148433 100644 --- a/contrib/runners/python_runner/tests/integration/test_python_action_process_wrapper.py +++ b/contrib/runners/python_runner/tests/integration/test_python_action_process_wrapper.py @@ -45,7 +45,7 @@ __all__ = ["PythonRunnerActionWrapperProcessTestCase"] # Maximum limit for the process wrapper script execution time (in seconds) -WRAPPER_PROCESS_RUN_TIME_UPPER_LIMIT = 0.31 +WRAPPER_PROCESS_RUN_TIME_UPPER_LIMIT = 0.70 ASSERTION_ERROR_MESSAGE = """ Python wrapper process script took more than %s seconds to execute (%s). This most likely means From 4f0f500699bd02c667c336ec60bbf06bfe0bce1b Mon Sep 17 00:00:00 2001 From: guzzijones12 Date: Mon, 9 Sep 2024 15:43:45 -0400 Subject: [PATCH 9/9] remove orig from conflict resolution --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 090159801f..dc1b6aec20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.py[cod] *.sqlite *.log +*.orig .stamp* # C extensions @@ -71,4 +72,4 @@ benchmark_histograms/ [._]*.sw[a-p]x [._]sw[a-p]x -**/build/lib/** \ No newline at end of file +**/build/lib/**