Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
110 lines (90 sloc) 2.82 KB

WebSockets Autobahn-Testsuite

This document will take you through the steps to test Kitura-Websockets using autobahn-testsuite.

Creating a EchoServer

These tests are run against a WebSocket EchoServer so we must first set one up.

  1. Create a swift project:
mkdir ~/WebSocketEchoServer
cd ~/WebSocketEchoServer
swift package init --type executable
open Package.swift
  1. Inside the Package.swift replace the text with:
// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "WebSocketEchoServer",
    dependencies: [
         .package(url: "https://github.com/IBM-Swift/Kitura.git", from: "2.3.0"),
         .package(url: "https://github.com/IBM-Swift/HeliumLogger.git", .upToNextMinor(from: "1.7.0")),
         .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket-NIO.git", from: "2.0.0")
    ],
    targets: [
    .target(
        name: "WebSocketEchoServer",
        dependencies: ["Kitura", "HeliumLogger", "Kitura-WebSocket"]),
    ]
)
  1. Open the projects main.swift file:
open ~/WebSocketEchoServer/Sources/WebSocketEchoServer/main.swift
  1. Inside the main.swift file replace print("Hello, world!") with:
import Foundation
import Kitura
import KituraWebSocket
import HeliumLogger

// Using an implementation for a Logger
HeliumLogger.use(.info)

let router = Router()

WebSocket.register(service: EchoService(), onPath: "/")

let port = 9001

Kitura.addHTTPServer(onPort: port, with: router)
Kitura.run()
  1. Create the EchoService file
cd ~/WebSocketEchoServer/Sources/WebSocketEchoServer/
touch EchoService.swift
open EchoService.swift
  1. Inside EchoService add the following code:
import Foundation

import KituraWebSocket
import LoggerAPI

class EchoService: WebSocketService {

    public func connected(connection: WebSocketConnection) {}

    public func disconnected(connection: WebSocketConnection, reason: WebSocketCloseReasonCode) {}

    public func received(message: Data, from: WebSocketConnection) {
        from.send(message: message)
    }

    public func received(message: String, from: WebSocketConnection) {
        Log.info("Got message \(message)... sending it back")
        from.send(message: message)
    }
}
  1. Start the EchoServer:
cd ~/WebSocketEchoServer
swift build
.build/x86_64-apple-macosx10.10/debug/WebSocketEchoServer

Install and run the test suite

Open a new terminal window and enter:

pip install autobahntestsuite
cd ~
mkdir testAutobahn
cd testAutobahn
wstest -m fuzzingclient

This will run the autobahn tests against a server running on port 9001. To change the tests inside testAutobahn: open fuzzingclient.json

In here you can select specific tests to include or exclude.

To view the results open ~/testAutobahn/reports/servers/index.html

You can’t perform that action at this time.