Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix GPXTrackAnalysisUpdatesTest #20913

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading