Skip to content

Commit

Permalink
Update to Swift 5 (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianpartridge authored Apr 10, 2019
1 parent 0d7e4b7 commit 2595b0a
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Package.resolved
.build
build
.vagrant
Package*
Packages*
*.pkg
Kitura-WebSocket.xcodeproj
*.DS_Store
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.3
5.0
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ matrix:
dist: xenial
sudo: required
services: docker
env: DOCKER_IMAGE=swift:4.2.3
env: DOCKER_IMAGE=swift:4.2.4 SWIFT_SNAPSHOT=4.2.4
- os: linux
dist: xenial
sudo: required
services: docker
env: DOCKER_IMAGE=swift:4.2.3 SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT
env: DOCKER_IMAGE=swift:5.0-xenial
- os: linux
dist: xenial
sudo: required
services: docker
env: DOCKER_IMAGE=ubuntu:18.04
env: DOCKER_IMAGE=swift:5.0 SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT
- os: osx
osx_image: xcode9.2
sudo: required
Expand All @@ -47,8 +47,12 @@ matrix:
- os: osx
osx_image: xcode10.1
sudo: required
env: SWIFT_SNAPSHOT=4.2.1
- os: osx
osx_image: xcode10.1
osx_image: xcode10.2
sudo: required
- os: osx
osx_image: xcode10.2
sudo: required
env: SWIFT_SNAPSHOT=$SWIFT_DEVELOPMENT_SNAPSHOT

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.0
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

/**
Expand Down
47 changes: 47 additions & 0 deletions Package@swift-4.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

/**
* Copyright IBM Corporation 2016, 2017
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

import PackageDescription

let package = Package(
name: "Kitura-WebSocket",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "Kitura-WebSocket",
targets: ["KituraWebSocket"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/IBM-Swift/Kitura-net.git", from: "2.1.0"),
.package(url: "https://github.com/IBM-Swift/BlueCryptor.git", from: "1.0.0"),

],
targets: [
// Targets are the basic building blocks of a package. A target defines a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "KituraWebSocket",
dependencies: ["KituraNet", "Cryptor"]),
.testTarget(
name: "KituraWebSocketTests",
dependencies: ["KituraWebSocket"]),
]
)
24 changes: 12 additions & 12 deletions Tests/KituraWebSocketTests/ConnectionCleanupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class ConnectionCleanupTests: KituraTest {
XCTAssertEqual(service.connections.count, 0, "Connections left on service at start of test")
guard let socket = self.sendUpgradeRequest(toPath: self.servicePath, usingKey: self.secWebKey) else { return }
let _ = self.checkUpgradeResponse(from: socket, forKey: self.secWebKey)
usleep(1500)
usleep(5000)
XCTAssertEqual(service.connections.count, 1, "Failed to create connection to service")
usleep(1500000)
XCTAssertEqual(service.connections.count, 1, "Stale connection was unexpectedly cleaned up")
socket.close()
usleep(150)
usleep(1000)
expectation.fulfill()
}
}
Expand All @@ -57,12 +57,12 @@ class ConnectionCleanupTests: KituraTest {
XCTAssertEqual(service.connections.count, 0, "Connections left on service at start of test")
guard let socket = self.sendUpgradeRequest(toPath: self.servicePath, usingKey: self.secWebKey) else { return }
let _ = self.checkUpgradeResponse(from: socket, forKey: self.secWebKey)
usleep(1500)
usleep(5000)
XCTAssertEqual(service.connections.count, 1, "Failed to create connection to service")
usleep(1500000)
XCTAssertEqual(service.connections.count, 0, "Stale connection was not cleaned up")
socket.close()
usleep(150)
usleep(1000)
expectation.fulfill()
}
}
Expand All @@ -74,7 +74,7 @@ class ConnectionCleanupTests: KituraTest {
XCTAssertEqual(service.connections.count, 0, "Connections left on service at start of test")
guard let socket = self.sendUpgradeRequest(toPath: self.servicePath, usingKey: self.secWebKey) else { return }
let _ = self.checkUpgradeResponse(from: socket, forKey: self.secWebKey)
usleep(1500)
usleep(5000)
XCTAssertEqual(service.connections.count, 1, "Failed to create connection to service")
usleep(500000)
self.sendFrame(final: true, withOpcode: self.opcodePing, withPayload: NSData(), on: socket)
Expand All @@ -86,7 +86,7 @@ class ConnectionCleanupTests: KituraTest {
usleep(500000)
XCTAssertEqual(service.connections.count, 0, "Connection was not removed even after getting a close opcode")
socket.close()
usleep(150)
usleep(1000)
expectation.fulfill()
}
}
Expand All @@ -98,11 +98,11 @@ class ConnectionCleanupTests: KituraTest {
XCTAssertEqual(service.connections.count, 0, "Connections left on service at start of test")
guard let socket = self.sendUpgradeRequest(toPath: self.servicePath, usingKey: self.secWebKey) else { return }
let _ = self.checkUpgradeResponse(from: socket, forKey: self.secWebKey)
usleep(1500)
usleep(5000)
XCTAssertEqual(service.connections.count, 1, "Failed to create connection to service")
guard let socket2 = self.sendUpgradeRequest(toPath: self.servicePath, usingKey: self.secWebKey) else { return }
let _ = self.checkUpgradeResponse(from: socket2, forKey: self.secWebKey)
usleep(1500)
usleep(5000)
XCTAssertEqual(service.connections.count, 2, "Failed to create second connection to service")
usleep(500000)
self.sendFrame(final: true, withOpcode: self.opcodePing, withPayload: NSData(), on: socket)
Expand All @@ -113,7 +113,7 @@ class ConnectionCleanupTests: KituraTest {
XCTAssertEqual(service.connections.count, 1, "Stale connection was not cleaned up")
socket.close()
socket2.close()
usleep(150)
usleep(1000)
expectation.fulfill()
}
}
Expand All @@ -125,14 +125,14 @@ class ConnectionCleanupTests: KituraTest {
XCTAssertEqual(service.connections.count, 0, "Connections left on service at start of test")
guard let socket = self.sendUpgradeRequest(toPath: self.servicePath, usingKey: self.secWebKey) else { return }
let _ = self.checkUpgradeResponse(from: socket, forKey: self.secWebKey)
usleep(1500)
usleep(5000)
XCTAssertEqual(service.connections.count, 1, "Failed to create connection to service")
let connections = Array(service.connections.values)
connections[0].processor?.close()
usleep(1500)
usleep(5000)
XCTAssertEqual(service.connections.count, 0, "Service was not notified of connection disconnect")
socket.close()
usleep(150)
usleep(1000)
expectation.fulfill()
}
}
Expand Down
8 changes: 1 addition & 7 deletions Tests/KituraWebSocketTests/ProtocolErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ class ProtocolErrorTests: KituraTest {

performServerTest() { expectation in

let text = "Testing, testing 1, 2, 3. "

let textPayload = self.payload(text: text)

let expectedPayload = NSMutableData()
var part = self.payload(closeReasonCode: .protocolError)
expectedPayload.append(part.bytes, length: part.length)
Expand All @@ -99,9 +95,7 @@ class ProtocolErrorTests: KituraTest {

let pingPayload = self.payload(text: "Testing, testing 1,2,3")

self.performTest(framesToSend: [(false, self.opcodePing, pingPayload),
(false, self.opcodeContinuation, textPayload),
(true, self.opcodeContinuation, textPayload)],
self.performTest(framesToSend: [(false, self.opcodePing, pingPayload)],
expectedFrames: [(true, self.opcodeClose, expectedPayload)],
expectation: expectation)
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import Glibc

srand(UInt32(time(nil)))
for (firstUnshuffled , unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) {
#if swift(>=4.1)
let d: Int = numericCast(random() % numericCast(unshuffledCount))
#else
let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount))
#endif
guard d != 0 else { continue }
let i = index(firstUnshuffled, offsetBy: d)
swapAt(firstUnshuffled, i)
Expand Down

0 comments on commit 2595b0a

Please sign in to comment.