Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2793 from forslund/bugfix/vk-error-stability
Browse files Browse the repository at this point in the history
Vk error stability
  • Loading branch information
krisgesling authored Jan 11, 2021
2 parents 81eae60 + 83ed811 commit e607acd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@
from mycroft.messagebus import Message
from mycroft.util import resolve_resource_file

CONFIG_CHANGE_TIMEOUT = 10


def wait_for_config_change(context, key, expected_value):
"""Wait for a config change to apply.
Waits until the specified key has changed into the expected value, if
the change delays for too long a TimeoutError will be raised.
Arguments:
context (Context): Behave context of current scenario
key (str): key to verify
expected_value (Object): The expected value indicating that the change
has been applied
"""
start_time = time.monotonic()
while context.config.get(key) != expected_value:
time.sleep(0.5)
if time.monotonic() - start_time >= CONFIG_CHANGE_TIMEOUT:
raise TimeoutError


def reset_config(context):
"""Cleanup callback to reset patched configuration
Expand All @@ -30,8 +51,7 @@ def reset_config(context):
context.log.info('Resetting patched configuration...')
context.bus.emit(Message('configuration.patch.clear'))
key = list(context.original_config)[0]
while context.config[key] != context.original_config[key]:
time.sleep(0.5)
wait_for_config_change(context, key, context.original_config[key])


def patch_config(context, patch):
Expand Down Expand Up @@ -60,8 +80,7 @@ def patch_config(context, patch):

# Wait until one of the keys has been updated
key = list(patch.keys())[0]
while context.config.get(key) != patch[key]:
time.sleep(0.5)
wait_for_config_change(context, key, patch[key])


def get_config_file_definition(configs_path, config, value):
Expand Down
2 changes: 1 addition & 1 deletion test/integrationtests/voight_kampff/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def mycroft_responses(context):
responses = 'Mycroft responded with:\n'
for m in messages:
responses += 'Mycroft: '
if 'dialog' in m.data['meta']:
if 'meta' in m.data and 'dialog' in m.data['meta']:
responses += '{}.dialog'.format(m.data['meta']['dialog'])
responses += '({})\n'.format(m.data['meta'].get('skill'))
responses += '"{}"\n'.format(m.data['utterance'])
Expand Down

0 comments on commit e607acd

Please sign in to comment.