Skip to content

Commit 9b42a1c

Browse files
authored
Update podspec and factor out common test sources (#2336)
* Update podspec and factor out common test sources * Add a wifi-only QoS specifier * Change the prioritizer protocol to include upload conditions * Remove an unused log target. * Call unprioritizeLog and remove an assert that wasn't helpful * Put the upload completionBlock on the uploader queue * Fix the CI and podspec. * [DO NOT MERGE TO MASTER] Raise the cocoapods version to 1.6.0.rc.2 * [DO NOT MERGE TO MASTER] Update Gemfile correctly * [DO NOT MERGE TO MASTER] Use the tag, not the version number. * Correct an incorrect commit * Remove the name for standard unit tests
1 parent 7e2d04c commit 9b42a1c

21 files changed

+112
-61
lines changed

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# use 'bundle update' to update to latest gems
22
source 'https://rubygems.org'
33

4-
gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git'
5-
gem 'cocoapods-core', :git => 'https://github.com/CocoaPods/Core.git'
4+
gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :tag => '1.6.0.rc.2'
5+
gem 'cocoapods-core', :git => 'https://github.com/CocoaPods/Core.git', :tag => '1.6.0.rc.2'
66
gem 'cocoapods-generate', :git => 'https://github.com/square/cocoapods-generate'
77
gem 'xcodeproj', :git => 'https://github.com/CocoaPods/Xcodeproj.git'

Gemfile.lock

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
GIT
22
remote: https://github.com/CocoaPods/CocoaPods.git
3-
revision: 10b69dbd9b991442646944f118f569d855652b26
3+
revision: 783424de392ebb327f7dc25d685b8df9605e76be
4+
tag: 1.6.0.rc.2
45
specs:
5-
cocoapods (1.5.3)
6+
cocoapods (1.6.0.rc.2)
67
activesupport (>= 4.0.2, < 5)
78
claide (>= 1.0.2, < 2.0)
8-
cocoapods-core (= 1.5.3)
9+
cocoapods-core (= 1.6.0.rc.2)
910
cocoapods-deintegrate (>= 1.0.2, < 2.0)
10-
cocoapods-downloader (>= 1.2.1, < 2.0)
11+
cocoapods-downloader (>= 1.2.2, < 2.0)
1112
cocoapods-plugins (>= 1.0.0, < 2.0)
1213
cocoapods-search (>= 1.0.0, < 2.0)
1314
cocoapods-stats (>= 1.0.0, < 2.0)
14-
cocoapods-trunk (>= 1.3.0, < 2.0)
15+
cocoapods-trunk (>= 1.3.1, < 2.0)
1516
cocoapods-try (>= 1.1.0, < 2.0)
1617
colored2 (~> 3.1)
1718
escape (~> 0.0.4)
18-
fourflusher (~> 2.0.1)
19+
fourflusher (>= 2.2.0, < 3.0)
1920
gh_inspector (~> 1.0)
20-
molinillo (~> 0.6.5)
21+
molinillo (~> 0.6.6)
2122
nap (~> 1.0)
22-
ruby-macho (~> 1.2)
23-
xcodeproj (>= 1.5.8, < 2.0)
23+
ruby-macho (~> 1.3, >= 1.3.1)
24+
xcodeproj (>= 1.8.0, < 2.0)
2425

2526
GIT
2627
remote: https://github.com/CocoaPods/Core.git
27-
revision: 577c69f38fdb56cbdb883b44681ca2b224cad746
28+
revision: 2e99d7e1ce9c36bc82c822624e34c150b48342f5
29+
tag: 1.6.0.rc.2
2830
specs:
29-
cocoapods-core (1.5.3)
31+
cocoapods-core (1.6.0.rc.2)
3032
activesupport (>= 4.0.2, < 6)
3133
fuzzy_match (~> 2.0.4)
3234
nap (~> 1.0)
3335

3436
GIT
3537
remote: https://github.com/CocoaPods/Xcodeproj.git
36-
revision: cadb238767d09942a1c5eba90a3112034438ba23
38+
revision: 2bc4222ff4664386363cda25c56d2b54c20d565e
3739
specs:
38-
xcodeproj (1.5.9)
40+
xcodeproj (1.8.0)
3941
CFPropertyList (>= 2.3.3, < 4.0)
40-
atomos (~> 0.1.2)
42+
atomos (~> 0.1.3)
4143
claide (>= 1.0.2, < 2.0)
4244
colored2 (~> 3.1)
43-
nanaimo (~> 0.2.5)
45+
nanaimo (~> 0.2.6)
4446

4547
GIT
4648
remote: https://github.com/square/cocoapods-generate
@@ -52,37 +54,37 @@ GEM
5254
remote: https://rubygems.org/
5355
specs:
5456
CFPropertyList (3.0.0)
55-
activesupport (4.2.10)
57+
activesupport (4.2.11)
5658
i18n (~> 0.7)
5759
minitest (~> 5.1)
5860
thread_safe (~> 0.3, >= 0.3.4)
5961
tzinfo (~> 1.1)
60-
atomos (0.1.2)
62+
atomos (0.1.3)
6163
claide (1.0.2)
6264
cocoapods-deintegrate (1.0.2)
63-
cocoapods-downloader (1.2.1)
65+
cocoapods-downloader (1.2.2)
6466
cocoapods-plugins (1.0.0)
6567
nap
6668
cocoapods-search (1.0.0)
67-
cocoapods-stats (1.0.0)
68-
cocoapods-trunk (1.3.0)
69+
cocoapods-stats (1.1.0)
70+
cocoapods-trunk (1.3.1)
6971
nap (>= 0.8, < 2.0)
7072
netrc (~> 0.11)
7173
cocoapods-try (1.1.0)
7274
colored2 (3.1.2)
73-
concurrent-ruby (1.0.5)
75+
concurrent-ruby (1.1.4)
7476
escape (0.0.4)
75-
fourflusher (2.0.1)
77+
fourflusher (2.2.0)
7678
fuzzy_match (2.0.4)
7779
gh_inspector (1.1.3)
7880
i18n (0.9.5)
7981
concurrent-ruby (~> 1.0)
8082
minitest (5.11.3)
81-
molinillo (0.6.5)
82-
nanaimo (0.2.5)
83+
molinillo (0.6.6)
84+
nanaimo (0.2.6)
8385
nap (1.1.0)
8486
netrc (0.11.0)
85-
ruby-macho (1.2.0)
87+
ruby-macho (1.3.1)
8688
thread_safe (0.3.6)
8789
tzinfo (1.2.5)
8890
thread_safe (~> 0.1)

GoogleDataLogger.podspec

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,28 @@ Shared library for iOS SDK data logging needs.
1818

1919
s.ios.deployment_target = '8.0'
2020

21-
s.cocoapods_version = '>= 1.5.3'
21+
s.cocoapods_version = '>= 1.6.0.rc.2'
2222

23-
# TODO(mikehaney24): Change to static framework after cocoapods 1.6.0 release?
24-
s.static_framework = false
23+
s.static_framework = true
2524
s.prefix_header_file = false
2625

2726
s.source_files = 'GoogleDataLogger/GoogleDataLogger/**/*'
2827
s.public_header_files = 'GoogleDataLogger/GoogleDataLogger/Classes/Public/*.h'
28+
s.private_header_files = 'GoogleDataLogger/GoogleDataLogger/Classes/Private/*.h'
2929

3030
s.dependency 'GoogleUtilities/Logger'
3131

3232
s.pod_target_xcconfig = {
3333
'GCC_C_LANGUAGE_STANDARD' => 'c99',
34-
'GCC_TREAT_WARNINGS_AS_ERRORS' => 'YES'
34+
'GCC_TREAT_WARNINGS_AS_ERRORS' => 'YES',
35+
'CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY' => 'YES'
3536
}
3637

37-
# Test specs
38-
s.test_spec 'UnitTests' do |test_spec|
39-
test_spec.source_files = 'GoogleDataLogger/Tests/Unit/**/*.{h,m}'
38+
common_test_sources = ['GoogleDataLogger/Tests/Common/**/*.{h,m}']
39+
40+
# Unit test specs
41+
s.test_spec do |test_spec|
42+
test_spec.requires_app_host = false
43+
test_spec.source_files = ['GoogleDataLogger/Tests/Unit/**/*.{h,m}'] + common_test_sources
4044
end
4145
end

GoogleDataLogger/GoogleDataLogger/Classes/GDLLogStorage.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ - (void)storeLog:(GDLLogEvent *)log {
7777
// Check that a log prioritizer is available for this logTarget.
7878
id<GDLLogPrioritizer> logPrioritizer =
7979
[GDLRegistrar sharedInstance].logTargetToPrioritizer[@(logTarget)];
80-
GDLAssert(logPrioritizer, @"There's no scorer registered for the given logTarget.");
80+
GDLAssert(logPrioritizer, @"There's no prioritizer registered for the given logTarget.");
8181

8282
// Write the extension bytes to disk, get a filename.
8383
GDLAssert(shortLivedLog.extensionBytes, @"The log should have been serialized to bytes");
84-
GDLAssert(shortLivedLog.extension == nil, @"The original log proto should be removed");
8584
NSURL *logFile = [self saveLogProtoToDisk:shortLivedLog.extensionBytes
8685
logHash:shortLivedLog.hash];
8786

@@ -121,6 +120,12 @@ - (void)removeLog:(NSNumber *)logHash logTarget:(NSNumber *)logTarget {
121120
GDLAssert(logHashes, @"There wasn't a logSet for this logTarget.");
122121
[logHashes removeObject:logHash];
123122
// It's fine to not remove the set if it's empty.
123+
124+
// Check that a log prioritizer is available for this logTarget.
125+
id<GDLLogPrioritizer> logPrioritizer =
126+
[GDLRegistrar sharedInstance].logTargetToPrioritizer[logTarget];
127+
GDLAssert(logPrioritizer, @"There's no prioritizer registered for the given logTarget.");
128+
[logPrioritizer unprioritizeLog:logHash];
124129
});
125130
}
126131

