Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ jobs:
script:
- 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
after_success:
- slather
# coverage collect for iOS only (.slather.yml)
- if [[ "$PLATFORM" == "iOS Simulator" ]]; then slather; fi
- sleep 5 # https://github.com/travis-ci/travis-ci/issues/4725
after_failure:
# install travis artifacts uploader
Expand Down
10 changes: 6 additions & 4 deletions Sources/Customization/DefaultEventDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ open class DefaultEventDispatcher: BackgroundingCallbacks, OPTEventDispatcher {

static let sharedInstance = DefaultEventDispatcher()

// default timerInterval
// timer-interval for batching (0 = no batching, negative = use default)
var timerInterval: TimeInterval
// default batchSize.
// batch size (1 = no batching, 0 or negative = use default)
// attempt to send events in batches with batchSize number of events combined
var batchSize: Int
var maxQueueSize: Int
Expand Down Expand Up @@ -61,10 +61,12 @@ open class DefaultEventDispatcher: BackgroundingCallbacks, OPTEventDispatcher {
timerInterval: TimeInterval = DefaultValues.timeInterval,
maxQueueSize: Int = DefaultValues.maxQueueSize) {
self.batchSize = batchSize > 0 ? batchSize : DefaultValues.batchSize
self.timerInterval = timerInterval >= 0 ? timerInterval : DefaultValues.timeInterval
self.maxQueueSize = maxQueueSize >= 100 ? maxQueueSize : DefaultValues.maxQueueSize

self.backingStore = backingStore
self.backingStoreName = dataStoreName
self.timerInterval = timerInterval
self.maxQueueSize = maxQueueSize > 100 ? maxQueueSize : DefaultValues.maxQueueSize


switch backingStore {
case .file:
Expand Down
2 changes: 1 addition & 1 deletion Sources/Data Model/ProjectConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ extension ProjectConfig {
}

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

Expand Down
6 changes: 2 additions & 4 deletions Tests/OptimizelyTests-Common/EventDispatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ class EventDispatcherTests: XCTestCase {
}

func testDefaultDispatcher() {
eventDispatcher = DefaultEventDispatcher(timerInterval: 1)
eventDispatcher = DefaultEventDispatcher(timerInterval: 10)
let pEventD: OPTEventDispatcher = eventDispatcher!

pEventD.flushEvents()

eventDispatcher?.dispatcher.sync {
}

pEventD.dispatchEvent(event: EventForDispatch(body: Data())) { (_) -> Void in

}
pEventD.dispatchEvent(event: EventForDispatch(body: Data()), completionHandler: nil)

eventDispatcher?.dispatcher.sync {
}
Expand Down
11 changes: 6 additions & 5 deletions Tests/OptimizelyTests-Common/EventDispatcherTests_Batch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ extension EventDispatcherTests_Batch {
XCTAssert(defaultMaxQueueSize > 100)

// invalid batchSize falls back to default value

ep = DefaultEventDispatcher(batchSize: 0, timerInterval: 0, maxQueueSize: 0)
// (timerInterval = 0 is a valid value, meaning no batch)
// invalid timeInterval tested in "testEventDispatchedOnTimer_ZeroInterval" below

ep = DefaultEventDispatcher(batchSize: 0, timerInterval: -1, maxQueueSize: 0)
XCTAssertEqual(ep.batchSize, defaultBatchSize)
XCTAssertEqual(ep.timerInterval, defaultTimeInterval)
XCTAssertEqual(ep.maxQueueSize, defaultMaxQueueSize)

// invalid timeInterval tested in "testEventDispatchedOnTimer_ZeroInterval" below
}

}
Expand Down Expand Up @@ -688,7 +689,7 @@ extension EventDispatcherTests_Batch {
wait(for: [eventDispatcher.exp!], timeout: 3)
XCTAssertEqual(eventDispatcher.sendRequestedEvents.count, 1, "should flush on batchSize hit")
}

func testEventsFlushedOnRevisionChange() {
// this tests timer-based dispatch, available for iOS 10+
guard #available(iOS 10.0, tvOS 10.0, *) else { return }
Expand Down