Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev to main - fix date formatting, better debug logging #438

Merged
merged 3 commits into from
Nov 2, 2020
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
6 changes: 5 additions & 1 deletion AEPCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
24543A1624E1DC95002D8D9A /* MockUnzipper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2467E43C24CB54B70022F6BE /* MockUnzipper.swift */; };
2467E43A24CA4DE20022F6BE /* Unzipping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2467E43924CA4DE20022F6BE /* Unzipping.swift */; };
247FBD7D24E331A600FA6505 /* Event+SignalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 247FBD7C24E331A600FA6505 /* Event+SignalTests.swift */; };
249498E2254A0C920045E392 /* Date+FormatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 249498E0254A0C910045E392 /* Date+FormatTests.swift */; };
24B4935824D4C31100AA38D9 /* AEPSignal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24B4934F24D4C31100AA38D9 /* AEPSignal.framework */; };
24B4935D24D4C31100AA38D9 /* SignalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24B4935C24D4C31100AA38D9 /* SignalTests.swift */; };
24B4935F24D4C31100AA38D9 /* AEPSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = 24B4935124D4C31100AA38D9 /* AEPSignal.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -591,6 +592,7 @@
2467E43B24CB54B70022F6BE /* MockDiskCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MockDiskCache.swift; path = AEPServices/Mocks/MockDiskCache.swift; sourceTree = SOURCE_ROOT; };
2467E43C24CB54B70022F6BE /* MockUnzipper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MockUnzipper.swift; path = AEPServices/Mocks/MockUnzipper.swift; sourceTree = SOURCE_ROOT; };
247FBD7C24E331A600FA6505 /* Event+SignalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Event+SignalTests.swift"; sourceTree = "<group>"; };
249498E0254A0C910045E392 /* Date+FormatTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+FormatTests.swift"; sourceTree = "<group>"; };
2499461B24E5E67700D3F7B2 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
24B4934F24D4C31100AA38D9 /* AEPSignal.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AEPSignal.framework; sourceTree = BUILT_PRODUCTS_DIR; };
24B4935124D4C31100AA38D9 /* AEPSignal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AEPSignal.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1349,12 +1351,12 @@
3F0397E724BE60910019F095 /* unzip */,
3F0397F124BE60910019F095 /* AnyCodable.swift */,
3F0397E624BE60910019F095 /* AtomicCounter.swift */,
BB00E26A24D8C9A600C578C1 /* Date+Format.swift */,
3F0397EE24BE60910019F095 /* OperationOrderer.swift */,
2107F02D24C9FF88002935CF /* SHA256.swift */,
3F0397ED24BE60910019F095 /* ThreadSafeArray.swift */,
3F0397EF24BE60910019F095 /* ThreadSafeDictionary.swift */,
3F0397F024BE60910019F095 /* URLEncoder.swift */,
BB00E26A24D8C9A600C578C1 /* Date+Format.swift */,
);
path = utility;
sourceTree = "<group>";
Expand Down Expand Up @@ -1408,6 +1410,7 @@
isa = PBXGroup;
children = (
3F03981124BE61520019F095 /* AnyCodableTests.swift */,
249498E0254A0C910045E392 /* Date+FormatTests.swift */,
3F03980F24BE61520019F095 /* OperationOrdererTests.swift */,
3F03981024BE61520019F095 /* PersistentHitQueueTests.swift */,
2107F02F24C9FFB2002935CF /* SHA256Tests.swift */,
Expand Down Expand Up @@ -2585,6 +2588,7 @@
buildActionMask = 2147483647;
files = (
3F03981624BE61520019F095 /* SystemInfoServiceTest.swift in Sources */,
249498E2254A0C920045E392 /* Date+FormatTests.swift in Sources */,
3F03981E24BE61520019F095 /* DataQueueTests.swift in Sources */,
3F03981524BE61520019F095 /* UnzipperTest.swift in Sources */,
3F03982424BE61520019F095 /* AnyCodableTests.swift in Sources */,
Expand Down
12 changes: 11 additions & 1 deletion AEPCore/Sources/eventhub/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ public class Event: NSObject, Codable {

/// Event description used for logging
@objc override public var description: String {
return "id: \(id.uuidString) name: \(name) type: \(type) source: \(source) data: \(String(describing: data)) timestamp: \(timestamp.description) responseId: \(String(describing: responseID?.uuidString))"
// swiftformat:disable indent
return "\n[\n" +
" id: \(id.uuidString)\n" +
" name: \(name)\n" +
" type: \(type)\n" +
" source: \(source)\n" +
" data: \(data as AnyObject)\n" +
" timestamp: \(timestamp.description)\n" +
" responseId: \(String(describing: responseID?.uuidString))\n" +
"]"
// swiftformat:enable indent
}

/// Creates a new `Event` with the given parameters
Expand Down
26 changes: 13 additions & 13 deletions AEPCore/Sources/eventhub/EventHub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ final class EventHub {
eventHubQueue.async {
self.eventQueue.start()
self.shareEventHubSharedState() // share state of all registered extensions
Log.debug(label: "\(self.LOG_TAG):\(#function)", "Event Hub successfully started")
Log.debug(label: self.LOG_TAG, "Event Hub successfully started")
}
}

Expand All @@ -84,7 +84,7 @@ final class EventHub {
// Set an event number for the event
eventNumberMap[event.id] = eventNumberCounter.incrementAndGet()
eventQueue.add(event)
Log.trace(label: "\(LOG_TAG):\(#function)", "Event #\(String(describing: eventNumberMap[event.id] ?? 0)), \(event) is dispatched.")
Log.trace(label: LOG_TAG, "Dispatching Event #\(String(describing: eventNumberMap[event.id] ?? 0)) - \(event)")
}

/// Registers a new `Extension` to the `EventHub`. This `Extension` must implement `Extension`
Expand All @@ -94,7 +94,7 @@ final class EventHub {
func registerExtension(_ type: Extension.Type, completion: @escaping (_ error: EventHubError?) -> Void) {
eventHubQueue.async {
guard !type.typeName.isEmpty else {
Log.warning(label: "\(self.LOG_TAG):\(#function)", "Extension name must not be empty.")
Log.warning(label: self.LOG_TAG, "Extension name must not be empty.")
completion(.invalidExtensionName)
return
}
Expand All @@ -108,7 +108,7 @@ final class EventHub {
let extensionQueue = DispatchQueue(label: "com.adobe.eventhub.extension.\(type.typeName)")
let extensionContainer = ExtensionContainer(type, extensionQueue, completion: completion)
self.registeredExtensions[type.typeName] = extensionContainer
Log.debug(label: "\(self.LOG_TAG):\(#function)", "\(type.typeName) successfully registered.")
Log.debug(label: self.LOG_TAG, "\(type.typeName) successfully registered.")
}
}

Expand All @@ -119,7 +119,7 @@ final class EventHub {
func unregisterExtension(_ type: Extension.Type, completion: @escaping (_ error: EventHubError?) -> Void) {
eventHubQueue.async {
guard self.registeredExtensions[type.typeName] != nil else {
Log.error(label: "\(self.LOG_TAG):\(#function)", "Cannot unregister an extension that is not registered.")
Log.error(label: self.LOG_TAG, "Cannot unregister an extension that is not registered.")
completion(.extensionNotRegistered)
return
}
Expand Down Expand Up @@ -156,13 +156,13 @@ final class EventHub {
/// - event: `Event` for which the `SharedState` should be versioned
func createSharedState(extensionName: String, data: [String: Any]?, event: Event?) {
guard let (sharedState, version) = versionSharedState(extensionName: extensionName, event: event) else {
Log.warning(label: "\(LOG_TAG):\(#function)", "Error creating shared state for \(extensionName).")
Log.warning(label: LOG_TAG, "Error creating shared state for \(extensionName)")
return
}

sharedState.set(version: version, data: data)
dispatch(event: createSharedStateEvent(extensionName: extensionName))
Log.debug(label: "\(LOG_TAG):\(#function)", "Shared state is created for \(extensionName) with data \(String(describing: data)) and version \(version)")
Log.debug(label: LOG_TAG, "Shared state created for \(extensionName) with version \(version) and data: \n\(data as AnyObject)")
}

/// Sets the `SharedState` for the extension to pending at `event`'s version and returns a `SharedStateResolver` which is to be invoked with data for the `SharedState` once available.
Expand All @@ -179,12 +179,12 @@ final class EventHub {
if let (sharedState, version) = versionSharedState(extensionName: extensionName, event: event) {
pendingVersion = version
sharedState.addPending(version: version)
Log.debug(label: "\(LOG_TAG):\(#function)", "Pending shared state is created for \(extensionName) with version \(version)")
Log.debug(label: LOG_TAG, "Pending shared state created for \(extensionName) with version \(version)")
}

return { [weak self] data in
self?.resolvePendingSharedState(extensionName: extensionName, version: pendingVersion, data: data)
Log.debug(label: "\(self?.LOG_TAG ?? "EventHub"):\(#function)", "Pending shared state is resolved for \(extensionName) with data \(String(describing: data)) and version \(String(describing: pendingVersion))")
Log.debug(label: self?.LOG_TAG ?? "EventHub", "Pending shared state resolved for \(extensionName) with version \(String(describing: pendingVersion)) and data: \n\(data as AnyObject)")
}
}

Expand All @@ -196,7 +196,7 @@ final class EventHub {
/// - Returns: The `SharedState` data and status for the extension with `extensionName`
func getSharedState(extensionName: String, event: Event?, barrier: Bool = true) -> SharedStateResult? {
guard let container = registeredExtensions.first(where: { $1.sharedStateName == extensionName })?.value, let sharedState = container.sharedState else {
Log.warning(label: "\(LOG_TAG):\(#function)", "Unable to retrieve shared state for \(extensionName). No such extension is registered.")
Log.warning(label: LOG_TAG, "Unable to retrieve shared state for \(extensionName). No such extension is registered.")
return nil
}

Expand Down Expand Up @@ -248,14 +248,14 @@ final class EventHub {
EventHubConstants.EventDataKeys.EXTENSIONS: extensionsInfo]

guard let sharedState = registeredExtensions.first(where: { $1.sharedStateName == EventHubConstants.NAME })?.value.sharedState else {
Log.warning(label: "\(LOG_TAG):\(#function)", "Extension not registered with EventHub")
Log.warning(label: LOG_TAG, "Extension not registered with EventHub")
return
}

let version = sharedState.resolve(version: 0).value == nil ? 0 : eventNumberCounter.incrementAndGet()
sharedState.set(version: version, data: data)
dispatch(event: createSharedStateEvent(extensionName: EventHubConstants.NAME))
Log.debug(label: "\(LOG_TAG):\(#function)", "Shared state is created for \(EventHubConstants.NAME) with data \(String(describing: data)) and version \(version)")
Log.debug(label: LOG_TAG, "Shared state created for \(EventHubConstants.NAME) with version \(version) and data: \n\(data as AnyObject)")
}

// MARK: - Private
Expand All @@ -268,7 +268,7 @@ final class EventHub {
/// - Returns: A `(SharedState, Int)?` containing the state for the provided extension and its version number
private func versionSharedState(extensionName: String, event: Event?) -> (SharedState, Int)? {
guard let extensionContainer = registeredExtensions.first(where: { $1.sharedStateName == extensionName })?.value else {
Log.error(label: "\(LOG_TAG):\(#function)", "Extension \(extensionName) not registered with EventHub")
Log.error(label: LOG_TAG, "Extension \(extensionName) not registered with EventHub")
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions AEPCore/Sources/rules/TokenFinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class TokenFinder: Traversable {
private let TOKEN_KEY_EVENT_TYPE = "~type"
private let TOKEN_KEY_EVENT_SOURCE = "~source"
private let TOKEN_KEY_TIMESTAMP_UNIX = "~timestampu"
private let TOKEN_KEY_TIMESTAMP_ISO8601 = "~timestampz"
private let TOKEN_KEY_TIMESTAMP_PLATFORM = "~timestampp"
private let TOKEN_KEY_TIMESTAMP_ISO8601_NO_COLON = "~timestampz"
private let TOKEN_KEY_TIMESTAMP_ISO8601 = "~timestampp"
private let TOKEN_KEY_SDK_VERSION = "~sdkver"
private let TOKEN_KEY_CACHEBUST = "~cachebust"
private let TOKEN_KEY_ALL_URL = "~all_url"
Expand Down Expand Up @@ -65,9 +65,9 @@ class TokenFinder: Traversable {
return event.source
case TOKEN_KEY_TIMESTAMP_UNIX:
return now.getUnixTimeInSeconds()
case TOKEN_KEY_TIMESTAMP_ISO8601_NO_COLON:
return now.getISO8601DateNoColon()
case TOKEN_KEY_TIMESTAMP_ISO8601:
return now.getRFC822Date()
case TOKEN_KEY_TIMESTAMP_PLATFORM:
return now.getISO8601Date()
case TOKEN_KEY_SDK_VERSION:
return MobileCore.extensionVersion
Expand Down
17 changes: 9 additions & 8 deletions AEPCore/Tests/RulesTests/TokenFinderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,21 @@ class TokenFinderTests: XCTestCase {
/// Given: initialize `TokenFinder` with mocked extension runtime & dummy event
let runtime = TestableExtensionRuntime()
let tokenFinder = TokenFinder(event: Event(name: "eventName", type: "eventType", source: "eventSource", data: nil), extensionRuntime: runtime)
let formatter_ISO8601 = DateFormatter()
formatter_ISO8601.locale = Locale(identifier: "en_US_POSIX")
formatter_ISO8601.setLocalizedDateFormatFromTemplate("yyyy-MM-dd'T'HH:mm:ssZZZ")
let formatter_PLATFORM = DateFormatter()
formatter_PLATFORM.locale = Locale(identifier: "en_US_POSIX")
formatter_PLATFORM.setLocalizedDateFormatFromTemplate("yyyy-MM-dd'T'HH:mm:ssXXX")
let formatter_ISO8601 = ISO8601DateFormatter()
formatter_ISO8601.timeZone = TimeZone.current
formatter_ISO8601.formatOptions.insert(.withInternetDateTime)
let formatter_ISO8601NoColon = DateFormatter()
formatter_ISO8601NoColon.locale = Locale(identifier: "en_US_POSIX")
formatter_ISO8601NoColon.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZ"

/// When: retrieve token `~timestampz`, `~timestampp` & `~timestampu`
guard let date_ISO8601_string = tokenFinder.get(key: "~timestampz") as? String, let date_ISO8601 = formatter_ISO8601.date(from: date_ISO8601_string), let date_PLATFORM_string = tokenFinder.get(key: "~timestampp") as? String, let date_PLATFORM = formatter_PLATFORM.date(from: date_PLATFORM_string), let date_UNIX_Int64 = tokenFinder.get(key: "~timestampu") as? Int64 else {
guard let date_ISO8601_string = tokenFinder.get(key: "~timestampp") as? String, let date_ISO8601 = formatter_ISO8601.date(from: date_ISO8601_string), let date_ISO8601NoColon_string = tokenFinder.get(key: "~timestampz") as? String, let date_ISO8601NoColon = formatter_ISO8601NoColon.date(from: date_ISO8601NoColon_string), let date_UNIX_Int64 = tokenFinder.get(key: "~timestampu") as? Int64 else {
XCTFail("Expected no-nil timestamp")
return
}
let date_UNIX = Date(timeIntervalSince1970: TimeInterval(date_UNIX_Int64))
/// Then: return same timestamp with different format
XCTAssertEqual(date_ISO8601, date_PLATFORM)
XCTAssertEqual(date_ISO8601, date_ISO8601NoColon)
XCTAssertEqual(date_ISO8601, date_UNIX)
}

Expand Down
2 changes: 1 addition & 1 deletion AEPIdentity/Sources/PushIDManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct PushIDManager: PushIDManageable {
pushEnabled = enabled
let pushStatusStr = enabled ? "True" : "False"
let contextData = [IdentityConstants.Analytics.EVENT_PUSH_STATUS: pushStatusStr]
let eventData = [IdentityConstants.Analytics.TRACK_ACTION: IdentityConstants.Analytics.PUSH_ID_ENABLED_ACTION_NAME,
let eventData = [IdentityConstants.Analytics.TRACK_ACTION: IdentityConstants.Analytics.PUSH_ID_ENABLED_ACTION_NAME,
IdentityConstants.Analytics.CONTEXT_DATA: contextData,
IdentityConstants.Analytics.TRACK_INTERNAL: true] as [String: Any]

Expand Down
14 changes: 7 additions & 7 deletions AEPIntegrationTests/LifecycleIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import AEPSignal

class LifecycleIntegrationTests: XCTestCase {
var mockNetworkService = TestableNetworkService()
let defaultSucsessResponse = HTTPURLResponse(url: URL(string: "https://adobe.com")!, statusCode: 200, httpVersion: nil, headerFields: [:])
let defaultSuccessResponse = HTTPURLResponse(url: URL(string: "https://adobe.com")!, statusCode: 200, httpVersion: nil, headerFields: [:])

override func setUp() {
UserDefaults.clear()
Expand Down Expand Up @@ -71,7 +71,7 @@ class LifecycleIntegrationTests: XCTestCase {
if request.url.absoluteString.starts(with: "https://www.lifecycle.com") {
lifecycleExpectation.fulfill()
XCTAssertTrue(request.url.absoluteString.contains("installevent=InstallEvent"))
return (data: nil, respsonse: self.defaultSucsessResponse, error: nil)
return (data: nil, respsonse: self.defaultSuccessResponse, error: nil)
}
return nil
}
Expand Down Expand Up @@ -105,7 +105,7 @@ class LifecycleIntegrationTests: XCTestCase {
lifecycleExpectation.fulfill()
XCTAssertTrue(request.url.absoluteString.contains("installevent=&"))
XCTAssertTrue(request.url.absoluteString.contains("launchevent=LaunchEvent"))
return (data: nil, respsonse: self.defaultSucsessResponse, error: nil)
return (data: nil, respsonse: self.defaultSuccessResponse, error: nil)
}
return nil
}
Expand Down Expand Up @@ -139,13 +139,13 @@ class LifecycleIntegrationTests: XCTestCase {
XCTAssertTrue(request.url.absoluteString.contains("installevent=&"))
XCTAssertTrue(request.url.absoluteString.contains("launchevent=LaunchEvent"))
XCTAssertTrue(request.url.absoluteString.contains("crashevent=CrashEvent"))
return (data: nil, respsonse: self.defaultSucsessResponse, error: nil)
return (data: nil, respsonse: self.defaultSuccessResponse, error: nil)
}
return nil
}

MobileCore.lifecycleStart(additionalContextData: nil)
wait(for: [lifecycleExpectation], timeout: 2)
wait(for: [lifecycleExpectation], timeout: 3)
}

func testAdditionalContextData() {
Expand All @@ -165,7 +165,7 @@ class LifecycleIntegrationTests: XCTestCase {
if request.url.absoluteString.starts(with: "https://www.lifecycle.com") {
lifecycleExpectation.fulfill()
XCTAssertTrue(request.url.absoluteString.contains("key=value"))
return (data: nil, respsonse: self.defaultSucsessResponse, error: nil)
return (data: nil, respsonse: self.defaultSuccessResponse, error: nil)
}
return nil
}
Expand Down Expand Up @@ -198,7 +198,7 @@ class LifecycleIntegrationTests: XCTestCase {
mockNetworkService.mock { request in
if request.url.absoluteString.starts(with: "https://www.lifecycle.com") {
lifecycleExpectation.fulfill()
return (data: nil, respsonse: self.defaultSucsessResponse, error: nil)
return (data: nil, respsonse: self.defaultSuccessResponse, error: nil)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion AEPLifecycle/Sources/Lifecycle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class Lifecycle: NSObject, Extension {
type: EventType.lifecycle,
source: EventSource.responseContent,
data: eventData)
Log.trace(label: LifecycleConstants.LOG_TAG, "Dispatching lifecycle start event with data: \(eventData)")
Log.trace(label: LifecycleConstants.LOG_TAG, "Dispatching lifecycle start event with data: \n\(eventData as AnyObject)")
dispatch(event: startEvent)
}

Expand Down
Loading