Skip to content

Commit

Permalink
Merge pull request #13 from locp/bugfix/12-test-interval-being-ignored
Browse files Browse the repository at this point in the history
Test interval being ignored
  • Loading branch information
dallinb authored Sep 19, 2022
2 parents 23726a0 + 532af29 commit 67f2f4a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Changelog


## 1.0.0
## 1.0.1

### Fix

* Avoid false positive when no services are available. [Ben Dalling]


## 1.0.0 (2022-08-11)

### New

Expand Down
Binary file modified docs/.doctrees/environment.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[coverage:report]
fail_under = 55.0
fail_under = 80.0
show_missing = True

[coverage:run]
Expand Down
2 changes: 1 addition & 1 deletion tests/step_defs/test_wait4localstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def wait4localstack_object():
def method_is_called_with_method_arguments(method, method_arguments, wait4localstack_fixture):
"""<method> is called with <method_arguments>."""
wait4localstack_fixture['method'] = method
widget = Wait4Localstack()
widget = Wait4Localstack(maximum_retries=1)

if method == 'exponential_backoff':
b = (method_arguments == 'True')
Expand Down
2 changes: 1 addition & 1 deletion wait4localstack/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1
31 changes: 17 additions & 14 deletions wait4localstack/localstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def __init__(self, connection_url, logger) -> None:
self.service_names = []
self.services = {}
data = self.get_connection_details()

if data:
self.live = True
else:
self.live = False
self.parse_services(data)

def get_connection_details(self):
"""
Expand All @@ -40,7 +36,7 @@ def get_connection_details(self):
dict
The connection string having being parsed as JSON.
"""
data = None
data = {}
logger = self.logger()
http = urllib3.PoolManager()

Expand All @@ -49,7 +45,9 @@ def get_connection_details(self):
r = http.request('GET', self.connection_url)

if r.status == 200:
logger.debug(f'Response is "{r.data}".')
data = json.loads(r.data)
logger.debug(f'Data is "{data}".')
else:
logger.warning(f'Unexpected status ({r.status}) from {self.connection_url}.')
except urllib3.exceptions.MaxRetryError as e:
Expand All @@ -66,19 +64,20 @@ def is_live(self):
bool
True if all services are available, False otherwise.
"""
response = True
logger = self.logger
live_services_count = 0
services_count = len(self.service_names)
logger = self.logger()

for service_name in self.service_names:
service = self.services[service_name]

if service.is_available():
logger.info(f'Service {service_name} is available/running.')
live_services_count += 1
else:
response = False
logger.error(f'Service {service_name} status is {service.status}.')

return response
return (services_count and live_services_count == services_count)

def logger(self, logger=None):
"""
Expand Down Expand Up @@ -107,14 +106,18 @@ def parse_services(self, data):
data : dict
The data (parsed from JSON text).
"""
logger = self.logger
logger = self.logger()
self.service_names = []
self.services = {}

try:
services = data['service']
services = data['services']

for service_name in services:
service_status = services[service_name]
logger.debug(f'Status of {service_name} is {service_status}.')
service = wait4localstack.service.Service(name, service_status)
self.service_names.append(service_name)
self.services[service_name] = service
except KeyError as ex:
logger.error(f'Unable to parse health endpoint response ({str(ex)}).')
except KeyError:
logger.error(f'Unable to parse health endpoint response ("{json.dumps(data)}").')

0 comments on commit 67f2f4a

Please sign in to comment.