[Swift Testing] Make it easy to use HTTPServer from Swift#63391
Conversation
|
EWS run on previous version of this PR (hash 2a35830) Details
|
2a35830 to
50fc6f9
Compare
|
EWS run on previous version of this PR (hash 50fc6f9) Details
|
50fc6f9 to
2675ab2
Compare
|
EWS run on previous version of this PR (hash 2675ab2) Details
|
2675ab2 to
23b4dff
Compare
|
EWS run on previous version of this PR (hash 23b4dff) Details
|
|
EWS run on previous version of this PR (hash 4e76a18) Details
|
|
EWS run on previous version of this PR (hash 30dc12f) Details
|
|
EWS run on previous version of this PR (hash cbc7059) Details
|
cbc7059 to
72abd4d
Compare
|
EWS run on previous version of this PR (hash 72abd4d) Details
|
72abd4d to
23b4dff
Compare
|
EWS run on previous version of this PR (hash cfe89d7) Details
|
cfe89d7 to
778781c
Compare
|
EWS run on previous version of this PR (hash 778781c) Details
|
778781c to
1470c37
Compare
|
EWS run on previous version of this PR (hash 1470c37) Details
|
| HTTPServer(std::initializer_list<std::pair<String, HTTPResponse>>, Protocol = Protocol::Http, CertificateVerifier&& = nullptr, SecIdentityRef = nullptr, std::optional<uint16_t> port = { }, bool startListeningImmediately = true); | ||
| HTTPServer(ResponseMap&& responses, Protocol = Protocol::Http, CertificateVerifier&& = nullptr, SecIdentityRef = nullptr, std::optional<uint16_t> port = { }, bool startListeningImmediately = true); |
There was a problem hiding this comment.
if we have a sync cancel() helper, we don't need this forked constructor logic.
There was a problem hiding this comment.
we can also now make startListening() private
There was a problem hiding this comment.
and you can drop this section from Swift run? Since the server is already listening from init?
await withCheckedContinuation { continuation in
unsafe self.storage.startListening(
consuming: .init(
{
continuation.resume()
},
WTF.ThreadLikeAssertion(WTF.CurrentThreadLike())
)
)
}| @@ -205,4 +213,6 @@ RetainPtr<SecIdentityRef> testIdentity(); | |||
| RetainPtr<SecIdentityRef> testIdentity2(); | |||
| void verifyCertificateAndPublicKey(SecTrustRef); | |||
|
|
|||
| void hashMapSet(HashMap<WTF::String, TestWebKitAPI::HTTPResponse>&, WTF::String&&, TestWebKitAPI::HTTPResponse&&); | |||
There was a problem hiding this comment.
two things: (1) does this need to be in a global namespace? (2) this feels like a general utility that could be housed in something like CxxInteropHelpers.h?
There was a problem hiding this comment.
I chose this deliberately because it is not general enough to go in a different file since it uses the specific types defined here, but it is general enough that it is unrelated to the core of TestWebKitAPI itself. Plus it’s temporary anyways so 🤷
There was a problem hiding this comment.
oh, temporary how? I think I missed that
There was a problem hiding this comment.
it’s just a swift compiler interop bug atm that it doesn’t work well with HashMap/generic types, so in the future this won’t be needed
| HTTPServer(std::initializer_list<std::pair<String, HTTPResponse>>, Protocol = Protocol::Http, CertificateVerifier&& = nullptr, SecIdentityRef = nullptr, std::optional<uint16_t> port = { }, bool startListeningImmediately = true); | ||
| HTTPServer(ResponseMap&& responses, Protocol = Protocol::Http, CertificateVerifier&& = nullptr, SecIdentityRef = nullptr, std::optional<uint16_t> port = { }, bool startListeningImmediately = true); |
There was a problem hiding this comment.
Consider making this an enum param? Makes it clearer from call sites
| HTTPServer(std::initializer_list<std::pair<String, HTTPResponse>>, Protocol = Protocol::Http, CertificateVerifier&& = nullptr, SecIdentityRef = nullptr, std::optional<uint16_t> port = { }, bool startListeningImmediately = true); | |
| HTTPServer(ResponseMap&& responses, Protocol = Protocol::Http, CertificateVerifier&& = nullptr, SecIdentityRef = nullptr, std::optional<uint16_t> port = { }, bool startListeningImmediately = true); | |
| enum class DeferListening : bool { No, Yes }; | |
| HTTPServer(std::initializer_list<std::pair<String, HTTPResponse>>, Protocol = Protocol::Http, CertificateVerifier&& = nullptr, SecIdentityRef = nullptr, std::optional<uint16_t> port = { }, DeferListening = DeferListening::No); | |
| HTTPServer(ResponseMap&& responses, Protocol = Protocol::Http, CertificateVerifier&& = nullptr, SecIdentityRef = nullptr, std::optional<uint16_t> port = { }, DeferListening = DeferListening::No); |
1470c37 to
87df6dd
Compare
|
EWS run on current version of this PR (hash 87df6dd) Details
|
https://bugs.webkit.org/show_bug.cgi?id=313093 rdar://175390188 Reviewed by Aditya Keerthi and Abrar Rahman Protyasha. Design and implement a Swift overlay of HTTPServer to make it so much nicer and easier to use from Swift. * Tools/TestWebKitAPI/Helpers/cocoa/HTTPServer.h: (TestWebKitAPI::HTTPServer::HTTPServer): * Tools/TestWebKitAPI/Helpers/cocoa/HTTPServer.mm: (TestWebKitAPI::HTTPServer::RequestData::RequestData): (TestWebKitAPI::HTTPServer::startListening): (TestWebKitAPI::HTTPServer::cancel): (TestWebKitAPI::HTTPServer::HTTPServer): (TestWebKitAPI::m_protocol): (hashMapSet): (TestWebKitAPI::startListening): Deleted. - Swift is unable to create an `std::initializer_list`, so add a `HashMap` overload for the constructor. - The `cancel` and `startListening` functions were masquarading as sync functions while in actuality they are async; change them to reflect their true async nature. - Change the Swift name of the Cxx HTTPServer so that Swift clients find the Swift version instead of the Cxx version. - Work around a limitation of Swift-Cxx interop with templated types by adding a helper setter function for a hashmap. * Tools/TestWebKitAPI/Helpers/cocoa/HTTPServer.swift: Added. (RouteBuilder.buildBlock(_:)): (HTTPServer.storage): Implement the Swift HTTPServer. * Tools/TestWebKitAPI/Helpers/cocoa/StdLibExtras.swift: Added. (WTF.description): Temporarily duplicate some code to make it easy to convert between WTF String and Swift String. * Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add the new file. * Tools/TestWebKitAPI/Tests/WebKit/WKWebView/AppPrivacyReport.mm: * Tools/TestWebKitAPI/Tests/WebKit/WKWebView/Download.mm: (TestWebKitAPI::ResumeCantReconnect)): * Tools/TestWebKitAPI/Tests/WebKit/WKWebView/ServiceWorkerBasic.mm: ((ServiceWorkers, ChangeOfServerCertificate)): Adjust some tests to accurately use the async cancel and startListening functions. * Tools/TestWebKitAPI/Tests/WebKit/WebPage/AppKitGesturesTests.swift: * Tools/TestWebKitAPI/Tests/WebKit/WebPage/URLSchemeHandlerTests.swift: * Tools/TestWebKitAPI/Tests/WebKit/WebPage/WebPageNavigationTests.swift: Disambiguate the `Task` type. Canonical link: https://commits.webkit.org/311958@main
87df6dd to
bb3490f
Compare
|
Committed 311958@main (bb3490f): https://commits.webkit.org/311958@main Reviewed commits have been landed. Closing PR #63391 and removing active labels. |
🛠 ios-safer-cpp
bb3490f
87df6dd