swifter
swifter copied to clipboard
Removing/resetting routes
When using Swifter for unit tests, it would be nice to be able to reset all routes in tearDown(). Occasionally a request will fail with error The network connection was lost, likely due to stopping/starting several servers very quickly that all try to bind to 8080. Being able to keep an instance running but resetting the routes should make this error less likely.
Or you can add support for multiple ports on server start, for example, I use this in my iOS UI-tests for parallel runs:
class HTTPDynamicStubs {
var server = HttpServer()
var port: UInt16 = 8080
...
func setUp() {
setupInitialStubs()
while port != 8090 {
do {
try server.start(port)
print("Server started on port \(port)")
} catch {
port += 1
print("Failure, trying new port \(port)")
continue
}
break
}
}
What about using port: 0 (gives an auto-assigned port), then get the port try server.port()