Skip to content

Commit

Permalink
Fix #23257: MVTTileTest has an infrequently hit race condition (patch…
Browse files Browse the repository at this point in the history
… 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.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18892 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Oct 31, 2023
1 parent 3342dd3 commit 3dee2d3
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
import java.util.Collections;
import java.util.stream.Stream;

import org.apache.commons.jcs3.access.behavior.ICacheAccess;
import org.awaitility.Awaitility;
import org.awaitility.Durations;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.openstreetmap.gui.jmapviewer.Tile;
import org.openstreetmap.gui.jmapviewer.interfaces.TileJob;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
import org.openstreetmap.josm.data.cache.JCSCacheManager;
import org.openstreetmap.josm.data.imagery.ImageryInfo;
import org.openstreetmap.josm.data.imagery.TileJobOptions;
Expand All @@ -25,15 +29,28 @@
* Test class for {@link MVTTile}
*/
class MVTTileTest {
private static ICacheAccess<String, BufferedImageCacheEntry> cache;
private MapboxVectorTileSource tileSource;
private MapboxVectorCachedTileLoader loader;

@BeforeAll
static void classSetup() {
cache = JCSCacheManager.getCache("testMapillaryCache");
}

@AfterAll
static void classTearDown() {
cache.clear();
cache = null;
}

@BeforeEach
void setup() {
cache.clear();
tileSource = new MapboxVectorTileSource(new ImageryInfo("Test Mapillary", "file:/" + TestUtils.getTestDataRoot()
+ "pbf/mapillary/{z}/{x}/{y}.mvt"));
loader = new MapboxVectorCachedTileLoader(null,
JCSCacheManager.getCache("testMapillaryCache"), new TileJobOptions(1, 1, Collections
.emptyMap(), 3600));
final TileJobOptions options = new TileJobOptions(1, 1, Collections.emptyMap(), 3600);
loader = new MapboxVectorCachedTileLoader(null, cache, options);
}

/**
Expand All @@ -57,10 +74,11 @@ void testMVTTile(BufferedImage image, Boolean isLoaded) {
assertEquals(image, tile.getImage());

TileJob job = loader.createTileLoaderJob(tile);
job.submit();
// Ensure that we are not getting a cached tile
job.submit(true);
Awaitility.await().atMost(Durations.ONE_SECOND).until(tile::isLoaded);
if (isLoaded) {
Awaitility.await().atMost(Durations.ONE_SECOND).until(() -> tile.getLayers() != null && tile.getLayers().size() > 1);
Awaitility.await().atMost(Durations.ONE_SECOND).until(() -> tile.getImage() == MVTTile.CLEAR_LOADED);
assertEquals(2, tile.getLayers().size());
assertEquals(4096, tile.getExtent());
// Ensure that we have the clear image set, such that the tile doesn't add to the dataset again
Expand Down

0 comments on commit 3dee2d3

Please sign in to comment.