Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a9ddb4

Browse files
committed
Sendable checking
1 parent42b0637 commit9a9ddb4

File tree

11 files changed

+159
-59
lines changed

11 files changed

+159
-59
lines changed

‎Sources/AsyncHTTPClient/ConnectionPool/HTTPExecutableRequest.swift‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,13 @@ protocol HTTPRequestExecutor {
201201
func cancelRequest(_ task:HTTPExecutableRequest)
202202
}
203203

204-
protocolHTTPExecutableRequest:AnyObject{
204+
#if swift(>=5.6)
205+
typealias_HTTPExecutableRequestSendable=Sendable
206+
#else
207+
typealias_HTTPExecutableRequestSendable=Any
208+
#endif
209+
210+
protocolHTTPExecutableRequest:AnyObject,_HTTPExecutableRequestSendable{
205211
/// The request's logger
206212
varlogger:Logger{get}
207213

‎Sources/AsyncHTTPClient/HTTPClient.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,3 +1025,8 @@ public struct HTTPClientError: Error, Equatable, CustomStringConvertible {
10251025
@available(*, deprecated, message:"AsyncHTTPClient now correctly supports informational headers. For this reason `httpEndReceivedAfterHeadWith1xx` will not be thrown anymore.")
10261026
publicstaticlethttpEndReceivedAfterHeadWith1xx=HTTPClientError(code:.httpEndReceivedAfterHeadWith1xx)
10271027
}
1028+
1029+
#if swift(>=5.6)
1030+
/// HTTPClient is Sendable, since shared state is protected by the internal ``stateLock``.
1031+
extensionHTTPClient:@uncheckedSendable{}
1032+
#endif

‎Sources/AsyncHTTPClient/HTTPHandler.swift‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414

1515
import Foundation
1616
import Logging
17-
import NIOConcurrencyHelpers
17+
#if swift(>=5.6)
18+
@preconcurrencyimport NIOCore
19+
#else
1820
import NIOCore
21+
#endif
22+
import NIOConcurrencyHelpers
1923
import NIOHTTP1
2024
import NIOSSL
2125

@@ -385,6 +389,12 @@ public class ResponseAccumulator: HTTPClientResponseDelegate {
385389
}
386390
}
387391

392+
#if swift(>=5.6)
393+
@preconcurrencypublicprotocol_HTTPClientResponseDelegate:Sendable{}
394+
#else
395+
publicprotocol_HTTPClientResponseDelegate{}
396+
#endif
397+
388398
/// `HTTPClientResponseDelegate` allows an implementation to receive notifications about request processing and to control how response parts are processed.
389399
/// You can implement this protocol if you need fine-grained control over an HTTP request/response, for example, if you want to inspect the response
390400
/// headers before deciding whether to accept a response body, or if you want to stream your request body. Pass an instance of your conforming
@@ -414,7 +424,7 @@ public class ResponseAccumulator: HTTPClientResponseDelegate {
414424
/// released together with the `HTTPTaskHandler` when channel is closed.
415425
/// Users of the library are not required to keep a reference to the
416426
/// object that implements this protocol, but may do so if needed.
417-
publicprotocolHTTPClientResponseDelegate:AnyObject{
427+
publicprotocolHTTPClientResponseDelegate:AnyObject,_HTTPClientResponseDelegate{
418428
associatedtypeResponse
419429

420430
/// Called when the request head is sent. Will be called once.
@@ -635,6 +645,11 @@ extension HTTPClient {
635645
}
636646
}
637647

648+
#if swift(>=5.6)
649+
// HTTPClient.Task is Sendable thanks to the internal lock.
650+
extensionHTTPClient.Task:@uncheckedSendable{}
651+
#endif
652+
638653
internalstructTaskCancelEvent{}
639654

640655
// MARK: - RedirectHandler

‎Sources/AsyncHTTPClient/RequestBag.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,8 @@ extension RequestBag: HTTPClientTaskDelegate {
446446
}
447447
}
448448
}
449+
450+
#if swift(>=5.6)
451+
// RequestBag is Sendable because everything is dispatched onto the EL.
452+
extensionRequestBag:@uncheckedSendable{}
453+
#endif

‎Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
@testableimport AsyncHTTPClient
16-
import Logging
16+
@preconcurrencyimport Logging
1717
import NIOCore
1818
import NIOPosix
1919
import XCTest
@@ -327,13 +327,14 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
327327
letclient=makeDefaultHTTPClient()
328328
defer{XCTAssertNoThrow(try client.syncShutdown())}
329329
letlogger=Logger(label:"HTTPClient", factory:StreamLogHandler.standardOutput(label:))
330-
varrequest=HTTPClientRequest(url:"http://localhost:\(bin.port)/offline")
331-
request.method=.POST
332-
letstreamWriter=AsyncSequenceWriter<ByteBuffer>()
333-
request.body=.stream(streamWriter, length:.unknown)
334330

335-
lettask=Task<HTTPClientResponse,Error>{[request]in
336-
tryawait client.execute(request, deadline:.now()+.seconds(2), logger: logger)
331+
lettask=Task<Void,Error>{
332+
varrequest=HTTPClientRequest(url:"http://localhost:\(bin.port)/offline")
333+
request.method=.POST
334+
letstreamWriter=AsyncSequenceWriter<ByteBuffer>()
335+
request.body=.stream(streamWriter, length:.unknown)
336+
337+
_=tryawait client.execute(request, deadline:.now()+.seconds(2), logger: logger)
337338
}
338339
task.cancel()
339340
awaitXCTAssertThrowsError(tryawait task.value){ errorin
@@ -352,10 +353,10 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
352353
letclient=makeDefaultHTTPClient()
353354
defer{XCTAssertNoThrow(try client.syncShutdown())}
354355
letlogger=Logger(label:"HTTPClient", factory:StreamLogHandler.standardOutput(label:))
355-
letrequest=HTTPClientRequest(url:"https://localhost:\(bin.port)/wait")
356356

357-
lettask=Task<HTTPClientResponse,Error>{[request]in
358-
tryawait client.execute(request, deadline:.now()+.milliseconds(100), logger: logger)
357+
lettask=Task<Void,Error>{
358+
letrequest=HTTPClientRequest(url:"https://localhost:\(bin.port)/wait")
359+
_=tryawait client.execute(request, deadline:.now()+.milliseconds(100), logger: logger)
359360
}
360361
awaitXCTAssertThrowsError(tryawait task.value){ errorin
361362
guardlet error= erroras?HTTPClientErrorelse{
@@ -377,10 +378,10 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
377378
letclient=makeDefaultHTTPClient()
378379
defer{XCTAssertNoThrow(try client.syncShutdown())}
379380
letlogger=Logger(label:"HTTPClient", factory:StreamLogHandler.standardOutput(label:))
380-
letrequest=HTTPClientRequest(url:"http://localhost:\(bin.port)/wait")
381381

382-
lettask=Task<HTTPClientResponse,Error>{[request]in
383-
tryawait client.execute(request, deadline:.now(), logger: logger)
382+
lettask=Task<Void,Error>{
383+
letrequest=HTTPClientRequest(url:"http://localhost:\(bin.port)/wait")
384+
_=tryawait client.execute(request, deadline:.now(), logger: logger)
384385
}
385386
awaitXCTAssertThrowsError(tryawait task.value){ errorin
386387
guardlet error= erroras?HTTPClientErrorelse{

‎Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,10 @@ extension HTTPBin where RequestHandler == HTTPBinHandler {
591591
}
592592
}
593593

594+
#if swift(>=5.6)
595+
extensionHTTPBin:@uncheckedSendable{}
596+
#endif
597+
594598
enumHTTPBinError:Error{
595599
case refusedConnection
596600
case invalidProxyRequest

‎Tests/AsyncHTTPClientTests/HTTPConnectionPool+RequestQueueTests.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,7 @@ private class MockScheduledRequest: HTTPSchedulableRequest {
137137
preconditionFailure("Unimplemented")
138138
}
139139
}
140+
141+
#if swift(>=5.6)
142+
extensionMockScheduledRequest:@uncheckedSendable{}
143+
#endif

‎Tests/AsyncHTTPClientTests/Mocks/MockConnectionPool.swift‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
@testableimport AsyncHTTPClient
1616
import Logging
17+
#if swift(>=5.6)
18+
@preconcurrencyimport NIOCore
19+
#else
1720
import NIOCore
21+
#endif
1822
import NIOHTTP1
1923
import NIOSSL
2024

@@ -747,3 +751,7 @@ class MockHTTPRequest: HTTPSchedulableRequest {
747751
preconditionFailure("Unimplemented")
748752
}
749753
}
754+
755+
#if swift(>=5.6)
756+
extensionMockHTTPRequest:@uncheckedSendable{}
757+
#endif

‎Tests/AsyncHTTPClientTests/Mocks/MockRequestExecutor.swift‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
@testableimport AsyncHTTPClient
1616
import NIOConcurrencyHelpers
17+
#if swift(>=5.6)
18+
@preconcurrencyimport NIOCore
19+
#else
1720
import NIOCore
21+
#endif
1822

1923
// This is a MockRequestExecutor, that is synchronized on its EventLoop.
2024
finalclassMockRequestExecutor{
@@ -273,3 +277,9 @@ extension MockRequestExecutor {
273277
}
274278
}
275279
}
280+
281+
#if swift(>=5.6)
282+
extensionMockRequestExecutor:@uncheckedSendable{}
283+
extensionMockRequestExecutor.RequestParts:Sendable{}
284+
extensionMockRequestExecutor.BlockingQueue:@uncheckedSendable{}
285+
#endif

‎Tests/AsyncHTTPClientTests/RequestBagTests.swift‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@testableimport AsyncHTTPClient
1616
import Logging
1717
import NIOCore
18+
import NIOConcurrencyHelpers
1819
import NIOEmbedded
1920
import NIOHTTP1
2021
import XCTest
@@ -522,16 +523,24 @@ class UploadCountingDelegate: HTTPClientResponseDelegate {
522523
}
523524
}
524525

525-
classMockTaskQueuer:HTTPRequestScheduler{
526-
private(set)varhitCancelCount=0
526+
finalclassMockTaskQueuer:HTTPRequestScheduler{
527+
privatelethitCancelCounter= NIOAtomic<Int>.makeAtomic(value:0)
528+
529+
varhitCancelCount:Int{
530+
self.hitCancelCounter.load()
531+
}
527532

528533
init(){}
529534

530535
func cancelRequest(_:HTTPSchedulableRequest){
531-
self.hitCancelCount+=1
536+
self.hitCancelCounter.add(1)
532537
}
533538
}
534539

540+
#if swift(>=5.6)
541+
extensionMockTaskQueuer:@uncheckedSendable{}
542+
#endif
543+
535544
extensionRequestOptions{
536545
staticfunc forTests(idleReadTimeout:TimeAmount?=nil)->Self{
537546
RequestOptions(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp