Skip to content

Commit 61a4b75

Browse files
authored
Merge pull request #55 from Parsely/bugfix/use-uint64-for-timestamps
Use UInt64 for rand timestamp
2 parents 8372991 + c42c8b0 commit 61a4b75

File tree

11 files changed

+52
-22
lines changed

11 files changed

+52
-22
lines changed

.travis.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
language: swift
2-
osx_image: xcode10.1
3-
xcode_workspace: ParselyDemo.xcworkspace
4-
xcode_scheme: ParselyTrackerTests
5-
xcode_destination: platform=iOS Simulator,OS=11.4,name=iPhone X
6-
before_install:
7-
- pod repo update
2+
os: osx
3+
4+
git:
5+
depth: 1
6+
7+
stages:
8+
- name: test
9+
10+
jobs:
11+
include:
12+
- stage: test
13+
name: Run Unit Tests (iOS 10.3.1, iPhone 5)
14+
osx_image: xcode10.1
15+
xcode_workspace: ParselyDemo.xcworkspace
16+
xcode_scheme: ParselyTrackerTests
17+
xcode_destination: platform=iOS Simulator,OS=10.3.1,name=iPhone 5
18+
before_install:
19+
- pod repo update
20+
- stage: test
21+
name: Run Unit Tests (iOS 11.4, iPhone X)
22+
osx_image: xcode10.1
23+
xcode_workspace: ParselyDemo.xcworkspace
24+
xcode_scheme: ParselyTrackerTests
25+
xcode_destination: platform=iOS Simulator,OS=11.4,name=iPhone X
26+
before_install:
27+
- pod repo update

ParselyDemo.xcodeproj/project.pbxproj

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@
763763
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
764764
GCC_WARN_UNUSED_FUNCTION = YES;
765765
GCC_WARN_UNUSED_VARIABLE = YES;
766-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
766+
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
767767
MTL_ENABLE_DEBUG_INFO = YES;
768768
ONLY_ACTIVE_ARCH = YES;
769769
SDKROOT = iphoneos;
@@ -816,7 +816,7 @@
816816
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
817817
GCC_WARN_UNUSED_FUNCTION = YES;
818818
GCC_WARN_UNUSED_VARIABLE = YES;
819-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
819+
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
820820
MTL_ENABLE_DEBUG_INFO = NO;
821821
SDKROOT = iphoneos;
822822
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
@@ -833,6 +833,7 @@
833833
CODE_SIGN_STYLE = Automatic;
834834
DEVELOPMENT_TEAM = N3Z6SG5Z94;
835835
INFOPLIST_FILE = ParselyDemo/Info.plist;
836+
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
836837
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
837838
PRODUCT_BUNDLE_IDENTIFIER = com.parsely.ParselyDemo;
838839
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -850,6 +851,7 @@
850851
CODE_SIGN_STYLE = Automatic;
851852
DEVELOPMENT_TEAM = N3Z6SG5Z94;
852853
INFOPLIST_FILE = ParselyDemo/Info.plist;
854+
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
853855
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
854856
PRODUCT_BUNDLE_IDENTIFIER = com.parsely.ParselyDemo;
855857
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -867,6 +869,7 @@
867869
CODE_SIGN_STYLE = Automatic;
868870
DEVELOPMENT_TEAM = N3Z6SG5Z94;
869871
INFOPLIST_FILE = AnalyticsSDKTests/Info.plist;
872+
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
870873
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
871874
PRODUCT_BUNDLE_IDENTIFIER = com.parsely.AnalyticsSDKTests;
872875
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -885,6 +888,7 @@
885888
CODE_SIGN_STYLE = Automatic;
886889
DEVELOPMENT_TEAM = N3Z6SG5Z94;
887890
INFOPLIST_FILE = AnalyticsSDKTests/Info.plist;
891+
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
888892
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
889893
PRODUCT_BUNDLE_IDENTIFIER = com.parsely.AnalyticsSDKTests;
890894
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -908,6 +912,7 @@
908912
DYLIB_INSTALL_NAME_BASE = "@rpath";
909913
INFOPLIST_FILE = ParselyTracker/Info.plist;
910914
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
915+
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
911916
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
912917
PRODUCT_BUNDLE_IDENTIFIER = com.parsely.ParselyTracker;
913918
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -933,6 +938,7 @@
933938
DYLIB_INSTALL_NAME_BASE = "@rpath";
934939
INFOPLIST_FILE = ParselyTracker/Info.plist;
935940
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
941+
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
936942
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
937943
PRODUCT_BUNDLE_IDENTIFIER = com.parsely.ParselyTracker;
938944
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -952,7 +958,9 @@
952958
CODE_SIGN_STYLE = Automatic;
953959
DEVELOPMENT_TEAM = N3Z6SG5Z94;
954960
INFOPLIST_FILE = ParselyTrackerTests/Info.plist;
961+
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
955962
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
963+
MACOSX_DEPLOYMENT_TARGET = 10.15;
956964
PRODUCT_BUNDLE_IDENTIFIER = com.parsely.ParselyTrackerTests;
957965
PRODUCT_NAME = "$(TARGET_NAME)";
958966
SWIFT_VERSION = 4.2;
@@ -969,7 +977,9 @@
969977
CODE_SIGN_STYLE = Automatic;
970978
DEVELOPMENT_TEAM = N3Z6SG5Z94;
971979
INFOPLIST_FILE = ParselyTrackerTests/Info.plist;
980+
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
972981
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
982+
MACOSX_DEPLOYMENT_TARGET = 10.15;
973983
PRODUCT_BUNDLE_IDENTIFIER = com.parsely.ParselyTrackerTests;
974984
PRODUCT_NAME = "$(TARGET_NAME)";
975985
SWIFT_VERSION = 4.2;

ParselyTracker/Event.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Event {
1414
var session_referrer: String?
1515
var last_session_timestamp: Int?
1616
var parsely_site_uuid: String?
17-
var rand: Int!
17+
var rand: UInt64!
1818

1919
init(_ action: String,
2020
url: String,

ParselyTracker/Metadata.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class ParselyMetadata {
4848
metas["link"] = canonical_url!
4949
}
5050
if pub_date != nil {
51-
metas["pub_date"] = String(format:"%i", pub_date!.timeIntervalSince1970 * 1000)
51+
metas["pub_date"] = String(format:"%i", pub_date!.millisecondsSince1970)
5252
}
5353
if title != nil {
5454
metas["title"] = title!

ParselyTracker/Session.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SessionManager {
2929
session["session_id"] = visitorInfo["session_count"]
3030
session["session_url"] = url
3131
session["session_referrer"] = urlref
32-
session["session_ts"] = Int(Date().timeIntervalSince1970 * 1000.0)
32+
session["session_ts"] = Date().millisecondsSince1970
3333
session["last_session_ts"] = visitorInfo["last_session_ts"]
3434

3535
visitorInfo["last_session_ts"] = session["session_ts"]

ParselyTracker/Storage.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Foundation
22

33
extension Date {
4-
var millisecondsSince1970:Int {
5-
return Int((self.timeIntervalSince1970 * 1000.0).rounded())
4+
var millisecondsSince1970:UInt64 {
5+
return UInt64(floor(self.timeIntervalSince1970 * 1000))
66
}
77

8-
init(milliseconds:Int) {
8+
init(milliseconds:UInt64) {
99
self = Date(timeIntervalSince1970: TimeInterval(milliseconds) / 1000)
1010
}
1111
}

ParselyTrackerTests/EventQueueTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class EventQueueTests: ParselyTestCase {
3636
}
3737

3838
func testGetTooMany() {
39-
XCTAssert(self.queue.get(count:99999999999) == [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30])
39+
XCTAssert(self.queue.get(count:2147483647) == [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30])
4040
}
4141

4242
func testNegativeCount() {

ParselyTrackerTests/EventTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class EventTests: ParselyTestCase {
115115
XCTAssertEqual(actualExtraData["parsely_site_uuid"] as! String, expectedVisitorID,
116116
"A visitor ID provided via Event.setVisitorInfo should be accessible in the result of " +
117117
"Event.toDict as data[\"parsely_site_uuid\"]")
118-
XCTAssert((actualExtraData["ts"] as! Int) > timestampInThePast,
118+
XCTAssert((actualExtraData["ts"] as! UInt64) > timestampInThePast,
119119
"The data.ts field of the result of Event.toDict should be a non-ancient timestamp")
120120
}
121121

ParselyTrackerTests/MetadataTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class MetadataTests: ParselyTestCase {
3939
duration: expected["duration"] as? TimeInterval
4040
)
4141
let actual: Dictionary<String, Any> = metasUnderTest.toDict()
42-
let pubDateUnix: String = String(format:"%i", (expected["pub_date"]! as! Date).timeIntervalSince1970 * 1000)
42+
let pubDateUnix: String = String(format:"%i", (expected["pub_date"]! as! Date).millisecondsSince1970)
4343
XCTAssertFalse(actual.isEmpty, "Creating a ParselyMetadataobject with many parameters results in a " +
4444
"non-empty object")
4545
XCTAssertEqual(actual["link"]! as! String, expected["canonical_url"]! as! String,

ParselyTrackerTests/SessionTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class SessionTests: ParselyTestCase {
2323
"The session_url of a newly-created session should be the url it was initialized with")
2424
XCTAssertEqual(session["session_referrer"] as! String, testSubsequentUrl,
2525
"The session_referrer of a newly-created session should be the urlref it was initialized with")
26-
XCTAssertGreaterThan(session["session_ts"] as! Int, epochTimeInThePast,
26+
XCTAssertGreaterThan(session["session_ts"] as! UInt64, UInt64(epochTimeInThePast),
2727
"The session_ts of a newly-created session should be non-ancient")
28-
XCTAssertGreaterThan(session["last_session_ts"] as! Int, epochTimeInThePast,
28+
XCTAssertGreaterThan(session["last_session_ts"] as! UInt64, UInt64(epochTimeInThePast),
2929
"The last_session_ts of a newly-created session should be non-ancient")
3030
}
3131

@@ -48,10 +48,10 @@ class SessionTests: ParselyTestCase {
4848
let session = sessions.get(url: testInitialUrl, urlref: testSubsequentUrl)
4949
let mutatedVisitor = visitorManager.getVisitorInfo()
5050
let expectedSessionCount = initialSessionCount + 1
51-
let expectedLastSessionTs: Int = session["session_ts"] as! Int
51+
let expectedLastSessionTs: UInt64 = session["session_ts"] as! UInt64
5252
XCTAssertEqual(mutatedVisitor["session_count"] as! Int, expectedSessionCount,
5353
"The visitor's session_count should have been incremented after a call to SessionManager.get")
54-
XCTAssertEqual(mutatedVisitor["last_session_ts"] as! Int, expectedLastSessionTs,
54+
XCTAssertEqual(mutatedVisitor["last_session_ts"] as! UInt64, UInt64(expectedLastSessionTs),
5555
"The visitor's last_session_ts should have been set to the session's session_ts after a call to " +
5656
"SessionManager.get")
5757
}

0 commit comments

Comments
 (0)