Skip to content

Commit fdc843f

Browse files
authored
fix(event processor): change ep behavior when timerInterval is negative value (#268)
* fix ep behavior when timerInterval is negative value * remove slather from tvOS
1 parent 9814468 commit fdc843f

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ jobs:
6868
script:
6969
- if [[ "$TRAVIS_BRANCH" == "master" ]]; then xcodebuild test -workspace OptimizelySwiftSDK.xcworkspace -scheme $SCHEME -configuration Release CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -sdk $TEST_SDK -destination "platform=$PLATFORM,OS=$OS,name=$NAME" ONLY_ACTIVE_ARCH=YES | tee buildoutput | xcpretty && test ${PIPESTATUS[0]} -eq 0; fi
7070
after_success:
71-
- slather
71+
# coverage collect for iOS only (.slather.yml)
72+
- if [[ "$PLATFORM" == "iOS Simulator" ]]; then slather; fi
7273
- sleep 5 # https://github.com/travis-ci/travis-ci/issues/4725
7374
after_failure:
7475
# install travis artifacts uploader

Sources/Customization/DefaultEventDispatcher.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ open class DefaultEventDispatcher: BackgroundingCallbacks, OPTEventDispatcher {
2424

2525
static let sharedInstance = DefaultEventDispatcher()
2626

27-
// default timerInterval
27+
// timer-interval for batching (0 = no batching, negative = use default)
2828
var timerInterval: TimeInterval
29-
// default batchSize.
29+
// batch size (1 = no batching, 0 or negative = use default)
3030
// attempt to send events in batches with batchSize number of events combined
3131
var batchSize: Int
3232
var maxQueueSize: Int
@@ -61,10 +61,12 @@ open class DefaultEventDispatcher: BackgroundingCallbacks, OPTEventDispatcher {
6161
timerInterval: TimeInterval = DefaultValues.timeInterval,
6262
maxQueueSize: Int = DefaultValues.maxQueueSize) {
6363
self.batchSize = batchSize > 0 ? batchSize : DefaultValues.batchSize
64+
self.timerInterval = timerInterval >= 0 ? timerInterval : DefaultValues.timeInterval
65+
self.maxQueueSize = maxQueueSize >= 100 ? maxQueueSize : DefaultValues.maxQueueSize
66+
6467
self.backingStore = backingStore
6568
self.backingStoreName = dataStoreName
66-
self.timerInterval = timerInterval
67-
self.maxQueueSize = maxQueueSize > 100 ? maxQueueSize : DefaultValues.maxQueueSize
69+
6870

6971
switch backingStore {
7072
case .file:

Sources/Data Model/ProjectConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ extension ProjectConfig {
157157
}
158158

159159
private func getWhitelistedVariationId(userId: String, experimentId: String) -> String? {
160-
if var dic = whitelistUsers[userId] {
160+
if let dic = whitelistUsers[userId] {
161161
return dic[experimentId]
162162
}
163163

Tests/OptimizelyTests-Common/EventDispatcherTests.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,15 @@ class EventDispatcherTests: XCTestCase {
4747
}
4848

4949
func testDefaultDispatcher() {
50-
eventDispatcher = DefaultEventDispatcher(timerInterval: 1)
50+
eventDispatcher = DefaultEventDispatcher(timerInterval: 10)
5151
let pEventD: OPTEventDispatcher = eventDispatcher!
5252

5353
pEventD.flushEvents()
5454

5555
eventDispatcher?.dispatcher.sync {
5656
}
5757

58-
pEventD.dispatchEvent(event: EventForDispatch(body: Data())) { (_) -> Void in
59-
60-
}
58+
pEventD.dispatchEvent(event: EventForDispatch(body: Data()), completionHandler: nil)
6159

6260
eventDispatcher?.dispatcher.sync {
6361
}

Tests/OptimizelyTests-Common/EventDispatcherTests_Batch.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,13 @@ extension EventDispatcherTests_Batch {
119119
XCTAssert(defaultMaxQueueSize > 100)
120120

121121
// invalid batchSize falls back to default value
122-
123-
ep = DefaultEventDispatcher(batchSize: 0, timerInterval: 0, maxQueueSize: 0)
122+
// (timerInterval = 0 is a valid value, meaning no batch)
123+
// invalid timeInterval tested in "testEventDispatchedOnTimer_ZeroInterval" below
124+
125+
ep = DefaultEventDispatcher(batchSize: 0, timerInterval: -1, maxQueueSize: 0)
124126
XCTAssertEqual(ep.batchSize, defaultBatchSize)
127+
XCTAssertEqual(ep.timerInterval, defaultTimeInterval)
125128
XCTAssertEqual(ep.maxQueueSize, defaultMaxQueueSize)
126-
127-
// invalid timeInterval tested in "testEventDispatchedOnTimer_ZeroInterval" below
128129
}
129130

130131
}
@@ -688,7 +689,7 @@ extension EventDispatcherTests_Batch {
688689
wait(for: [eventDispatcher.exp!], timeout: 3)
689690
XCTAssertEqual(eventDispatcher.sendRequestedEvents.count, 1, "should flush on batchSize hit")
690691
}
691-
692+
692693
func testEventsFlushedOnRevisionChange() {
693694
// this tests timer-based dispatch, available for iOS 10+
694695
guard #available(iOS 10.0, tvOS 10.0, *) else { return }

0 commit comments

Comments
 (0)