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

Commit

Permalink
Add query integration test (#317)
Browse files Browse the repository at this point in the history
* Port tests from gl-native 14324

* Remove crud.

* Set baselines

* Add timing for dictionary generation

* Remove access token

* Use insert access token script to insert an access token

* Update accessing the access token

* Fix second accessToken

* Refactor accessibility calculations (#318)

* Port tests from gl-native 14324

* Port accessibility calcs

* Fix typo from merge.

* Match results from before optimization.

* Remove temp commented code

* Address some TODOs

* Include exception from failing test

Co-authored-by: jmkiley <jordan.kiley@mapbox.com>

* Update MGLAnnotationViewIntegrationTests.mm

Co-authored-by: jmkiley <jordan.kiley@mapbox.com>
Co-authored-by: Jordan Kiley <jmkiley@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 8, 2020
1 parent 28e4c59 commit fb2b28e
Show file tree
Hide file tree
Showing 16 changed files with 858 additions and 307 deletions.
92 changes: 92 additions & 0 deletions platform/darwin/src/MGLSignpost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#ifndef MGLSignpost_h
#define MGLSignpost_h

#include <os/log.h>
#include <os/signpost.h>

#define SIGNPOST_CONCAT2(x,y) x##y
#define SIGNPOST_CONCAT(x,y) SIGNPOST_CONCAT2(x,y)
#define SIGNPOST_NAME(x) SIGNPOST_CONCAT(signpost,x)
//
//#define MGL_EXPORT __attribute__((visibility ("default")))
//
//MGL_EXPORT extern os_log_t MGLDefaultSignpostLog;
//MGL_EXPORT extern os_signpost_id_t MGLDefaultSignpost;
//
/**
Create an os_log_t (for use with os_signposts) with the "com.mapbox.mapbox" subsystem.
This method checks `NSUserDefaults` for `MGLSignpostsEnabled`, otherwise will return `OS_LOG_DISABLED`.
Typically you should add `-MGLSignpostsEnabled YES` as run arguments to the Xcode scheme when
profiling.
This is only required if you need to add categories other than the default.
@param name Name for the log category.
@return log object.
*/
//MGL_EXPORT extern os_log_t MGLSignpostLogCreate(const char* name);



//os_log_t log = os_log_create("com.mapbox.mapbox", name);
//
//OS_LOG_DISABLED


#define MGL_CREATE_SIGNPOST(log) \
({ \
os_signpost_id_t SIGNPOST_NAME(__LINE__) = OS_SIGNPOST_ID_INVALID; \
if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
SIGNPOST_NAME(__LINE__) = os_signpost_id_generate(log); \
} \
SIGNPOST_NAME(__LINE__); \
})

#define MGL_SIGNPOST_BEGIN(log, signpost, name, ...) \
({ \
if (signpost != OS_SIGNPOST_ID_INVALID) { \
if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
os_signpost_interval_begin(log, signpost, name, ##__VA_ARGS__); \
} \
} \
})

#define MGL_SIGNPOST_END(log, signpost, name, ...) \
({ \
if (signpost != OS_SIGNPOST_ID_INVALID) { \
if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
os_signpost_interval_end(log, signpost, name, ##__VA_ARGS__); \
} \
} \
})

#define MGL_SIGNPOST_EVENT(log, signpost, name, ...) \
({ \
if (signpost != OS_SIGNPOST_ID_INVALID) { \
if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
os_signpost_event_emit(log, signpost, name, ##__VA_ARGS__); \
} \
} \
})

// Use MGL_SIGNPOST_BEGIN & MGL_SIGNPOST_END around sections of code that you
// wish to profile.
// MGL_SIGNPOST_EVENT can be used for single one-off events
//
// For example:
//
// os_signpost_id_t signpost = MGL_CREATE_SIGNPOST();
// MGL_SIGNPOST_BEGIN(signpost, "example");
// [self performAComputationallyExpensiveOperation];
// MGL_SIGNPOST_END(signpost, "example", "%d", numberOfWidgets);
//
// MGL_SIGNPOST_EVENT("error", "%d", errorCode);
//
//#define MGL_CREATE_SIGNPOST() MGL_NAMED_CREATE_SIGNPOST(MGLDefaultSignpostLog)
//
//#define MGL_SIGNPOST_BEGIN(signpost, name, ...) MGL_NAMED_SIGNPOST_BEGIN(MGLDefaultSignpostLog, signpost, name, ##__VA_ARGS__)
//#define MGL_SIGNPOST_END(signpost, name, ...) MGL_NAMED_SIGNPOST_END(MGLDefaultSignpostLog, signpost, name, ##__VA_ARGS__)
//#define MGL_SIGNPOST_EVENT(signpost, name, ...) MGL_NAMED_SIGNPOST_EVENT(MGLDefaultSignpostLog, signpost, name, ##__VA_ARGS__)

#endif /* MGLSignpost_h */
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,7 @@ - (void)waitForCollisionDetectionToRun {
self.renderFinishedExpectation = [self expectationWithDescription:@"Map view should be rendered"];
XCTestExpectation *timerExpired = [self expectationWithDescription:@"Timer expires"];

// Wait 1/2 second
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(NSEC_PER_SEC >> 1)), dispatch_get_main_queue(), ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[timerExpired fulfill];
});

