Changeset 19718 in josm for trunk/test


Ignore:
Timestamp:
2026-11-29T09:59:39+01:00 (21 hours ago)
Author:
GerdP
Message:

fix #25133: WMS Continued retries after response 500

  • Improve error handling with WMS (return codes 500,503)
  • tile-retry-backoff.patch by wangi
Location:
trunk/test/unit/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java

    r19709 r19718  
    132132        doTestStatusCode(501);
    133133        doTestStatusCode(502);
     134        doTestStatusCode(503);
     135        doTestStatusCode(504);
    134136    }
    135137
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java

    r19709 r19718  
    44import static org.junit.jupiter.api.Assertions.assertArrayEquals;
    55import static org.junit.jupiter.api.Assertions.assertEquals;
     6import static org.junit.jupiter.api.Assertions.assertFalse;
    67import static org.junit.jupiter.api.Assertions.assertNotSame;
    78import static org.junit.jupiter.api.Assertions.assertTrue;
    … …  
    107108        private CacheEntryAttributes attributes;
    108109        private boolean ready;
     110        private int notifications;
    109111        private byte[] data;
    110112
    … …  
    112114        public synchronized void tileLoadingFinished(Tile tile, boolean success) {
    113115            ready = true;
     116            notifications++;
    114117            this.notifyAll();
     118        }
     119
     120        synchronized boolean waitForNotifications(int count, long timeoutMillis) throws InterruptedException {
     121            long end = System.currentTimeMillis() + timeoutMillis;
     122            while (notifications < count) {
     123                long remaining = end - System.currentTimeMillis();
     124                if (remaining <= 0) {
     125                    return false;
     126                }
     127                wait(remaining);
     128            }
     129            return true;
    115130        }
    116131    }
    … …  
    373388        assertNotSame(Tile.LOADING_IMAGE, tile.getImage(), "the tile still shows the hourglass");
    374389    }
     390
     391    /**
     392     * A 5xx response is a transient error: the tile is downloaded again, but only after a delay and a limited number of times.
     393     * Until then, the tile stays loaded with its error, so the layer neither shows nothing nor downloads it again at once.
     394     * Non-regression test for #25133.
     395     * @throws Exception exception
     396     */
     397    @Test
     398    void testTransientErrorRetriedWithDelay() throws Exception {
     399        TMSCachedTileLoaderJob.TRANSIENT_ERROR_RETRY_DELAY.put(50L);
     400        final int retries = TMSCachedTileLoaderJob.TRANSIENT_ERROR_RETRIES.get();
     401        wireMockRuntimeInfo.getWireMock().register(
     402                WireMock.get(WireMock.urlEqualTo("/error"))
     403                .willReturn(WireMock.serverError())
     404                );
     405        MockTile tile = new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/error");
     406
     407        for (int attempt = 0; attempt <= retries; attempt++) {
     408            // as the layer does at a repaint, download the tile when it is not loaded
     409            assertFalse(tile.isLoaded() || tile.isLoading(), "the tile isn't due for a download");
     410            Listener listener = new Listener();
     411            new TestCachedTileLoaderJob(listener, tile, "error").submit(false);
     412            assertTrue(listener.waitForNotifications(1, 10_000), "the download didn't finish");
     413
     414            wireMockRuntimeInfo.getWireMock().verifyThat(attempt + 1, WireMock.getRequestedFor(WireMock.urlEqualTo("/error")));
     415            assertTrue(tile.hasError(), "the tile doesn't show the error");
     416            assertTrue(tile.isLoaded(), "the tile would be downloaded again at once");
     417
     418            if (attempt < retries) {
     419                // after the delay, the tile is due for a download again
     420                assertTrue(listener.waitForNotifications(2, 10_000), "the tile wasn't retried");
     421                assertFalse(tile.isLoaded(), "the tile wasn't retried");
     422            } else {
     423                // no more retries
     424                assertFalse(listener.waitForNotifications(2, 50L << retries), "the tile was retried too often");
     425                assertTrue(tile.isLoaded(), "the tile was retried too often");
     426            }
     427        }
     428    }
    375429}
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayerTest.java

    r18870 r19718  
    66import static org.junit.jupiter.api.Assertions.assertFalse;
    77import static org.junit.jupiter.api.Assertions.assertNotNull;
     8import static org.junit.jupiter.api.Assertions.assertNull;
     9import static org.junit.jupiter.api.Assertions.assertSame;
    810import static org.junit.jupiter.api.Assertions.assertTrue;
    911
    … …  
    198200        assertDoesNotThrow(() -> testLayer.new TileSourceLayerPopup(100, 100));
    199201    }
     202
     203    /**
     204     * Test {@link AbstractTileSourceLayer#getTileStatusImage}: a tile shows the error image or the hourglass only once
     205     * it has failed, until it is loaded successfully. Non-regression test for #25133.
     206     */
     207    @Test
     208    void testTileStatusImage() {
     209        Tile tile = new Tile(testLayer.tileSource, 1, 1, 1);
     210        tile.initLoading();
     211        assertNull(testLayer.getTileStatusImage(tile), "a tile which never failed shows its normal loading");
     212
     213        tile.finishLoading();
     214        tile.setError("HTTP error 503 when loading tiles");
     215        testLayer.tileLoadingFinished(tile, false);
     216        assertSame(Tile.ERROR_IMAGE, testLayer.getTileStatusImage(tile));
     217
     218        // the retry after a transient error
     219        tile.setLoaded(false);
     220        assertSame(Tile.ERROR_IMAGE, testLayer.getTileStatusImage(tile));
     221        tile.initLoading();
     222        assertSame(Tile.LOADING_IMAGE, testLayer.getTileStatusImage(tile));
     223
     224        testLayer.getDisplaySettings().setShowErrors(false);
     225        assertNull(testLayer.getTileStatusImage(tile), "errors are not shown");
     226        testLayer.getDisplaySettings().setShowErrors(true);
     227
     228        tile.finishLoading();
     229        testLayer.tileLoadingFinished(tile, true);
     230        assertNull(testLayer.getTileStatusImage(tile), "a tile loaded successfully shows its image");
     231
     232        // after a success, normal loading is shown again
     233        tile.initLoading();
     234        assertNull(testLayer.getTileStatusImage(tile));
     235    }
    200236}
Note: See TracChangeset for help on using the changeset viewer.