swifter icon indicating copy to clipboard operation
swifter copied to clipboard

Removing/resetting routes

Open andrewtheis opened this issue 6 years ago • 2 comments

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.

andrewtheis avatar Sep 18 '19 19:09 andrewtheis

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
        }
    }

AndrewSad avatar Oct 25 '19 10:10 AndrewSad

What about using port: 0 (gives an auto-assigned port), then get the port try server.port()

chosa91 avatar May 28 '20 13:05 chosa91