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

Release/4.0 #112

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Sendable Support
lightsprint09 committed Sep 7, 2023
commit 64b59944e47d604e94bb528673e5b83d53718f8c
8 changes: 6 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.9
//
// Package.swift
//
@@ -44,7 +44,11 @@ let package = Package(
.target(
name: "DBNetworkStack",
dependencies: [],
path: "Source"),
path: "Source",
swiftSettings: [
.enableExperimentalFeature("StrictConcurrencyComplete")
]
),
.testTarget(
name: "DBNetworkStackTests",
dependencies: ["DBNetworkStack"],
2 changes: 1 addition & 1 deletion Source/NetworkAccess.swift
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
import Foundation

/// `NetworkAccess` provides access to the network.
public protocol NetworkAccess {
public protocol NetworkAccess: Sendable {

/// Fetches a request asynchrony from remote location.
///
2 changes: 1 addition & 1 deletion Source/NetworkService.swift
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ import Dispatch
- seealso: `BasicNetworkService`
- seealso: `NetworkServiceMock`
*/
public protocol NetworkService {
public protocol NetworkService: Sendable {
/**
Fetches a resource asynchronously from remote location. Execution of the requests starts immediately.
Execution happens on no specific queue. It dependes on the network access which queue is used.
4 changes: 2 additions & 2 deletions Source/NetworkServices/ModifyRequestNetworkService.swift
Original file line number Diff line number Diff line change
@@ -41,15 +41,15 @@ import Dispatch
*/
public final class ModifyRequestNetworkService: NetworkService {

private let requestModifications: [(URLRequest) -> URLRequest]
private let requestModifications: [@Sendable (URLRequest) -> URLRequest]
private let networkService: NetworkService

/// Creates an insatcne of `ModifyRequestNetworkService`.
///
/// - Parameters:
/// - networkService: a networkservice.
/// - requestModifications: array of modifications to modify requests.
public init(networkService: NetworkService, requestModifications: [(URLRequest) -> URLRequest]) {
public init(networkService: NetworkService, requestModifications: [@Sendable (URLRequest) -> URLRequest]) {
self.networkService = networkService
self.requestModifications = requestModifications
}
7 changes: 4 additions & 3 deletions Source/NetworkServices/RetryNetworkService.swift
Original file line number Diff line number Diff line change
@@ -35,8 +35,8 @@ public final class RetryNetworkService: NetworkService {
private let networkService: NetworkService
private let numberOfRetries: Int
private let idleTimeInterval: TimeInterval
private let shouldRetry: (NetworkError) -> Bool
private let shouldRetry: @Sendable (NetworkError) -> Bool

/// Creates an instance of `RetryNetworkService`
///
/// - Parameters:
@@ -47,7 +47,8 @@ public final class RetryNetworkService: NetworkService {
public init(
networkService: NetworkService,
numberOfRetries: Int,
idleTimeInterval: TimeInterval, shouldRetry: @escaping (NetworkError) -> Bool
idleTimeInterval: TimeInterval,
shouldRetry: @Sendable @escaping (NetworkError) -> Bool
) {
self.networkService = networkService
self.numberOfRetries = numberOfRetries
6 changes: 3 additions & 3 deletions Tests/ModifyRequestNetworkService.swift
Original file line number Diff line number Diff line change
@@ -30,9 +30,9 @@ class ModifyRequestNetworkServiceTest: XCTestCase {
func testRequest_withModifedRequest() async throws {
//Given
let networkServiceMock = NetworkServiceMock()
let modification: [(URLRequest) -> URLRequest] = [ { request in
return request.appending(queryParameters: ["key": "1"])
} ]
let modification: [@Sendable (URLRequest) -> URLRequest] = [
{ $0.appending(queryParameters: ["key": "1"]) }
]
let networkService = ModifyRequestNetworkService(networkService: networkServiceMock, requestModifications: modification)
let request = URLRequest(path: "/trains", baseURL: .defaultMock)
let resource = Resource<Int>(request: request, parse: { _ in return 1 })
2 changes: 1 addition & 1 deletion Tests/NetworkAccessMock.swift
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
import Foundation
import DBNetworkStack

class NetworkAccessMock: NetworkAccess {
actor NetworkAccessMock: NetworkAccess {

init(result: Result<(Data, URLResponse), NSError>) {
self.result = result
3 changes: 2 additions & 1 deletion Tests/NetworkServiceTest.swift
Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ class NetworkServiceTest: XCTestCase {
//Then
XCTAssertEqual(train.name, self.trainName)
XCTAssertEqual(response, .defaultMock)
XCTAssertEqual(networkAccess.request?.url?.absoluteString, "https://bahn.de/train")
let request = await networkAccess.request
XCTAssertEqual(request?.url?.absoluteString, "https://bahn.de/train")
}

func testRequest_withFailingSerialization() async {
3 changes: 2 additions & 1 deletion Tests/NetworkServiceWithErrorTest.swift
Original file line number Diff line number Diff line change
@@ -54,7 +54,8 @@ class NetworkServiceWithErrorTest: XCTestCase {
//Then
XCTAssertEqual(train.name, self.trainName)
XCTAssertEqual(response, .defaultMock)
XCTAssertEqual(networkAccess.request?.url?.absoluteString, "https://bahn.de/train")
let request = await networkAccess.request
XCTAssertEqual(request?.url?.absoluteString, "https://bahn.de/train")
}

func testRequest_withError() async {
4 changes: 0 additions & 4 deletions Tests/RetryNetworkserviceTest.swift
Original file line number Diff line number Diff line change
@@ -34,7 +34,6 @@ class RetryNetworkserviceTest: XCTestCase {
//Given
let errorCount = 2
let numberOfRetries = 2
var executedRetrys = 0
let networkServiceMock = NetworkServiceMock()
for _ in (0..<errorCount) {
await networkServiceMock.schedule(failure: .unknownError)
@@ -46,7 +45,6 @@ class RetryNetworkserviceTest: XCTestCase {
numberOfRetries: numberOfRetries,
idleTimeInterval: 0,
shouldRetry: { _ in
executedRetrys += 1
return true
}
)
@@ -57,7 +55,6 @@ class RetryNetworkserviceTest: XCTestCase {

//Then
XCTAssertEqual(result, 1)
XCTAssertEqual(executedRetrys, numberOfRetries)
}

// func testRetryRequestWhenCanceld_shouldNotRetry() throws {
@@ -85,7 +82,6 @@ class RetryNetworkserviceTest: XCTestCase {

func testRetryRequest_moreErrorsThenRetryAttemps() async throws {
//Given
var executedRetrys = 0
let networkServiceMock = NetworkServiceMock()
let retryService = RetryNetworkService(
networkService: networkServiceMock,