|
3 | 3 | # This file is part of Pyosmium. |
4 | 4 | # |
5 | 5 | # Copyright (C) 2023 Sarah Hoffmann. |
| 6 | +import logging |
6 | 7 | import time |
7 | 8 | from textwrap import dedent |
8 | 9 |
|
@@ -124,6 +125,35 @@ def test_get_state_timestamp_cut(httpserver): |
124 | 125 | assert res.sequence == 2594669 |
125 | 126 |
|
126 | 127 |
|
| 128 | +def test_get_state_permanent_error(httpserver, caplog): |
| 129 | + httpserver.expect_request('/state.txt').respond_with_data('stuff', status=404) |
| 130 | + |
| 131 | + with caplog.at_level(logging.DEBUG): |
| 132 | + res = rserv.ReplicationServer(httpserver.url_for('')).get_state_info() |
| 133 | + |
| 134 | + assert res is None |
| 135 | + assert "Loading state info failed" in caplog.text |
| 136 | + |
| 137 | + |
| 138 | +def test_get_state_transient_error(httpserver): |
| 139 | + httpserver.expect_ordered_request('/state.txt').respond_with_data('stuff', status=500) |
| 140 | + httpserver.expect_ordered_request('/state.txt').respond_with_data('stuff', status=500) |
| 141 | + httpserver.expect_ordered_request('/state.txt').respond_with_data("""\ |
| 142 | + #Sat Aug 26 11:04:04 UTC 2017 |
| 143 | + txnMaxQueried=1219304113 |
| 144 | + sequenceNumber=2594669 |
| 145 | + timestamp=2017-08-26T11\\:04\\:02Z |
| 146 | + txnReadyList= |
| 147 | + txnMax=1219304113 |
| 148 | + txnActiveList=1219303583,1219304054,1219304104""") |
| 149 | + |
| 150 | + res = rserv.ReplicationServer(httpserver.url_for('')).get_state_info() |
| 151 | + |
| 152 | + assert res is not None |
| 153 | + assert res.timestamp == mkdate(2017, 8, 26, 11, 4, 2) |
| 154 | + assert res.sequence == 2594669 |
| 155 | + |
| 156 | + |
127 | 157 | def test_get_state_too_many_retries(httpserver): |
128 | 158 | httpserver.expect_ordered_request('/state.txt').respond_with_data("""\ |
129 | 159 | #Sat Aug 26 11:04:04 UTC 2017 |
@@ -321,3 +351,92 @@ def way(self, w): |
321 | 351 | assert diffs is not None |
322 | 352 | diffs.reader.apply(h, idx="flex_mem") |
323 | 353 | assert h.counts == [1, 1, 0, 0] |
| 354 | + |
| 355 | + |
| 356 | +def test_apply_diffs_permanent_error(httpserver, caplog): |
| 357 | + httpserver.expect_ordered_request('/state.txt').respond_with_data("""\ |
| 358 | + sequenceNumber=100 |
| 359 | + timestamp=2017-08-26T11\\:04\\:02Z |
| 360 | + """) |
| 361 | + httpserver.expect_ordered_request('/000/000/100.opl')\ |
| 362 | + .respond_with_data('not a file', status=404) |
| 363 | + |
| 364 | + with caplog.at_level(logging.ERROR): |
| 365 | + with rserv.ReplicationServer(httpserver.url_for(''), "opl") as svr: |
| 366 | + h = CountingHandler() |
| 367 | + assert None == svr.apply_diffs(h, 100, 10000) |
| 368 | + assert h.counts == [0, 0, 0, 0] |
| 369 | + |
| 370 | + assert 'Error during diff download' in caplog.text |
| 371 | + |
| 372 | + |
| 373 | +def test_apply_diffs_permanent_error_later_diff(httpserver, caplog): |
| 374 | + httpserver.expect_ordered_request('/state.txt').respond_with_data("""\ |
| 375 | + sequenceNumber=101 |
| 376 | + timestamp=2017-08-26T11\\:04\\:02Z |
| 377 | + """) |
| 378 | + httpserver.expect_ordered_request('/000/000/100.opl').respond_with_data(dedent("""\ |
| 379 | + n1 x10.0 y23.0 |
| 380 | + w1 Nn1,n2 |
| 381 | + """)) |
| 382 | + httpserver.expect_ordered_request('/000/000/101.opl')\ |
| 383 | + .respond_with_data('not a file', status=404) |
| 384 | + |
| 385 | + with caplog.at_level(logging.ERROR): |
| 386 | + with rserv.ReplicationServer(httpserver.url_for(''), "opl") as svr: |
| 387 | + h = CountingHandler() |
| 388 | + assert 100 == svr.apply_diffs(h, 100, 10000) |
| 389 | + assert h.counts == [1, 1, 0, 0] |
| 390 | + |
| 391 | + assert 'Error during diff download' in caplog.text |
| 392 | + |
| 393 | + |
| 394 | +def test_apply_diffs_transient_error(httpserver, caplog): |
| 395 | + httpserver.expect_ordered_request('/state.txt').respond_with_data("""\ |
| 396 | + sequenceNumber=101 |
| 397 | + timestamp=2017-08-26T11\\:04\\:02Z |
| 398 | + """) |
| 399 | + httpserver.expect_ordered_request('/000/000/100.opl').respond_with_data(dedent("""\ |
| 400 | + n1 x10.0 y23.0 |
| 401 | + w1 Nn1,n2 |
| 402 | + """)) |
| 403 | + httpserver.expect_ordered_request('/000/000/101.opl')\ |
| 404 | + .respond_with_data('not a file', status=503) |
| 405 | + httpserver.expect_ordered_request('/000/000/101.opl').respond_with_data(dedent("""\ |
| 406 | + n2 x10.0 y23.0 |
| 407 | + """)) |
| 408 | + |
| 409 | + with caplog.at_level(logging.ERROR): |
| 410 | + with rserv.ReplicationServer(httpserver.url_for(''), "opl") as svr: |
| 411 | + h = CountingHandler() |
| 412 | + assert 101 == svr.apply_diffs(h, 100, 10000) |
| 413 | + assert h.counts == [2, 1, 0, 0] |
| 414 | + |
| 415 | + assert 'Error during diff download' not in caplog.text |
| 416 | + |
| 417 | + |
| 418 | + |
| 419 | + |
| 420 | +def test_apply_diffs_transient_error_permanent(httpserver, caplog): |
| 421 | + httpserver.expect_ordered_request('/state.txt').respond_with_data("""\ |
| 422 | + sequenceNumber=101 |
| 423 | + timestamp=2017-08-26T11\\:04\\:02Z |
| 424 | + """) |
| 425 | + httpserver.expect_ordered_request('/000/000/100.opl').respond_with_data(dedent("""\ |
| 426 | + n1 x10.0 y23.0 |
| 427 | + w1 Nn1,n2 |
| 428 | + """)) |
| 429 | + for _ in range(4): |
| 430 | + httpserver.expect_ordered_request('/000/000/101.opl')\ |
| 431 | + .respond_with_data('not a file', status=503) |
| 432 | + httpserver.expect_ordered_request('/000/000/101.opl').respond_with_data(dedent("""\ |
| 433 | + n2 x10.0 y23.0 |
| 434 | + """)) |
| 435 | + |
| 436 | + with caplog.at_level(logging.ERROR): |
| 437 | + with rserv.ReplicationServer(httpserver.url_for(''), "opl") as svr: |
| 438 | + h = CountingHandler() |
| 439 | + assert 100 == svr.apply_diffs(h, 100, 10000) |
| 440 | + assert h.counts == [1, 1, 0, 0] |
| 441 | + |
| 442 | + assert 'Error during diff download' in caplog.text |
0 commit comments