1
- # Copyright (c) 2020-2023 The MathWorks, Inc.
1
+ # Copyright 2020-2023 The MathWorks, Inc.
2
2
3
3
import asyncio
4
+ import datetime
4
5
import json
5
6
import platform
7
+ import random
6
8
import time
7
- import datetime
9
+ from datetime import timedelta , timezone
10
+ from http import HTTPStatus
8
11
9
12
import aiohttp
10
13
import pytest
11
- import random
12
- from http import HTTPStatus
14
+ import test_constants
15
+
13
16
from matlab_proxy import app , util
14
17
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
19
19
20
20
21
21
def test_create_app ():
@@ -314,8 +314,18 @@ async def test_root_redirect(test_server):
314
314
test_server (aiohttp_client): A aiohttp_client server to send HTTP GET request.
315
315
316
316
"""
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
319
329
320
330
321
331
@pytest .fixture (name = "proxy_payload" )
@@ -343,10 +353,21 @@ async def test_matlab_proxy_404(proxy_payload, test_server):
343
353
344
354
# Request a non-existing html file.
345
355
# 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
350
371
351
372
352
373
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):
369
390
"/http_get_request.html" , data = json .dumps (proxy_payload )
370
391
)
371
392
372
- if resp .status == 404 :
393
+ if resp .status in ( HTTPStatus . NOT_FOUND , HTTPStatus . SERVICE_UNAVAILABLE ) :
373
394
time .sleep (1 )
374
395
count += 1
375
396
@@ -402,7 +423,7 @@ async def test_matlab_proxy_http_put_request(proxy_payload, test_server):
402
423
"/http_put_request.html" , data = json .dumps (proxy_payload )
403
424
)
404
425
405
- if resp .status == 404 :
426
+ if resp .status in ( HTTPStatus . NOT_FOUND , HTTPStatus . SERVICE_UNAVAILABLE ) :
406
427
time .sleep (1 )
407
428
count += 1
408
429
@@ -435,7 +456,7 @@ async def test_matlab_proxy_http_delete_request(proxy_payload, test_server):
435
456
"/http_delete_request.html" , data = json .dumps (proxy_payload )
436
457
)
437
458
438
- if resp .status == 404 :
459
+ if resp .status in ( HTTPStatus . NOT_FOUND , HTTPStatus . SERVICE_UNAVAILABLE ) :
439
460
time .sleep (1 )
440
461
count += 1
441
462
@@ -467,7 +488,7 @@ async def test_matlab_proxy_http_post_request(proxy_payload, test_server):
467
488
data = json .dumps (proxy_payload ),
468
489
)
469
490
470
- if resp .status == 404 :
491
+ if resp .status in ( HTTPStatus . NOT_FOUND , HTTPStatus . SERVICE_UNAVAILABLE ) :
471
492
time .sleep (1 )
472
493
count += 1
473
494
0 commit comments