Skip to content

Commit 5de4355

Browse files
krisctlPrabhakar Kumar
authored andcommitted
Updates test points to include SERVICE_UNAVAILABLE status errors.
1 parent e8316cd commit 5de4355

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

matlab_proxy/app.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,7 @@ async def matlab_view(req):
475475
logger.debug(
476476
"MATLAB hasn't fully started, please retry after embedded connector has started"
477477
)
478-
raise web.HTTPServiceUnavailable(
479-
"MATLAB hasn't fully started yet, please retry after some time."
480-
)
478+
raise web.HTTPServiceUnavailable()
481479

482480
# WebSocket
483481
# According to according to RFC6455 (https://www.rfc-editor.org/rfc/rfc6455.html)

tests/test_app.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# Copyright (c) 2020-2023 The MathWorks, Inc.
1+
# Copyright 2020-2023 The MathWorks, Inc.
22

33
import asyncio
4+
import datetime
45
import json
56
import platform
7+
import random
68
import time
7-
import datetime
9+
from datetime import timedelta, timezone
10+
from http import HTTPStatus
811

912
import aiohttp
1013
import pytest
11-
import random
12-
from http import HTTPStatus
14+
import test_constants
15+
1316
from matlab_proxy import app, util
1417
from matlab_proxy.util.mwi import environment_variables as mwi_env
15-
from matlab_proxy.util.mwi.exceptions import MatlabInstallError
16-
from datetime import timedelta, timezone
17-
from matlab_proxy.util.mwi.exceptions import EntitlementError
18-
import test_constants
18+
from matlab_proxy.util.mwi.exceptions import EntitlementError, MatlabInstallError
1919

2020

2121
def test_create_app():
@@ -314,8 +314,18 @@ async def test_root_redirect(test_server):
314314
test_server (aiohttp_client): A aiohttp_client server to send HTTP GET request.
315315
316316
"""
317-
resp = await test_server.get("/")
318-
assert resp.status == 404
317+
count = 0
318+
while True:
319+
resp = await test_server.get("/")
320+
if resp.status == HTTPStatus.SERVICE_UNAVAILABLE:
321+
time.sleep(test_constants.ONE_SECOND_DELAY)
322+
count += 1
323+
else:
324+
assert resp.status == HTTPStatus.NOT_FOUND
325+
break
326+
327+
if count > test_constants.FIVE_MAX_TRIES:
328+
raise ConnectionError
319329

320330

321331
@pytest.fixture(name="proxy_payload")
@@ -343,10 +353,21 @@ async def test_matlab_proxy_404(proxy_payload, test_server):
343353

344354
# Request a non-existing html file.
345355
# Request gets proxied to app.matlab_view() which should raise HTTPNotFound() exception ie. return HTTP status code 404
346-
resp = await test_server.post(
347-
"./1234.html", data=json.dumps(proxy_payload), headers=headers
348-
)
349-
assert resp.status == 404
356+
357+
count = 0
358+
while True:
359+
resp = await test_server.post(
360+
"./1234.html", data=json.dumps(proxy_payload), headers=headers
361+
)
362+
if resp.status == HTTPStatus.SERVICE_UNAVAILABLE:
363+
time.sleep(test_constants.ONE_SECOND_DELAY)
364+
count += 1
365+
else:
366+
assert resp.status == HTTPStatus.NOT_FOUND
367+
break
368+
369+
if count > test_constants.FIVE_MAX_TRIES:
370+
raise ConnectionError
350371

351372

352373
async def test_matlab_proxy_http_get_request(proxy_payload, test_server):
@@ -369,7 +390,7 @@ async def test_matlab_proxy_http_get_request(proxy_payload, test_server):
369390
"/http_get_request.html", data=json.dumps(proxy_payload)
370391
)
371392

372-
if resp.status == 404:
393+
if resp.status in (HTTPStatus.NOT_FOUND, HTTPStatus.SERVICE_UNAVAILABLE):
373394
time.sleep(1)
374395
count += 1
375396

@@ -402,7 +423,7 @@ async def test_matlab_proxy_http_put_request(proxy_payload, test_server):
402423
"/http_put_request.html", data=json.dumps(proxy_payload)
403424
)
404425

405-
if resp.status == 404:
426+
if resp.status in (HTTPStatus.NOT_FOUND, HTTPStatus.SERVICE_UNAVAILABLE):
406427
time.sleep(1)
407428
count += 1
408429

@@ -435,7 +456,7 @@ async def test_matlab_proxy_http_delete_request(proxy_payload, test_server):
435456
"/http_delete_request.html", data=json.dumps(proxy_payload)
436457
)
437458

438-
if resp.status == 404:
459+
if resp.status in (HTTPStatus.NOT_FOUND, HTTPStatus.SERVICE_UNAVAILABLE):
439460
time.sleep(1)
440461
count += 1
441462

@@ -467,7 +488,7 @@ async def test_matlab_proxy_http_post_request(proxy_payload, test_server):
467488
data=json.dumps(proxy_payload),
468489
)
469490

470-
if resp.status == 404:
491+
if resp.status in (HTTPStatus.NOT_FOUND, HTTPStatus.SERVICE_UNAVAILABLE):
471492
time.sleep(1)
472493
count += 1
473494

0 commit comments

Comments
 (0)