Skip to content

Commit

Permalink
Added fix for crash in load(_:mimeType:characterEncodingName:baseURL:…
Browse files Browse the repository at this point in the history
…) (#286)

* Added fix for crash in load(_:mimeType:characterEncodingName:baseURL:)

* Whenever some test is using EmbraceHTTPMock, it should be able to use multiple connections at the same time w/o waiting

* Fixing race condition on test_updateCallback

* Fixing race condition on test_updateCallback
  • Loading branch information
ArielDemarco authored Jul 17, 2024
1 parent f11fdc2 commit 995b06b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ struct WKWebViewLoadFileURLSwizzler: Swizzlable {
}

struct WKWebViewLoadDataSwizzler: Swizzlable {
typealias ImplementationType = @convention(c) (WKWebView, Selector, Data, String, String, URL) -> WKNavigation?
typealias BlockImplementationType = @convention(block) (WKWebView, Data, String, String, URL) -> WKNavigation?
typealias ImplementationType = @convention(c) (WKWebView, Selector, Data, String, String, URL?) -> WKNavigation?
typealias BlockImplementationType = @convention(block) (WKWebView, Data, String, String, URL?) -> WKNavigation?
static var selector: Selector = #selector(
WKWebView.load(_:mimeType:characterEncodingName:baseURL:)
)
Expand Down
12 changes: 8 additions & 4 deletions Tests/EmbraceConfigInternalTests/EmbraceConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class EmbraceConfigTests: XCTestCase {
}

override func setUpWithError() throws {
EmbraceConfigTests.urlSessionConfig = URLSessionConfiguration.ephemeral
let config = URLSessionConfiguration.ephemeral
config.httpMaximumConnectionsPerHost = .max
EmbraceConfigTests.urlSessionConfig = config
EmbraceConfigTests.urlSessionConfig.protocolClasses = [EmbraceHTTPMock.self]
}

Expand Down Expand Up @@ -154,6 +156,10 @@ class EmbraceConfigTests: XCTestCase {
}

func test_updateCallback() throws {
expectation(forNotification: .embraceConfigUpdated, object: nil) { _ in
return true
}

// given a config with 1 hour minimum update interval
let options = testOptions(
deviceId: TestConstants.deviceId,
Expand All @@ -169,9 +175,7 @@ class EmbraceConfigTests: XCTestCase {
// making sure the fetched config is different so the notification is triggered
config.payload.backgroundSessionThreshold = 12345

expectation(forNotification: .embraceConfigUpdated, object: nil) { _ in
return true
}
config.update()

waitForExpectations(timeout: .veryLongTimeout)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ final class SessionControllerTests: XCTestCase {
}

let urlSessionconfig = URLSessionConfiguration.ephemeral
urlSessionconfig.httpMaximumConnectionsPerHost = .max
urlSessionconfig.protocolClasses = [EmbraceHTTPMock.self]

testOptions = EmbraceUpload.Options(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class UnsentDataHandlerTests: XCTestCase {
)

let urlSessionconfig = URLSessionConfiguration.ephemeral
urlSessionconfig.httpMaximumConnectionsPerHost = .max
urlSessionconfig.protocolClasses = [EmbraceHTTPMock.self]

let testCacheOptions = EmbraceUpload.CacheOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class EmbraceUploadOperationTests: XCTestCase {

override func setUpWithError() throws {
let urlSessionconfig = URLSessionConfiguration.ephemeral
urlSessionconfig.httpMaximumConnectionsPerHost = .max
urlSessionconfig.protocolClasses = [EmbraceHTTPMock.self]

self.urlSession = URLSession(configuration: urlSessionconfig)
Expand Down
1 change: 1 addition & 0 deletions Tests/EmbraceUploadInternalTests/EmbraceUploadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class EmbraceUploadTests: XCTestCase {
}

let urlSessionconfig = URLSessionConfiguration.ephemeral
urlSessionconfig.httpMaximumConnectionsPerHost = .max
urlSessionconfig.protocolClasses = [EmbraceHTTPMock.self]

testOptions = EmbraceUpload.Options(
Expand Down

0 comments on commit 995b06b

Please sign in to comment.