Expand Down
8 changes: 3 additions & 5 deletions platform/ios/Integration Tests/MGLIntegrationTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ + (XCTestSuite*)defaultTestSuite {
XCTestSuite *newTestSuite = [XCTestSuite testSuiteWithName:defaultTestSuite.name];

BOOL runPendingTests = [[[NSProcessInfo processInfo] environment][@"MAPBOX_RUN_PENDING_TESTS"] boolValue];
NSString *accessToken = [[NSProcessInfo processInfo] environment][@"MAPBOX_ACCESS_TOKEN"];
NSString *accessToken = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLMapboxAccessToken"];

for (XCTest *test in tests) {

Expand Down Expand Up @@ -44,13 +44,11 @@ - (void)setUp {
NSString *accessToken;

if ([self.name containsString:@"🔒"]) {
accessToken = [[NSProcessInfo processInfo] environment][@"MAPBOX_ACCESS_TOKEN"];
accessToken = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLMapboxAccessToken"];

if (!accessToken) {
printf("warning: MAPBOX_ACCESS_TOKEN env var is required for test '%s' - trying anyway.\n", self.name.UTF8String);
printf("warning: MGLMapboxAccessToken info.plist key is required for test '%s' - trying anyway.\n", self.name.UTF8String);
}
}

[MGLAccountManager setAccessToken:accessToken ?: @"pk.feedcafedeadbeefbadebede"];
}
@end
3 changes: 3 additions & 0 deletions platform/ios/Integration Tests/MGLMapViewIntegrationTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@property (nonatomic) MGLStyle *style;
@property (nonatomic) XCTestExpectation *styleLoadingExpectation;
@property (nonatomic) XCTestExpectation *renderFinishedExpectation;
@property (nonatomic) XCTestExpectation *idleExpectation;
@property (nonatomic) MGLAnnotationView * (^viewForAnnotation)(MGLMapView *mapView, id<MGLAnnotation> annotation);
@property (nonatomic) void (^regionWillChange)(MGLMapView *mapView, BOOL animated);
@property (nonatomic) void (^regionIsChanging)(MGLMapView *mapView);
Expand All @@ -18,4 +19,6 @@
- (void)waitForMapViewToFinishLoadingStyleWithTimeout:(NSTimeInterval)timeout;
- (void)waitForMapViewToBeRenderedWithTimeout:(NSTimeInterval)timeout;
- (MGLMapView *)mapViewForTestWithFrame:(CGRect)rect styleURL:(NSURL *)styleURL;
- (void)waitForMapViewToIdleWithTimeout:(NSTimeInterval)timeout;
- (NSURL*)styleURL;
@end
22 changes: 20 additions & 2 deletions platform/ios/Integration Tests/MGLMapViewIntegrationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ - (MGLMapView *)mapViewForTestWithFrame:(CGRect)rect styleURL:(NSURL *)styleURL
return [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL];
}

- (NSURL*)styleURL {
return [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"];
}

- (void)setUp {
[super setUp];

NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"];
NSURL *styleURL = [self styleURL];

self.mapView = [self mapViewForTestWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL];
self.mapView.delegate = self;
Expand Down Expand Up @@ -56,13 +60,20 @@ - (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
XCTAssertEqual(mapView.style, style);

[self.styleLoadingExpectation fulfill];
self.styleLoadingExpectation = nil;
}

- (void)mapViewDidFinishRenderingFrame:(MGLMapView *)mapView fullyRendered:(__unused BOOL)fullyRendered {
[self.renderFinishedExpectation fulfill];
self.renderFinishedExpectation = nil;
}

- (void)mapViewDidBecomeIdle:(MGLMapView *)mapView {
[self.idleExpectation fulfill];
self.idleExpectation = nil;
}


- (void)mapView:(MGLMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
if (self.regionWillChange) {
self.regionWillChange(mapView, animated);
Expand Down Expand Up @@ -119,6 +130,13 @@ - (void)waitForMapViewToBeRenderedWithTimeout:(NSTimeInterval)timeout {
self.renderFinishedExpectation = nil;
}

- (void)waitForMapViewToIdleWithTimeout:(NSTimeInterval)timeout {
XCTAssertNil(self.renderFinishedExpectation);
[self.mapView setNeedsRerender];
self.idleExpectation = [self expectationWithDescription:@"Map view should idle"];
[self waitForExpectations:@[self.idleExpectation] timeout:timeout];
}

- (void)waitForExpectations:(NSArray<XCTestExpectation *> *)expectations timeout:(NSTimeInterval)seconds {
NSTimer *timer;

Expand Down
Loading

0 comments on commit fb2b28e

Please sign in to comment.