Changeset 18892 in josm


Ignore:
Timestamp:
2023-10-31T21:27:34+01:00 (8 months ago)
Author:
taylor.smock
Message:

Fix #23257: MVTTileTest has an infrequently hit race condition (patch by marcello, modified)

The race condition is dependent upon calculation speed; if the layers get loaded
prior to the image loading, it is possible for us to get to the point where
we expect the image to be loaded, but it isn't yet.

Modifications are as follows:

  • Reinitialize tileSource and loader before each test, but initialize the cache once and clear that between tests.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/vectortile/mapbox/MVTTileTest.java

    r18853 r18892  
    99import java.util.stream.Stream;
    1010
     11import org.apache.commons.jcs3.access.behavior.ICacheAccess;
    1112import org.awaitility.Awaitility;
    1213import org.awaitility.Durations;
     14import org.junit.jupiter.api.AfterAll;
     15import org.junit.jupiter.api.BeforeAll;
    1316import org.junit.jupiter.api.BeforeEach;
    1417import org.junit.jupiter.params.ParameterizedTest;
     
    1821import org.openstreetmap.gui.jmapviewer.interfaces.TileJob;
    1922import org.openstreetmap.josm.TestUtils;
     23import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
    2024import org.openstreetmap.josm.data.cache.JCSCacheManager;
    2125import org.openstreetmap.josm.data.imagery.ImageryInfo;
     
    2630 */
    2731class MVTTileTest {
     32    private static ICacheAccess<String, BufferedImageCacheEntry> cache;
    2833    private MapboxVectorTileSource tileSource;
    2934    private MapboxVectorCachedTileLoader loader;
     35
     36    @BeforeAll
     37    static void classSetup() {
     38        cache = JCSCacheManager.getCache("testMapillaryCache");
     39    }
     40
     41    @AfterAll
     42    static void classTearDown() {
     43        cache.clear();
     44        cache = null;
     45    }
     46
    3047    @BeforeEach
    3148    void setup() {
     49        cache.clear();
    3250        tileSource = new MapboxVectorTileSource(new ImageryInfo("Test Mapillary", "file:/" + TestUtils.getTestDataRoot()
    3351          + "pbf/mapillary/{z}/{x}/{y}.mvt"));
    34         loader = new MapboxVectorCachedTileLoader(null,
    35           JCSCacheManager.getCache("testMapillaryCache"), new TileJobOptions(1, 1, Collections
    36           .emptyMap(), 3600));
     52        final TileJobOptions options = new TileJobOptions(1, 1, Collections.emptyMap(), 3600);
     53        loader = new MapboxVectorCachedTileLoader(null, cache, options);
    3754    }
    3855
     
    5875
    5976        TileJob job = loader.createTileLoaderJob(tile);
    60         job.submit();
     77        // Ensure that we are not getting a cached tile
     78        job.submit(true);
    6179        Awaitility.await().atMost(Durations.ONE_SECOND).until(tile::isLoaded);
    6280        if (isLoaded) {
    63             Awaitility.await().atMost(Durations.ONE_SECOND).until(() -> tile.getLayers() != null && tile.getLayers().size() > 1);
     81            Awaitility.await().atMost(Durations.ONE_SECOND).until(() -> tile.getImage() == MVTTile.CLEAR_LOADED);
    6482            assertEquals(2, tile.getLayers().size());
    6583            assertEquals(4096, tile.getExtent());
Note: See TracChangeset for help on using the changeset viewer.