You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following test in my XCTestCase, which should demonstrate the problem.
letmockServer=MockServer()
mockServer.start()
mockServer.router["/test"]=JSONResponse(){ _ ->NSDictionaryinprint("request received")return[:]}print("Send request")URLSession(configuration:URLSessionConfiguration.default).dataTask(with:URL(string:"http://localhost:8080/test")!).resume()sleep(3) // Any action or tear down delay.
print("stop mock server")
mockServer.stop() // Never ends
print("mock server stopped")
MockServer is a wrapper I have made, which handles starting and stopping the server.
I followed your gist about running the server.
classMockServer{letrouter=Router()privateletserver:HTTPServerprivateletserverDispatchQueue=DispatchQueue(label:"com.timr.uitest.serverDispatchQueue", qos:.background)privateleteventLoop:EventLoopprivatevareventLoopThreadCondition=NSCondition()init(){
eventLoop =try!SelectorEventLoop(selector:try!KqueueSelector())
server =DefaultHTTPServer(
eventLoop: eventLoop,
port:8080,
app: router.app
)}func start(){try! server.start()
eventLoopThreadCondition =NSCondition()
serverDispatchQueue.async(){self.eventLoop.runForever()self.eventLoopThreadCondition.lock()self.eventLoopThreadCondition.signal()self.eventLoopThreadCondition.unlock()}}func stop(){
server.stopAndWait()
eventLoopThreadCondition.lock()
eventLoop.stop()letstopEventLoopTimeout= 10.0
while eventLoop.running {
if !eventLoopThreadCondition.wait(until:Date(timeIntervalSinceNow: stopEventLoopTimeout)){fatalError("Join eventLoopThread timeout")}}}}
The problem is that the test never ends because it gets stuck at server.stopAndWait().
I get this output:
Send request
request received
stop mock server
As I digged a bit deeper I found out that the last event loop round does not finish. So the action awaited in stopAndWait, which is passed to eventLoop.call never gets called. runOncein EventLoop gets stuck at events = try selector.select(timeout: timeout).
Would be great if you could take a look on this issue @fangpenlin. This problem is a bit too deep for me.
The text was updated successfully, but these errors were encountered:
I have the following test in my
XCTestCase
, which should demonstrate the problem.MockServer
is a wrapper I have made, which handles starting and stopping the server.I followed your gist about running the server.
The problem is that the test never ends because it gets stuck at
server.stopAndWait()
.I get this output:
As I digged a bit deeper I found out that the last event loop round does not finish. So the action awaited in
stopAndWait
, which is passed toeventLoop.call
never gets called.runOnce
inEventLoop
gets stuck atevents = try selector.select(timeout: timeout)
.Would be great if you could take a look on this issue @fangpenlin. This problem is a bit too deep for me.
The text was updated successfully, but these errors were encountered: