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

Commit fb2b28e

Browse files
Julian Rexjmkileyjmkiley
authored
Add query integration test (#317)
* 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>
1 parent 28e4c59 commit fb2b28e

File tree

16 files changed

+858
-307
lines changed

16 files changed

+858
-307
lines changed

platform/darwin/src/MGLSignpost.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#ifndef MGLSignpost_h
2+
#define MGLSignpost_h
3+
4+
#include <os/log.h>
5+
#include <os/signpost.h>
6+
7+
#define SIGNPOST_CONCAT2(x,y) x##y
8+
#define SIGNPOST_CONCAT(x,y) SIGNPOST_CONCAT2(x,y)
9+
#define SIGNPOST_NAME(x) SIGNPOST_CONCAT(signpost,x)
10+
//
11+
//#define MGL_EXPORT __attribute__((visibility ("default")))
12+
//
13+
//MGL_EXPORT extern os_log_t MGLDefaultSignpostLog;
14+
//MGL_EXPORT extern os_signpost_id_t MGLDefaultSignpost;
15+
//
16+
/**
17+
Create an os_log_t (for use with os_signposts) with the "com.mapbox.mapbox" subsystem.
18+
19+
This method checks `NSUserDefaults` for `MGLSignpostsEnabled`, otherwise will return `OS_LOG_DISABLED`.
20+
Typically you should add `-MGLSignpostsEnabled YES` as run arguments to the Xcode scheme when
21+
profiling.
22+
23+
This is only required if you need to add categories other than the default.
24+
25+
@param name Name for the log category.
26+
@return log object.
27+
*/
28+
//MGL_EXPORT extern os_log_t MGLSignpostLogCreate(const char* name);
29+
30+
31+
32+
//os_log_t log = os_log_create("com.mapbox.mapbox", name);
33+
//
34+
//OS_LOG_DISABLED
35+
36+
37+
#define MGL_CREATE_SIGNPOST(log) \
38+
({ \
39+
os_signpost_id_t SIGNPOST_NAME(__LINE__) = OS_SIGNPOST_ID_INVALID; \
40+
if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
41+
SIGNPOST_NAME(__LINE__) = os_signpost_id_generate(log); \
42+
} \
43+
SIGNPOST_NAME(__LINE__); \
44+
})
45+
46+
#define MGL_SIGNPOST_BEGIN(log, signpost, name, ...) \
47+
({ \
48+
if (signpost != OS_SIGNPOST_ID_INVALID) { \
49+
if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
50+
os_signpost_interval_begin(log, signpost, name, ##__VA_ARGS__); \
51+
} \
52+
} \
53+
})
54+
55+
#define MGL_SIGNPOST_END(log, signpost, name, ...) \
56+
({ \
57+
if (signpost != OS_SIGNPOST_ID_INVALID) { \
58+
if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
59+
os_signpost_interval_end(log, signpost, name, ##__VA_ARGS__); \
60+
} \
61+
} \
62+
})
63+
64+
#define MGL_SIGNPOST_EVENT(log, signpost, name, ...) \
65+
({ \
66+
if (signpost != OS_SIGNPOST_ID_INVALID) { \
67+
if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
68+
os_signpost_event_emit(log, signpost, name, ##__VA_ARGS__); \
69+
} \
70+
} \
71+
})
72+
73+
// Use MGL_SIGNPOST_BEGIN & MGL_SIGNPOST_END around sections of code that you
74+
// wish to profile.
75+
// MGL_SIGNPOST_EVENT can be used for single one-off events
76+
//
77+
// For example:
78+
//
79+
// os_signpost_id_t signpost = MGL_CREATE_SIGNPOST();
80+
// MGL_SIGNPOST_BEGIN(signpost, "example");
81+
// [self performAComputationallyExpensiveOperation];
82+
// MGL_SIGNPOST_END(signpost, "example", "%d", numberOfWidgets);
83+
//
84+
// MGL_SIGNPOST_EVENT("error", "%d", errorCode);
85+
//
86+
//#define MGL_CREATE_SIGNPOST() MGL_NAMED_CREATE_SIGNPOST(MGLDefaultSignpostLog)
87+
//
88+
//#define MGL_SIGNPOST_BEGIN(signpost, name, ...) MGL_NAMED_SIGNPOST_BEGIN(MGLDefaultSignpostLog, signpost, name, ##__VA_ARGS__)
89+
//#define MGL_SIGNPOST_END(signpost, name, ...) MGL_NAMED_SIGNPOST_END(MGLDefaultSignpostLog, signpost, name, ##__VA_ARGS__)
90+
//#define MGL_SIGNPOST_EVENT(signpost, name, ...) MGL_NAMED_SIGNPOST_EVENT(MGLDefaultSignpostLog, signpost, name, ##__VA_ARGS__)
91+
92+
#endif /* MGLSignpost_h */

platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,7 @@ - (void)waitForCollisionDetectionToRun {
813813
self.renderFinishedExpectation = [self expectationWithDescription:@"Map view should be rendered"];
814814
XCTestExpectation *timerExpired = [self expectationWithDescription:@"Timer expires"];
815815

816-
// Wait 1/2 second
817-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(NSEC_PER_SEC >> 1)), dispatch_get_main_queue(), ^{
816+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
818817
[timerExpired fulfill];
819818
});
820819

platform/ios/Integration Tests/MGLIntegrationTestCase.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ + (XCTestSuite*)defaultTestSuite {
1111
XCTestSuite *newTestSuite = [XCTestSuite testSuiteWithName:defaultTestSuite.name];
1212

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

1616
for (XCTest *test in tests) {
1717

@@ -44,13 +44,11 @@ - (void)setUp {
4444
NSString *accessToken;
4545

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

4949
if (!accessToken) {
50-
printf("warning: MAPBOX_ACCESS_TOKEN env var is required for test '%s' - trying anyway.\n", self.name.UTF8String);
50+
printf("warning: MGLMapboxAccessToken info.plist key is required for test '%s' - trying anyway.\n", self.name.UTF8String);
5151
}
5252
}
53-
54-
[MGLAccountManager setAccessToken:accessToken ?: @"pk.feedcafedeadbeefbadebede"];
5553
}
5654
@end

platform/ios/Integration Tests/MGLMapViewIntegrationTest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@property (nonatomic) MGLStyle *style;
77
@property (nonatomic) XCTestExpectation *styleLoadingExpectation;
88
@property (nonatomic) XCTestExpectation *renderFinishedExpectation;
9+
@property (nonatomic) XCTestExpectation *idleExpectation;
910
@property (nonatomic) MGLAnnotationView * (^viewForAnnotation)(MGLMapView *mapView, id<MGLAnnotation> annotation);
1011
@property (nonatomic) void (^regionWillChange)(MGLMapView *mapView, BOOL animated);
1112
@property (nonatomic) void (^regionIsChanging)(MGLMapView *mapView);
@@ -18,4 +19,6 @@
1819
- (void)waitForMapViewToFinishLoadingStyleWithTimeout:(NSTimeInterval)timeout;
1920
- (void)waitForMapViewToBeRenderedWithTimeout:(NSTimeInterval)timeout;
2021
- (MGLMapView *)mapViewForTestWithFrame:(CGRect)rect styleURL:(NSURL *)styleURL;
22+
- (void)waitForMapViewToIdleWithTimeout:(NSTimeInterval)timeout;
23+
- (NSURL*)styleURL;
2124
@end

platform/ios/Integration Tests/MGLMapViewIntegrationTest.m

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ - (MGLMapView *)mapViewForTestWithFrame:(CGRect)rect styleURL:(NSURL *)styleURL
1111
return [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL];
1212
}
1313

14+
- (NSURL*)styleURL {
15+
return [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"];
16+
}
17+
1418
- (void)setUp {
1519
[super setUp];
16-
17-
NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"];
20+
21+
NSURL *styleURL = [self styleURL];
1822

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

5862
[self.styleLoadingExpectation fulfill];
63+
self.styleLoadingExpectation = nil;
5964
}
6065

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

71+
- (void)mapViewDidBecomeIdle:(MGLMapView *)mapView {
72+
[self.idleExpectation fulfill];
73+
self.idleExpectation = nil;
74+
}
75+
76+
6677
- (void)mapView:(MGLMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
6778
if (self.regionWillChange) {
6879
self.regionWillChange(mapView, animated);
@@ -119,6 +130,13 @@ - (void)waitForMapViewToBeRenderedWithTimeout:(NSTimeInterval)timeout {
119130
self.renderFinishedExpectation = nil;
120131
}
121132

133+
- (void)waitForMapViewToIdleWithTimeout:(NSTimeInterval)timeout {
134+
XCTAssertNil(self.renderFinishedExpectation);
135+
[self.mapView setNeedsRerender];
136+
self.idleExpectation = [self expectationWithDescription:@"Map view should idle"];
137+
[self waitForExpectations:@[self.idleExpectation] timeout:timeout];
138+
}
139+
122140
- (void)waitForExpectations:(NSArray<XCTestExpectation *> *)expectations timeout:(NSTimeInterval)seconds {
123141
NSTimer *timer;
124142

0 commit comments

Comments
 (0)