Skip to content

Commit

Permalink
Merge pull request #20913 from osmandapp/chumva_fixes
Browse files Browse the repository at this point in the history
Try to fix GPXTrackAnalysisUpdatesTest
  • Loading branch information
Chumva authored Sep 26, 2024
2 parents 41a6e88 + 14a8aac commit 5da994e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ object GpxDbHelper : GpxReaderAdapter {
private const val READER_TASKS_LIMIT = 4
private var readers = mutableListOf<GpxReader>()
private var readerSync = Synchronizable()
var readTrackItemCount: Long = 0

private var initialized: Boolean = false

Expand Down Expand Up @@ -250,7 +249,6 @@ object GpxDbHelper : GpxReaderAdapter {
}
val item = dataItems[file]
if (GpxDbUtils.isAnalyseNeeded(item)) {
readTrackItemCount++
readGpxItem(file, item, callback)
}
return item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
import net.osmand.plus.track.helpers.GpxSelectionHelper;
import net.osmand.plus.utils.OsmAndFormatter;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.shared.data.KQuadRect;
import net.osmand.shared.gpx.GpxDataItem;
import net.osmand.shared.gpx.GpxDbHelper;
import net.osmand.shared.gpx.GpxDbHelper.GpxDataItemCallback;
import net.osmand.shared.gpx.GpxFile;
import net.osmand.shared.gpx.GpxTrackAnalysis;
import net.osmand.test.common.AndroidTest;
import net.osmand.test.common.BaseIdlingResource;
import net.osmand.test.common.ResourcesImporter;
Expand Down Expand Up @@ -77,6 +81,12 @@ public void onGpxSaved(@Nullable String error, @NotNull GpxFile gpxFile) {
file = new File(ImportHelper.getGpxDestinationDir(app, true), SELECTED_GPX_NAME);
gpxFile.setPath(file.getAbsolutePath());
selectionHelper.selectGpxFile(gpxFile, GpxSelectionParams.getDefaultSelectionParams());

KQuadRect rect = gpxFile.getRect();
if (rect.getLeft() != 0 && rect.getRight() != 0) {
app.getOsmandMap().getMapView().fitRectToMap(rect.getLeft(), rect.getRight(),
rect.getTop(), rect.getBottom(), (int) rect.width(), (int) rect.height(), 0);
}
}
}
});
Expand Down Expand Up @@ -110,6 +120,8 @@ private class ObserveDistToFinishIdlingResource extends BaseIdlingResource {
private static final int LOW_FPS_VALUE = 15;
private static final int LOW_FPS_COUNT = 10;

private GpxTrackAnalysis analysis;

private int checksCounter;
private int lowFpsCounter;

Expand All @@ -124,7 +136,7 @@ private void startHandler() {
checksCounter++;

checkFPS();
checkAnalysisUpdate();
checkAnalysisUpdate(); // simulate multiple calls for getting GpxDataItem

if (isIdleNow()) {
notifyIdleTransition();
Expand All @@ -151,10 +163,21 @@ private void checkFPS() {
}

private void checkAnalysisUpdate() {
gpxDbHelper.getItem(SharedUtil.kFile(file)); // simulate multiple calls for getting GpxDataItem
long readItemCount = gpxDbHelper.getReadTrackItemCount();
if (readItemCount > 2) {
throw new AssertionError("To many updates of analysis " + readItemCount);
GpxDataItem dataItem = gpxDbHelper.getItem(SharedUtil.kFile(file), new GpxDataItemCallback() {
@Override
public boolean isCancelled() {
return false;
}

@Override
public void onGpxDataItemReady(@NotNull GpxDataItem item) {
if (analysis != item.getAnalysis()) {
throw new AssertionError("To many updates of analysis ");
}
}
});
if (analysis == null && dataItem != null) {
analysis = dataItem.getAnalysis();
}
}

Expand Down

0 comments on commit 5da994e

Please sign in to comment.