Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Node render test suite on Android #12041

Merged
merged 1 commit into from
Jun 1, 2018
Merged

Node render test suite on Android #12041

merged 1 commit into from
Jun 1, 2018

Conversation

tobrun
Copy link
Member

@tobrun tobrun commented May 31, 2018

Continuation of #10045, Closes #10047.

This PR enables running the node render test suite on Android:

Example run can be seen here, executing these tests can be done with:

make run-android-render-test-arm-v7

image

When running the render tests the following happens

  • copies test files from mapbox-gl-js/test/integration/* to app assets folder
  • builds application and executes RenderTest.java instrumentation test
  • pulls images from device and compares results with PixelMatch

The following items are open, thinking about tackling them in separate PRs:

  • update $(BUILD_DEPS)
  • use ignore.json from node to ignore tests
  • integrate in CI (nightly integration)
  • ticket out
    • ignored tests that have operations
    • integrating expressions tests
    • integrating query rendered features tests
    • ticket out failing render tests

@tobrun tobrun added the Android Mapbox Maps SDK for Android label May 31, 2018
@tobrun tobrun self-assigned this May 31, 2018
@tobrun tobrun force-pushed the tvn-render-test branch from 86b997d to 8580bd7 Compare May 31, 2018 16:01
@ChrisLoer
Copy link
Contributor

It looks like it would be relatively straightforward to extend this approach to the query tests and the expression tests? Being able to run expression tests on Android would be useful for the Collator expression which has an Android-specific implementation (#11869).

@tobrun
Copy link
Member Author

tobrun commented Jun 1, 2018

Great idea @ChrisLoer, quickly glanced at tests in mapbox-gl-js/test/integration/query-test/..:

These tests require some kind of integration of QueryRenderFeatures functionality (see queryGeometry in json below). This kind of feature isn't implemented on MapSnapshotter but we can definitely add this.

{
  "version": 8,
  "metadata": {
    "test": {
      "height": 256,
      "queryGeometry": [
        10,
        100
      ]
    }
  },
  "center": [
    13.418056,
    52.499167
  ],
  "zoom": 14,
  "sources": {
    "mapbox": {
      "type": "vector",
      "maxzoom": 14,
      "tiles": [
        "local://tiles/{z}-{x}-{y}.mvt"
      ]
    }
  },
  "layers": [
    {
      "id": "road",
      "type": "circle",
      "source": "mapbox",
      "source-layer": "road",
      "paint": {
        "circle-radius": 10
      },
      "interactive": true
    }
  ]
}

That said, this fits inline with some other render tests that I had to ignore for a similar reason (I'm ignoring all tests with test{operations{ as the mapsnapshotter doesn't have the ability to change the map transformation (eg. change zoom level and wait for that to take effect).

I will be ticketing these improvements out with the rest of the todo items, thank you for 👀 'ing this!

@tobrun tobrun force-pushed the tvn-render-test branch from 8580bd7 to 93225f8 Compare June 1, 2018 09:29
@tobrun tobrun requested a review from LukasPaczos June 1, 2018 09:33
@tobrun tobrun force-pushed the tvn-render-test branch 2 times, most recently from 61b6115 to 97b56de Compare June 1, 2018 09:41
Copy link
Contributor

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This look amazing! 🚀
A couple of comments below.

int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using try-with-resources?

setupIdlingResource();
}

private void grantWriteRuntimePermission() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be achieved with handy JUnit Rules.


@Before
public void beforeTest() {
IdlingPolicies.setMasterPolicyTimeout(30, TimeUnit.MINUTES);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract the timeout to a variable?

private void setupIdlingResource() {
try {
Timber.e("@Before test: register idle resource");
IdlingPolicies.setIdlingResourceTimeout(30, TimeUnit.MINUTES);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

}

private static String loadStyleJson(AssetManager assets, String category, String test) throws IOException {
InputStream input = assets.open(String.format("%s/%s/%s/style.json", RENDER_TEST_BASE_PATH, category, test));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try-with-resources would be nice, also extracting whole path format or at least the file name to a variable.

FileOutputStream out = new FileOutputStream(filePath);
testResult.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting try-with-resources again.

}

private static File createTestResultRootFolder() {
File testResultDir = new File(Environment.getExternalStorageDirectory() + File.separator + "mapbox");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding "/render" to the root path?

//
// Callback configuration to notify test executor of test finishing
//
public interface OnSnapshotReadyListener {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface's name and method's name are a bit ambiguous. Could we rename it to something along the lines of OnTestSnapshotsReadyListener?

try {
Timber.e("@Before test: register idle resource");
IdlingPolicies.setIdlingResourceTimeout(30, TimeUnit.MINUTES);
Espresso.registerIdlingResources(idlingResource = new SnapshotterIdlingResource(rule.getActivity()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is deprecated, could you use IdlingRegistry.register(IdlingResource...) instead?

@After
public void afterTest() {
Timber.e("@After test: unregister idle resource");
Espresso.unregisterIdlingResources(idlingResource);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@tobrun tobrun force-pushed the tvn-render-test branch 4 times, most recently from dcfa87d to 9810d8c Compare June 1, 2018 12:14
int size = input.available();
buffer = new byte[size];
input.read(buffer);
input.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to explicitly close the resource here.

@@ -791,6 +791,18 @@
<activity
android:name=".activity.style.FillExtrusionStyleTestActivity"
android:screenOrientation="portrait" />
<activity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was only the debug setup. Can we remove it?

@tobrun tobrun force-pushed the tvn-render-test branch from 9810d8c to 09751b2 Compare June 1, 2018 12:34
@tobrun tobrun force-pushed the tvn-render-test branch 4 times, most recently from bdf6b5d to 3f04f13 Compare June 1, 2018 16:49
@tobrun tobrun force-pushed the tvn-render-test branch from 3f04f13 to 94027ae Compare June 1, 2018 17:49
@tobrun tobrun merged commit be66de6 into master Jun 1, 2018
@tobrun tobrun deleted the tvn-render-test branch June 1, 2018 18:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants