Skip to content

Commit

Permalink
Added the AutoTracker to the tests to make them iOS 9.3 compatible (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
brototyp authored Sep 4, 2017
1 parent ed6f877 commit 81145e5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
4 changes: 4 additions & 0 deletions PiwikTracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
1F1949F81E17B2C800458199 /* MemoryQueueFixtures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1949F71E17B2C800458199 /* MemoryQueueFixtures.swift */; };
1F38EBF81EE568D10021FBF8 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F38EBF71EE568D10021FBF8 /* Logger.swift */; };
1F3CA58C1E09A30600121FDC /* Queue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F3CA58B1E09A30600121FDC /* Queue.swift */; };
1F5D08721F5D79AD0064314F /* AutoTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F5D08711F5D79AD0064314F /* AutoTracker.swift */; };
1F6F0CD71E61E35A008170FC /* PiwikTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F6F0CD61E61E35A008170FC /* PiwikTracker.swift */; };
1F6F0CDC1E61E377008170FC /* DispatcherStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F6F0CD81E61E377008170FC /* DispatcherStub.swift */; };
1F6F0CDD1E61E377008170FC /* QueueStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F6F0CD91E61E377008170FC /* QueueStub.swift */; };
Expand Down Expand Up @@ -53,6 +54,7 @@
1F1949F71E17B2C800458199 /* MemoryQueueFixtures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MemoryQueueFixtures.swift; path = Fixtures/MemoryQueueFixtures.swift; sourceTree = "<group>"; };
1F38EBF71EE568D10021FBF8 /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
1F3CA58B1E09A30600121FDC /* Queue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Queue.swift; sourceTree = "<group>"; };
1F5D08711F5D79AD0064314F /* AutoTracker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutoTracker.swift; sourceTree = "<group>"; };
1F6F0CD61E61E35A008170FC /* PiwikTracker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PiwikTracker.swift; sourceTree = "<group>"; };
1F6F0CD81E61E377008170FC /* DispatcherStub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DispatcherStub.swift; sourceTree = "<group>"; };
1F6F0CD91E61E377008170FC /* QueueStub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueueStub.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -169,6 +171,7 @@
1F6F0CD81E61E377008170FC /* DispatcherStub.swift */,
1F6F0CD91E61E377008170FC /* QueueStub.swift */,
1F6F0CDB1E61E377008170FC /* TrackerSpec.swift */,
1F5D08711F5D79AD0064314F /* AutoTracker.swift */,
1FCA6D4B1DBE0B2F0033F01C /* Info.plist */,
);
path = PiwikTrackerTests;
Expand Down Expand Up @@ -378,6 +381,7 @@
1F1949F81E17B2C800458199 /* MemoryQueueFixtures.swift in Sources */,
1F6F0CDD1E61E377008170FC /* QueueStub.swift in Sources */,
1F6F0CDC1E61E377008170FC /* DispatcherStub.swift in Sources */,
1F5D08721F5D79AD0064314F /* AutoTracker.swift in Sources */,
1F6F0CDE1E61E377008170FC /* TrackerFixtures.swift in Sources */,
1F1949F41E17B06600458199 /* MemoryQueueSpec.swift in Sources */,
1F6F0CDF1E61E377008170FC /* TrackerSpec.swift in Sources */,
Expand Down
39 changes: 39 additions & 0 deletions PiwikTrackerTests/AutoTracker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// AutoTracker.swift
// PiwikTracker
//
// Created by Cornelius Horstmann on 04.09.17.
// Copyright © 2017 PIWIK. All rights reserved.
//

import Foundation
@testable import PiwikTracker

extension TrackerSpec {

internal final class AutoTracker {

let tracker: PiwikTracker
let interval: TimeInterval
var timer: Timer?

init(tracker: PiwikTracker, trackingInterval: TimeInterval) {
self.tracker = tracker
self.interval = trackingInterval
}

@objc private func track() {
tracker.queue(event: EventFixture.event())
}

func start() {
self.timer = Timer.scheduledTimer(timeInterval: interval, target: self, selector: #selector(track), userInfo: nil, repeats: true)
}

func stop() {
self.timer?.invalidate()
}

}

}
6 changes: 3 additions & 3 deletions PiwikTrackerTests/TrackerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class TrackerSpec: QuickSpec {
success()
}
trackerFixture.tracker.queue(event: EventFixture.event())
let _ = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in
trackerFixture.tracker.queue(event: EventFixture.event())
}
let autoTracker = AutoTracker(tracker: trackerFixture.tracker, trackingInterval: 0.1)
autoTracker.start()
trackerFixture.tracker.dispatchInterval = 0.1
expect(numberOfDispatches).toEventually(equal(5), timeout: 5)
autoTracker.stop()
}
context("with an already dispatching tracker") {
it("should not ask the queue for events") {
Expand Down

0 comments on commit 81145e5

Please sign in to comment.