GoogleDataLogger/GoogleDataLogger/Classes/GDLUploadCoordinator.m

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,27 @@ - (GDLUploaderCompletionBlock)onCompleteBlock {
9292
onCompleteBlock = ^(GDLLogTarget target, GDLClock *nextUploadAttemptUTC, NSError *error) {
9393
GDLUploadCoordinator *strongSelf = weakSelf;
9494
if (strongSelf) {
95-
NSNumber *logTarget = @(target);
96-
if (error) {
97-
GDLLogWarning(GDLMCWUploadFailed, @"Error during upload: %@", error);
95+
dispatch_async(strongSelf.coordinationQueue, ^{
96+
NSNumber *logTarget = @(target);
97+
if (error) {
98+
GDLLogWarning(GDLMCWUploadFailed, @"Error during upload: %@", error);
99+
[strongSelf->_logTargetToInFlightLogSet removeObjectForKey:logTarget];
100+
return;
101+
}
102+
strongSelf->_logTargetToNextUploadTimes[logTarget] = nextUploadAttemptUTC;
103+
NSSet<NSNumber *> *logHashSet =
104+
[strongSelf->_logTargetToInFlightLogSet objectForKey:logTarget];
105+
[strongSelf.logStorage removeLogs:logHashSet logTarget:logTarget];
98106
[strongSelf->_logTargetToInFlightLogSet removeObjectForKey:logTarget];
99-
return;
100-
}
101-
strongSelf->_logTargetToNextUploadTimes[logTarget] = nextUploadAttemptUTC;
102-
NSSet<NSNumber *> *logHashSet =
103-
[strongSelf->_logTargetToInFlightLogSet objectForKey:logTarget];
104-
[strongSelf.logStorage removeLogs:logHashSet logTarget:logTarget];
105-
[strongSelf->_logTargetToInFlightLogSet removeObjectForKey:logTarget];
106-
if (strongSelf->_forcedUploadQueue.count) {
107-
GDLUploadCoordinatorForceUploadBlock queuedBlock =
108-
[strongSelf->_forcedUploadQueue lastObject];
109-
if (queuedBlock) {
110-
queuedBlock();
107+
if (strongSelf->_forcedUploadQueue.count) {
108+
GDLUploadCoordinatorForceUploadBlock queuedBlock =
109+
[strongSelf->_forcedUploadQueue lastObject];
110+
if (queuedBlock) {
111+
queuedBlock();
112+
}
113+
[strongSelf->_forcedUploadQueue removeLastObject];
111114
}
112-
[strongSelf->_forcedUploadQueue removeLastObject];
113-
}
115+
});
114116
}
115117
};
116118
});
@@ -144,6 +146,8 @@ - (void)startTimer {
144146
- (void)checkPrioritizersAndUploadLogs {
145147
__weak GDLUploadCoordinator *weakSelf = self;
146148
dispatch_async(_coordinationQueue, ^{
149+
static int count = 0;
150+
count++;
147151
GDLUploadCoordinator *strongSelf = weakSelf;
148152
if (strongSelf) {
149153
NSArray<NSNumber *> *logTargetsReadyForUpload = [self logTargetsReadyForUpload];
@@ -153,10 +157,14 @@ - (void)checkPrioritizersAndUploadLogs {
153157
id<GDLLogUploader> uploader = strongSelf->_registrar.logTargetToUploader[logTarget];
154158
GDLAssert(prioritizer && uploader, @"log target '%@' is missing an implementation",
155159
logTarget);
156-
NSSet<NSNumber *> *logHashesToUpload = [prioritizer logsForNextUpload];
160+
GDLUploadConditions conds = [self uploadConditions];
161+
NSSet<NSNumber *> *logHashesToUpload = [prioritizer logsToUploadGivenConditions:conds];
157162
if (logHashesToUpload && logHashesToUpload.count > 0) {
163+
NSAssert(logHashesToUpload.count > 0, @"");
158164
NSSet<NSURL *> *logFilesToUpload =
159165
[strongSelf.logStorage logHashesToFiles:logHashesToUpload];
166+
NSAssert(logFilesToUpload.count == logHashesToUpload.count,
167+
@"There should be the same number of files to logs");
160168
[uploader uploadLogs:logFilesToUpload onComplete:self.onCompleteBlock];
161169
strongSelf->_logTargetToInFlightLogSet[logTarget] = logHashesToUpload;
162170
}
@@ -165,6 +173,12 @@ - (void)checkPrioritizersAndUploadLogs {
165173
});
166174
}
167175

176+
/** */
177+
- (GDLUploadConditions)uploadConditions {
178+
// TODO: Compute the real upload conditions.
179+
return GDLUploadConditionMobileData;
180+
}
181+
168182
/** Checks the next upload time for each log target and returns an array of log targets that are
169183
* able to make an upload attempt.
170184
*
@@ -174,6 +188,10 @@ - (void)checkPrioritizersAndUploadLogs {
174188
NSMutableArray *logTargetsReadyForUpload = [[NSMutableArray alloc] init];
175189
GDLClock *currentTime = [GDLClock snapshot];
176190
for (NSNumber *logTarget in self.registrar.logTargetToPrioritizer) {
191+
// Log targets in flight are not ready.
192+
if (_logTargetToInFlightLogSet[logTarget]) {
193+
continue;
194+
}
177195
GDLClock *nextUploadTime = _logTargetToNextUploadTimes[logTarget];
178196

179197
// If no next upload time was specified or if the currentTime > nextUpload time, mark as ready.

GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogEvent.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ typedef NS_ENUM(NSInteger, GDLLogQoS) {
3535
GDLLogQosDefault = 3,
3636

3737
/** This log should be sent immediately along with any other data that can be batched. */
38-
GDLLogQoSFast = 4
38+
GDLLogQoSFast = 4,
39+
40+
/** This log should only be uploaded on wifi. */
41+
GDLLogQoSWifiOnly = 5,
3942
};
4043

4144
@interface GDLLogEvent : NSObject <NSSecureCoding>

GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogPrioritizer.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020

2121
NS_ASSUME_NONNULL_BEGIN
2222

23+
/** Options that define a set of upload conditions. This is used to help minimize end user data
24+
* consumption impact.
25+
*/
26+
typedef NS_OPTIONS(NSInteger, GDLUploadConditions) {
27+
28+
/** An upload would likely use mobile data. */
29+
GDLUploadConditionMobileData,
30+
31+
/** An upload would likely use wifi data. */
32+
GDLUploadConditionWifiData,
33+
};
34+
2335
/** This protocol defines the common interface of a log prioritization. Log prioritizers are
2436
* stateful objects that prioritize logs upon insertion into storage and remain prepared to return a
2537
* set of log filenames to the storage system.
@@ -40,11 +52,17 @@ NS_ASSUME_NONNULL_BEGIN
4052
*/
4153
- (void)prioritizeLog:(GDLLogEvent *)logEvent;
4254

43-
/** Returns a set of logs based on the logic of the prioritizer.
55+
/** Unprioritizes a log. This method is called when a log has been removed from storage and should
56+
* no longer be given as a log to upload.
57+
*/
58+
- (void)unprioritizeLog:(NSNumber *)logHash;
59+
60+
/** Returns a set of logs to upload given a set of conditions.
4461
*
45-
* @return A set of log hashes to upload, presumably based on the logs' priority.
62+
* @param conditions A bit mask specifying the current upload conditions.
63+
* @return A set of logs to upload with respect to the current conditions.
4664
*/
47-
- (NSSet<NSNumber *> *)logsForNextUpload;
65+
- (NSSet<NSNumber *> *)logsToUploadGivenConditions:(GDLUploadConditions)conditions;
4866

4967
@end
5068

GoogleDataLogger/GoogleDataLogger/Classes/Public/GDLLogTargets.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@ typedef NS_ENUM(NSInteger, GDLLogTarget) {
2323

2424
/** The CCT log target. */
2525
kGDLLogTargetCCT = 1000,
26-
27-
GDLLogTargetLast = 1001
2826
};

GoogleDataLogger/Tests/Unit/Helpers/GDLTestPrioritizer.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ - (instancetype)init {
2626
return self;
2727
}
2828

29-
- (NSSet<NSNumber *> *)logsForNextUpload {
29+
- (NSSet<NSNumber *> *)logsToUploadGivenConditions:(GDLUploadConditions)conditions {
3030
if (_logsForNextUploadBlock) {
3131
_logsForNextUploadBlock();
3232
}
@@ -39,4 +39,7 @@ - (void)prioritizeLog:(GDLLogEvent *)logEvent {
3939
}
4040
}
4141

42+
- (void)unprioritizeLog:(nonnull NSNumber *)logHash {
43+
}
44+
4245
@end

0 commit comments

Comments
 (0)