Skip to content

Commit 760fdcd

Browse files
authored
Merge pull request #45 from cloudblue/fix_max_connect_attemps_reached
Fix exit on max connection attemps reached
2 parents 9e784e2 + 9e3f842 commit 760fdcd

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ jobs:
5454
with:
5555
images: cloudblueconnect/connect-extension-runner
5656
tags: |
57-
type=semver,pattern={{version}},value=${{ steps.tag.outputs.result }}.0
5857
type=semver,pattern={{major}}.{{minor}},value=${{ steps.tag.outputs.result }}.0
5958
type=semver,pattern={{major}},value=${{ steps.tag.outputs.result }}.0
6059
flavor: |

connect/eaas/worker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ async def run(self): # noqa: CCR001
199199
continue
200200
await self.process_message(message)
201201
except (ConnectionClosedOK, StopBackoffError):
202+
self.run_event.set()
203+
break
204+
except (CommunicationError, MaintenanceError):
205+
logger.error('Max connection attemps reached, exit.')
206+
self.run_event.set()
202207
break
203208
except ConnectionClosedError:
204209
logger.warning(

tests/test_worker.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,3 +1180,25 @@ async def test_ensure_connection_exit_backoff(mocker, caplog):
11801180
await task
11811181

11821182
assert 'Worker exiting, stop backoff loop' in caplog.text
1183+
1184+
1185+
@pytest.mark.asyncio
1186+
async def test_ensure_connection_exit_max_attemps(mocker, caplog):
1187+
mocker.patch('connect.eaas.handler.get_extension_class')
1188+
mocker.patch('connect.eaas.handler.get_extension_type')
1189+
mocker.patch('connect.eaas.worker.MAX_RETRY_TIME_GENERIC_SECONDS', 10)
1190+
mocker.patch('connect.eaas.worker.MAX_RETRY_DELAY_TIME_SECONDS', 1)
1191+
mocker.patch(
1192+
'connect.eaas.worker.websockets.connect',
1193+
side_effect=RuntimeError('generic error'),
1194+
)
1195+
1196+
worker = Worker()
1197+
worker.run_event.set()
1198+
worker.get_url = lambda: 'ws://test'
1199+
1200+
with caplog.at_level(logging.ERROR):
1201+
task = asyncio.create_task(worker.run())
1202+
await task
1203+
1204+
assert 'Max connection attemps reached, exit.' in caplog.text

0 commit comments

Comments
 (0)