Skip to content

Commit

Permalink
fix for 15.2 and 15.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ndurell committed Nov 6, 2024
1 parent a7c4e0a commit 4b1afbf
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/KlaviyoCore/KlaviyoEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import Foundation
import UIKit

// Though this is a var it should never be modified outside of tests.
#if swift(>=6)
public nonisolated(unsafe) var environment = KlaviyoEnvironment.production
#else
public var environment = KlaviyoEnvironment.production
#endif

public struct KlaviyoEnvironment: Sendable {
public init(
Expand Down
4 changes: 4 additions & 0 deletions Sources/KlaviyoCore/Networking/KlaviyoAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@ public struct KlaviyoAPI: Sendable {
}

// For internal testing use only
#if swift(>=6)
public nonisolated(unsafe) static var requestHandler: (KlaviyoRequest, URLRequest?, RequestStatus) -> Void = { _, _, _ in }
#else
public static var requestHandler: (KlaviyoRequest, URLRequest?, RequestStatus) -> Void = { _, _, _ in }
#endif
}
4 changes: 4 additions & 0 deletions Sources/KlaviyoCore/Networking/NetworkSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,9 @@ public struct NetworkSession: Sendable {
}

public enum URLProtocolOverrides {
#if swift(>=6)
public nonisolated(unsafe) static var protocolClasses = [AnyClass]()
#else
public static var protocolClasses = [AnyClass]()
#endif
}
6 changes: 6 additions & 0 deletions Tests/KlaviyoCoreTests/ArchivalUtilsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ import XCTest

@MainActor
class ArchivalUtilsTests: XCTestCase {
#if swift(>=6)
nonisolated(unsafe) var dataToWrite: Data?
nonisolated(unsafe) var wroteToFile = false
nonisolated(unsafe) var removedFile = false
#else
var dataToWrite: Data?
var wroteToFile = false
var removedFile = false
#endif

override func setUp() async throws {
environment = KlaviyoEnvironment.test()
Expand Down
6 changes: 6 additions & 0 deletions Tests/KlaviyoCoreTests/FileUtilsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ import XCTest

@MainActor
class FileUtilsTests: XCTestCase {
#if swift(>=6)
nonisolated(unsafe) var dataToWrite: Data?
nonisolated(unsafe) var wroteToFile = false
nonisolated(unsafe) var removedFile = false
#else
var dataToWrite: Data?
var wroteToFile = false
var removedFile = false
#endif

override func setUp() async throws {
environment = KlaviyoEnvironment.test()
Expand Down
12 changes: 12 additions & 0 deletions Tests/KlaviyoSwiftTests/AppLifeCycleEventsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import XCTest

@MainActor
class AppLifeCycleEventsTests: XCTestCase, Sendable {
#if swift(>=6)
nonisolated(unsafe) let passThroughSubject = PassthroughSubject<Notification, Never>()
#else
let passThroughSubject = PassthroughSubject<Notification, Never>()
#endif

func getFilteredNotificaitonPublished(name: Notification.Name) -> @Sendable (Notification.Name) -> AnyPublisher<Notification, Never> {
// returns passthrough if it's match other return nothing
Expand Down Expand Up @@ -96,7 +100,11 @@ class AppLifeCycleEventsTests: XCTestCase, Sendable {
func testAppBecomesActiveStartsReachibility() {
environment.notificationCenterPublisher = getFilteredNotificaitonPublished(name: UIApplication.didBecomeActiveNotification)
let expection = XCTestExpectation(description: "Start reachability is called.")
#if swift(>=6)
nonisolated(unsafe) var count = 0
#else
var count = 0
#endif
let cancellable = AppLifeCycleEvents().lifeCycleEvents(environment.notificationCenterPublisher, {
if count == 0 {
count += 1
Expand Down Expand Up @@ -175,7 +183,11 @@ class AppLifeCycleEventsTests: XCTestCase, Sendable {
func testReachabilityStatusNilThenNotNil() {
let expection = XCTestExpectation(description: "Reachability status is accessed")
environment.notificationCenterPublisher = getFilteredNotificaitonPublished(name: ReachabilityChangedNotification)
#if swift(>=6)
nonisolated(unsafe) var count = 0
#else
var count = 0
#endif
let cancellable = AppLifeCycleEvents().lifeCycleEvents(environment.notificationCenterPublisher, {}, {}, {
if count == 0 {
count += 1
Expand Down
8 changes: 7 additions & 1 deletion Tests/KlaviyoSwiftTests/StateManagementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ import Foundation
import KlaviyoCore
import XCTest

#if swift(>=6)
nonisolated(unsafe) var count = 0
#else
var count = 0
#endif

@MainActor
class StateManagementTests: XCTestCase {
override func setUp() async throws {
environment = KlaviyoEnvironment.test()
klaviyoSwiftEnvironment = KlaviyoSwiftEnvironment.test()
count = 0
}

// MARK: - Initialization
Expand Down Expand Up @@ -266,7 +273,6 @@ class StateManagementTests: XCTestCase {
}

func testFlushQueueWithMultipleRequests() async throws {
nonisolated(unsafe) var count = 0
// request uuids need to be unique :)
environment.uuid = {
count += 1
Expand Down

0 comments on commit 4b1afbf

Please sign in to comment.