Skip to content

Commit

Permalink
Fix the new tests issues in Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Vkt0r committed May 1, 2019
1 parent c9e072b commit faf3a6e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
6 changes: 2 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ let package = Package(
dependencies: [
"Swifter"
],
path: "XCode/Tests",
exclude: [
"ServerThreadingTests.swift"
])
path: "XCode/Tests"
)
]
)
30 changes: 20 additions & 10 deletions XCode/Tests/ServerThreadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,54 @@ import XCTest
class ServerThreadingTests: XCTestCase {

var server: HttpServer!

override func setUp() {
super.setUp()
server = HttpServer()
}

override func tearDown() {
if server.operating {
server.stop()
}
server = nil
server = nil
super.tearDown()
}

func testShouldHandleTheSameRequestWithDifferentTimeIntervals() {

let path = "/a/:b/c"
let queue = DispatchQueue(label: "com.swifter.queue")

let queue = DispatchQueue(label: "com.swifter.threading")
let hostURL: URL

server.GET[path] = { .ok(.html("You asked for " + $0.path)) }

do {

#if os(Linux)
try server.start(9081)
hostURL = URL(string: "http://localhost:9081")!
#else
try server.start()
hostURL = defaultLocalhost
#endif

let requestExpectation = expectation(description: "Request should finish.")
requestExpectation.expectedFulfillmentCount = 3

(1...3).forEach { index in
queue.asyncAfter(deadline: .now() + .seconds(index)) {
let task = URLSession.shared.executeAsyncTask(path: path) { (_, response, _) in
let task = URLSession.shared.executeAsyncTask(hostURL: hostURL, path: path) { (_, response, _ ) in
requestExpectation.fulfill()
let statusCode = (response as? HTTPURLResponse)?.statusCode
XCTAssertNotNil(statusCode)
XCTAssertEqual(statusCode, 200)
XCTAssertEqual(statusCode, 200, "\(hostURL)")
}

task.resume()
}
}

} catch let error {
XCTFail("\(error)")
}
Expand All @@ -66,13 +75,14 @@ class ServerThreadingTests: XCTestCase {
var requestExpectation: XCTestExpectation? = expectation(description: "Should handle the request concurrently")

do {

try server.start()
let downloadGroup = DispatchGroup()

DispatchQueue.concurrentPerform(iterations: 3) { _ in
downloadGroup.enter()

let task = URLSession.shared.executeAsyncTask(path: path) { (_, response, _) in
let task = URLSession.shared.executeAsyncTask(path: path) { (_, response, _ ) in

let statusCode = (response as? HTTPURLResponse)?.statusCode
XCTAssertNotNil(statusCode)
Expand Down
11 changes: 11 additions & 0 deletions XCode/Tests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ extension MimeTypeTests {
]
}

extension ServerThreadingTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__ServerThreadingTests = [
("testShouldHandleTheSameRequestConcurrently", testShouldHandleTheSameRequestConcurrently),
("testShouldHandleTheSameRequestWithDifferentTimeIntervals", testShouldHandleTheSameRequestWithDifferentTimeIntervals),
]
}

extension SwifterTestsHttpParser {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
Expand Down Expand Up @@ -76,6 +86,7 @@ extension SwifterTestsWebSocketSession {
public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(MimeTypeTests.__allTests__MimeTypeTests),
testCase(ServerThreadingTests.__allTests__ServerThreadingTests),
testCase(SwifterTestsHttpParser.__allTests__SwifterTestsHttpParser),
testCase(SwifterTestsHttpRouter.__allTests__SwifterTestsHttpRouter),
testCase(SwifterTestsStringExtensions.__allTests__SwifterTestsStringExtensions),
Expand Down

0 comments on commit faf3a6e

Please sign in to comment.