Skip to content

Commit 70f7537

Browse files
committed
Got test working without mac specific check
1 parent 2c75a50 commit 70f7537

File tree

1 file changed

+0
-36
lines changed

1 file changed

+0
-36
lines changed

Tests/SwiftMCPTests/HTTPSSETransportTests.swift

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,6 @@ fileprivate let _initializeLogging: Void = {
1111
LoggingSystem.bootstrap { _ in NoOpLogHandler() }
1212
}()
1313

14-
/// Check if a port is available by attempting to create a server socket
15-
fileprivate func isPortAvailable(_ port: Int) -> Bool {
16-
let socket = socket(AF_INET, SOCK_STREAM, 0)
17-
if socket == -1 { return false }
18-
defer { Darwin.close(socket) }
19-
20-
var addr = sockaddr_in()
21-
addr.sin_family = sa_family_t(AF_INET)
22-
addr.sin_port = UInt16(port).bigEndian
23-
addr.sin_addr.s_addr = inet_addr("127.0.0.1")
24-
addr.sin_len = UInt8(MemoryLayout<sockaddr_in>.size)
25-
let bind_result = withUnsafePointer(to: &addr) { ptr in
26-
ptr.withMemoryRebound(to: sockaddr.self, capacity: 1) { ptr in
27-
Darwin.bind(socket, ptr, socklen_t(MemoryLayout<sockaddr_in>.size))
28-
}
29-
}
30-
return bind_result == 0
31-
}
32-
33-
/// Wait for a port to become available with timeout
34-
fileprivate func waitForPort(_ port: Int, timeout: TimeInterval = 5) async -> Bool {
35-
let start = Date()
36-
while Date().timeIntervalSince(start) < timeout {
37-
if isPortAvailable(port) {
38-
return true
39-
}
40-
try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
41-
}
42-
return false
43-
}
44-
4514
fileprivate func createTransport() async throws -> (HTTPSSETransport, MCPClient) {
4615
// Ensure logging is initialized
4716
_ = _initializeLogging
@@ -51,11 +20,6 @@ fileprivate func createTransport() async throws -> (HTTPSSETransport, MCPClient)
5120
// Create random port
5221
let port = Int.random(in: 49152...65535)
5322

54-
// Check if port is available
55-
guard await waitForPort(port, timeout: 1) else {
56-
continue
57-
}
58-
5923
// Create and configure transport
6024
let calculator = Calculator()
6125
let transport = HTTPSSETransport(server: calculator, port: port)

0 commit comments

Comments
 (0)