Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test: allow ignoring non-existant file when cleaning up #1549

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
24 changes: 16 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,24 @@ matrix:
dist: xenial
sudo: required
services: docker
env: DOCKER_IMAGE=swift:5.0.3-xenial SWIFT_SNAPSHOT=5.0.3 SWIFT_TEST_ARGS="--parallel"
env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci:5.0.3 SWIFT_SNAPSHOT=5.0.3 SWIFT_TEST_ARGS="--parallel"
- os: linux
dist: xenial
sudo: required
services: docker
env: DOCKER_IMAGE=swift:5.1 SWIFT_TEST_ARGS="--parallel"
env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci:5.3.3 SWIFT_TEST_ARGS="--parallel"
- os: linux
dist: xenial
sudo: required
services: docker
env: DOCKER_IMAGE=swift:5.1 KITURA_NIO=1 SWIFT_TEST_ARGS="--parallel"
env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci:5.3.3 KITURA_NIO=1 SWIFT_TEST_ARGS="--parallel"
- os: linux
dist: xenial
sudo: required
services: docker
env: DOCKER_IMAGE=swift:5.1 SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT SWIFT_TEST_ARGS="--parallel"
env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci:5.3.3 SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT SWIFT_TEST_ARGS="--parallel"

# OSX SWIFT_SNAPSHOT should match that of built-in swift otherwise link issues may occur.
- os: osx
osx_image: xcode9.2
sudo: required
Expand All @@ -75,14 +77,20 @@ matrix:
- os: osx
osx_image: xcode11
sudo: required
env: KITURA_NIO=1 SWIFT_TEST_ARGS="--parallel"
env: SWIFT_SNAPSHOT=5.1 KITURA_NIO=1 SWIFT_TEST_ARGS="--parallel"
- os: osx
osx_image: xcode11
osx_image: xcode12.2
sudo: required
env: SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT SWIFT_TEST_ARGS="--parallel"
env: SWIFT_SNAPSHOT=5.3.1 KITURA_NIO=1 SWIFT_TEST_ARGS="--parallel"

# Disable non-standard swift builds on macOS due to library path issues.
#- os: osx
#osx_image: xcode12.2
#sudo: required
#env: SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT SWIFT_TEST_ARGS="--parallel"

before_install:
- git clone https://github.com/IBM-Swift/Package-Builder.git
- git clone https://github.com/Kitura/Package-Builder.git

script:
- ./Package-Builder/build-package.sh -projectDir $TRAVIS_BUILD_DIR
20 changes: 15 additions & 5 deletions Tests/KituraTests/KituraTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,23 @@ class KituraTest: XCTestCase {
}
self.port = port
}

var expectations: [XCTestExpectation] = []

let requestQueue = DispatchQueue(label: "Request queue")
for (index, asyncTask) in asyncTasks.enumerated() {
let expectation = self.expectation(line: line, index: index)
expectations.append(expectation)
requestQueue.async {
asyncTask(expectation)
}
}

// wait for timeout or for all created expectations to be fulfilled
waitForExpectations(timeout: timeout) { error in
XCTAssertNil(error)
}
wait(for: expectations, timeout: timeout)
// waitForExpectations(timeout: timeout) { error in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we clean this or do you plan to re-introduce it like that?

// XCTAssertNil(error)
// }

// If we created a short-lived server for specific ServerOptions, shut it down now
serverWithOptions?.stop()
Expand Down Expand Up @@ -367,7 +372,7 @@ class KituraTest: XCTestCase {
}

func expectation(line: Int, index: Int) -> XCTestExpectation {
return self.expectation(description: "\(type(of: self)):\(line)[\(index)](ssl:\(useSSL))")
return XCTestExpectation(description: "\(type(of: self)):\(line)[\(index)](ssl:\(useSSL))")
}

// Generates a unique temporary file path suitable for use as a Unix domain socket.
Expand All @@ -388,9 +393,14 @@ class KituraTest: XCTestCase {
}

// Delete a temporary file path.
func removeTemporaryFilePath(_ path: String) {
func removeTemporaryFilePath(_ path: String, ignoreIfNotExist: Bool=false) {
let fileURL = URL(fileURLWithPath: path)
let fm = FileManager.default
if ignoreIfNotExist {
guard fm.fileExists(atPath: path) else {
return
}
}
do {
try fm.removeItem(at: fileURL)
} catch {
Expand Down
3 changes: 2 additions & 1 deletion Tests/KituraTests/TestServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ final class TestServer: KituraTest, KituraTestSuite {
// Create a temporary socket path for this server
let socketPath = uniqueTemporaryFilePath()
defer {
removeTemporaryFilePath(socketPath)
// on Kitura.stop(), the socket is removed
removeTemporaryFilePath(socketPath, ignoreIfNotExist: true)
}

let router = Router()
Expand Down