Skip to content

Commit

Permalink
Resolve Test Failures (#528)
Browse files Browse the repository at this point in the history
* Remove deprecated `add_event` override method

* Troubleshooting test failures

* Update default MQ config

* Retry backend request on 502 return

* Troubleshoot new test failure

* Remove ovos-workshop git spec

---------

Co-authored-by: Daniel McKnight <[email protected]>
  • Loading branch information
NeonDaniel and NeonDaniel authored May 31, 2024
1 parent 013fdad commit 0efc5cf
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 32 deletions.
9 changes: 7 additions & 2 deletions neon_utils/hana_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,14 @@ def request_backend(endpoint: str, request_data: dict,
except ServerException as e:
LOG.error(e)
_get_token(server_url)
resp = requests.post(f"{server_url}/{endpoint.lstrip('/')}",
json=request_data, headers=_headers)
request_kwargs = {"url": f"{server_url}/{endpoint.lstrip('/')}",
"json": request_data, "headers": _headers}
resp = requests.post(**request_kwargs)
if resp.status_code == 502:
# This is raised occasionally on valid requests. Need to resolve in HANA
resp = requests.post(**request_kwargs)
if resp.ok:
return resp.json()

else:
raise ServerException(f"Error response {resp.status_code}: {resp.text}")
2 changes: 1 addition & 1 deletion neon_utils/mq_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
logging.getLogger("pika").setLevel(logging.CRITICAL)

_default_mq_config = {
"server": "api.neon.ai",
"server": "mq.neonaiservices.com",
"port": 5672,
"users": {
"mq_handler": {
Expand Down
6 changes: 2 additions & 4 deletions neon_utils/skills/kiosk_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ def stop(self):
if user in self._active_users:
self.end_interaction(message)

def _on_event_error(self, error, message, handler_info,
skill_data, speak_errors):
def _on_event_error(self, error, message, *args, **kwargs):
"""
Override error handling to speak custom exception for active sessions
"""
Expand All @@ -208,5 +207,4 @@ def _on_event_error(self, error, message, handler_info,
LOG.exception(error)
self.handle_error(message)
else:
super()._on_event_error(error, message, handler_info,
skill_data, speak_errors)
super()._on_event_error(error, message, *args, **kwargs)
20 changes: 0 additions & 20 deletions neon_utils/skills/neon_fallback_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,23 +875,3 @@ def init_dialog(self, root_directory: Optional[str] = None):
"""
log_deprecation("Use `load_dialog_files`", "2.0.0")
self.load_dialog_files(root_directory)

def add_event(self, name: str, handler: callable,
handler_info: Optional[str] = None, once: bool = False,
speak_errors: bool = True):
# TODO: Remove with ovos-workshop==0.0.13
try:
# Patching FakeBus compat. with MessageBusClient
if hasattr(self.bus, "ee"):
emitter = self.bus.ee
else:
emitter = self.bus.emitter
if handler_info == "mycroft.skill.handler" and \
emitter.listeners(name):
LOG.warning(f"Not re-registering intent handler {name}")
return
except Exception as e:
LOG.exception(e)
OVOSSkill.add_event(self, name, handler, handler_info, once,
speak_errors)

2 changes: 1 addition & 1 deletion tests/neon_skill_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def is_valid(_):
test_results["validator"] = True
return False

on_fail = Mock()
on_fail = Mock(return_value="fail")

def skill_response_thread(s: MycroftSkill, idx: str):
resp = s.get_response(test_dialog, validator=is_valid,
Expand Down
10 changes: 6 additions & 4 deletions tests/net_util_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

TCP_TEST = "mq.neonaiservices.com"


class NetUtilTests(unittest.TestCase):
@classmethod
Expand Down Expand Up @@ -119,18 +121,18 @@ def mock_socket(*args, **kwargs):
def test_check_url_connection_invalid_url(self):
from neon_utils.net_utils import check_url_response

self.assertFalse(check_url_response("https://api.neon.ai"))
self.assertFalse(check_url_response(f"https://{TCP_TEST}"))

def test_check_online_valid_online(self):
from neon_utils.net_utils import check_online
self.assertTrue(check_online())
self.assertTrue(check_online(("google.com", "github.com")))
self.assertTrue(check_online(("api.neon.ai", "google.com")))
self.assertTrue(check_online((TCP_TEST, "google.com")))
self.assertTrue(check_online(("", "google.com")))

def test_check_online_invalid_offline(self):
from neon_utils.net_utils import check_online
self.assertFalse(check_online(("api.neon.ai",)))
self.assertFalse(check_online((TCP_TEST,)))
self.assertFalse(check_online(("",)))

def test_check_online_valid_offline(self):
Expand All @@ -152,7 +154,7 @@ def test_check_online_invalid_params(self):

def test_check_port_is_open(self):
from neon_utils.net_utils import check_port_is_open
self.assertTrue(check_port_is_open("api.neon.ai", 5672))
self.assertTrue(check_port_is_open(TCP_TEST, 5672))
self.assertFalse(check_port_is_open("www.neon.ai", 5672))


Expand Down

0 comments on commit 0efc5cf

Please sign in to comment.