|
6 | 6 | from typing import Optional |
7 | 7 |
|
8 | 8 | import pytest |
| 9 | +import timeout_decorator |
9 | 10 | from mock_vws import MockVWS |
10 | 11 | from mock_vws.database import VuforiaDatabase |
11 | 12 |
|
@@ -364,6 +365,42 @@ def test_custom_seconds_between_requests( |
364 | 365 | ) |
365 | 366 | assert report['request_usage'] == expected_requests |
366 | 367 |
|
| 368 | + def test_custom_timeout( |
| 369 | + self, |
| 370 | + high_quality_image: io.BytesIO, |
| 371 | + ) -> None: |
| 372 | + """ |
| 373 | + It is possible to set a maximum timeout. |
| 374 | + """ |
| 375 | + with MockVWS(processing_time_seconds=0.5) as mock: |
| 376 | + database = VuforiaDatabase() |
| 377 | + mock.add_database(database=database) |
| 378 | + client = VWS( |
| 379 | + server_access_key=database.server_access_key.decode(), |
| 380 | + server_secret_key=database.server_secret_key.decode(), |
| 381 | + ) |
| 382 | + |
| 383 | + target_id = client.add_target( |
| 384 | + name='x', |
| 385 | + width=1, |
| 386 | + image=high_quality_image, |
| 387 | + ) |
| 388 | + |
| 389 | + report = client.get_target_summary_report(target_id=target_id) |
| 390 | + assert report['status'] == 'processing' |
| 391 | + with pytest.raises(timeout_decorator.TimeoutError): |
| 392 | + client.wait_for_target_processed( |
| 393 | + target_id=target_id, |
| 394 | + timeout_seconds=0.1, |
| 395 | + ) |
| 396 | + |
| 397 | + client.wait_for_target_processed( |
| 398 | + target_id=target_id, |
| 399 | + timeout_seconds=0.5, |
| 400 | + ) |
| 401 | + report = client.get_target_summary_report(target_id=target_id) |
| 402 | + assert report['status'] != 'processing' |
| 403 | + |
367 | 404 |
|
368 | 405 | class TestGetDuplicateTargets: |
369 | 406 | """ |
|
0 commit comments