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

[feat] Concurrency improvements #52

Open
wants to merge 45 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a55d385
[feat] enable complete swift concurrency checking
matejmolnar Nov 24, 2023
06a9819
[fix] change shared static var property into get only
matejmolnar Nov 24, 2023
641bc10
[feat] add sendable conformances
matejmolnar Nov 24, 2023
ca85c82
[feat] conform authorization protocols to Actor
matejmolnar Nov 24, 2023
fbaa27b
[feat] conform RetryConfiguration to sendable
matejmolnar Nov 24, 2023
71f2a19
[chore] supress non-sendable type 'AnyCancellables' warning
matejmolnar Nov 24, 2023
196b8f7
[fix] DownloadManager swift concurrency warnings
matejmolnar Nov 24, 2023
7ba3e6b
[fix] UploadManager swift concurrency warnings
matejmolnar Nov 27, 2023
b8a20bc
[fix] warning: reference to static mutable property not thread safe
matejmolnar Nov 27, 2023
155dbb1
[feat] make processors and adapters conform to Sendable
matejmolnar Nov 27, 2023
e617286
[feat] add FileManager sendable conformance
matejmolnar Nov 27, 2023
7ca81c7
[feat] change EndpointRequestStorageProcessor and MultipeerConnectivi…
matejmolnar Nov 27, 2023
78b039f
[fix] lint warning
matejmolnar Dec 4, 2023
4107039
[fix] MultipeerConnectivityManager init crash
matejmolnar Dec 4, 2023
410f39f
[chore] remove unnecessary final keywords
matejmolnar Dec 4, 2023
bd75c8d
[fix] UploadService deinit retain cycle with singleton
matejmolnar Dec 4, 2023
82c53a3
[fix] tests
matejmolnar Dec 4, 2023
f75e1ed
[chore] revert let to lazy var
matejmolnar Dec 5, 2023
644e5e4
[chore] fix comment types
matejmolnar Dec 18, 2023
8bdffbe
[feat] change Actor protocol conformances to Sendable
matejmolnar Dec 18, 2023
9e72630
[chore] update package config
matejmolnar Dec 18, 2023
d385d34
[feat] change internal var to let
matejmolnar Dec 18, 2023
3386b03
[feat] add NetworkingActor
matejmolnar Dec 29, 2023
5bde238
[feat] conform DownloadAPIManaging to NetworkingActor
matejmolnar Dec 29, 2023
bde749f
[feat] add APIManagerTests
matejmolnar Dec 29, 2023
41ecd24
[feat] conform UploadAPIManaging to NetworkingActor
matejmolnar Dec 29, 2023
fb2fc95
[chore] remove unnecessary ThreadSafeDictionary
matejmolnar Dec 30, 2023
9febe71
[feat] conform other protocols and classes to @NetworkingActor
matejmolnar Dec 30, 2023
1effc96
[fix] concurrency warning
matejmolnar Dec 30, 2023
ab9ebcc
[chore] add comments
matejmolnar Dec 30, 2023
2312444
[feat] add multithread DownloadAPIManagerTests
matejmolnar Jan 1, 2024
f2bff45
[feat] change configuration
matejmolnar Jan 1, 2024
9dd468a
[chore] fix typo
matejmolnar Jan 1, 2024
24b7b30
[feat] add UploadAPIManagerTests
matejmolnar Jan 1, 2024
f54eb2b
Update Tests/NetworkingTests/UploadAPIManagerTests.swift
matejmolnar Jan 2, 2024
2590c04
Update Tests/NetworkingTests/DownloadAPIManagerTests.swift
matejmolnar Jan 2, 2024
3481616
[fix] multithread managers tests
matejmolnar Jan 2, 2024
c45f120
[fix] manager tests
matejmolnar Jan 3, 2024
dee8532
[chore] revert some classes back to open
matejmolnar Jan 8, 2024
9645825
[chore] update file name comments
matejmolnar Jan 9, 2024
296c372
[chore] remove unnecessary explicit Sendable conformance
matejmolnar Jan 9, 2024
987d49d
[chore] add final statement
matejmolnar Jan 9, 2024
d6613e0
[feat] change class to open
matejmolnar Jan 11, 2024
0b170b4
[feat] remove unnecessary async statement
matejmolnar Jan 11, 2024
7b8c5df
[fix] DownloadAPIManager tests by adjusting asyncResponse method
matejmolnar Jan 14, 2024
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
2 changes: 1 addition & 1 deletion Tests/NetworkingTests/APIManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class APIManagerTests: XCTestCase {
responseProcessors: []
)

// Create 15 parallel requests on multiple threads to test the managers thread safety.
// Create 15 parallel requests on multiple threads to test the manager's thread safety.
try await withThrowingTaskGroup(of: Void.self) { group in
for _ in 0..<15 {
group.addTask {
Expand Down
59 changes: 59 additions & 0 deletions Tests/NetworkingTests/DownloadAPIManagerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// File.swift
matejmolnar marked this conversation as resolved.
Show resolved Hide resolved
//
//
// Created by Matej Molnár on 01.01.2024.
//

@testable import Networking
import XCTest

@NetworkingActor
final class DownloadAPIManagerTests: XCTestCase {
enum DownloadRouter: Requestable {
case download(url: URL)

var baseURL: URL {
switch self {
case let .download(url):
url
}
}

var path: String {
switch self {
case .download:
""
}
}
}

func testMultiThreadRequests() async throws {
johnkodes marked this conversation as resolved.
Show resolved Hide resolved
let apiManager = DownloadAPIManager(
// A session configuration that uses no persistent storage for caches, cookies, or credentials.
urlSessionConfiguration: .ephemeral,
// Set empty response processors since the mock download requests return status code 0 and we don't want the test fail.
responseProcessors: []
)

// We can simulate the download even with a local file.
guard let downloadUrl = Bundle.module.url(forResource: "download_test", withExtension: "txt") else {
XCTFail("Resource not found")
return
}

// Create 15 parallel requests on multiple threads to test the manager's thread safety.
try await withThrowingTaskGroup(of: Void.self) { group in
for _ in 0..<15 {
group.addTask {
_ = try await apiManager.downloadRequest(
DownloadRouter.download(url: downloadUrl),
retryConfiguration: nil
)
}
}

try await group.waitForAll()
}
}
}
1 change: 1 addition & 0 deletions Tests/NetworkingTests/Resources/download_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
just a test download file
48 changes: 48 additions & 0 deletions Tests/NetworkingTests/UploadAPIManagerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// File.swift
matejmolnar marked this conversation as resolved.
Show resolved Hide resolved
//
//
// Created by Matej Molnár on 01.01.2024.
//

@testable import Networking
import XCTest

@NetworkingActor
final class UploadAPIManagerTests: XCTestCase {
enum UploadRouter: Requestable {
case mock

var baseURL: URL {
// swiftlint:disable:next force_unwrapping
URL(string: "https://uploadAPIManager.tests")!
}

var path: String {
"/mock"
}

var method: HTTPMethod {
.post
}
}

func testMultiThreadRequests2() async throws {
matejmolnar marked this conversation as resolved.
Show resolved Hide resolved
let apiManager = UploadAPIManager(
// A session configuration that uses no persistent storage for caches, cookies, or credentials.
urlSessionConfiguration: .ephemeral
)
let data = Data("Test data".utf8)

// Create 15 parallel requests on multiple threads to test the manager's thread safety.
try await withThrowingTaskGroup(of: Void.self) { group in
for _ in 0..<15 {
group.addTask {
_ = try await apiManager.upload(data: data, to: UploadRouter.mock)
}
}

try await group.waitForAll()
}
}
}