diff --git a/DXFeedFrameworkTests/DXConnectionTest.swift b/DXFeedFrameworkTests/DXConnectionTest.swift index a55e22590..610e9bb27 100644 --- a/DXFeedFrameworkTests/DXConnectionTest.swift +++ b/DXFeedFrameworkTests/DXConnectionTest.swift @@ -9,7 +9,15 @@ import XCTest @testable import DXFeedFramework private class Listener: DXEventListener { + let expectation: XCTestExpectation + + init(expectation: XCTestExpectation) { + self.expectation = expectation + self.expectation.assertForOverFulfill = false + } + func receiveEvents(_ events: [MarketEvent]) { + expectation.fulfill() events.forEach { print($0.toString()) } @@ -28,36 +36,39 @@ extension Listener: Hashable { } final class DXConnectionTest: XCTestCase { + override class func setUp() { + // The experimental property must be enabled. + try? SystemProperty.setProperty("dxfeed.experimental.dxlink.enable", "true") + } - -// connect "dxlink:wss://demo.dxfeed.com/dxlink-ws" Quote AAPL -p dxfeed.experimental.dxlink.enable=true func testDXLinkConnection() throws { - try SystemProperty.setProperty("dxfeed.experimental.dxlink.enable", "true") + // For token-based authorization, use the following address format: + // "dxlink:wss://demo.dxfeed.com/dxlink-ws[login=dxlink:token]" let endpoint = try DXEndpoint.builder() .withProperty("dxfeed.address", "dxlink:wss://demo.dxfeed.com/dxlink-ws") .build() let subscription = try endpoint.getFeed()?.createSubscription(EventCode.quote) - let eventListener = Listener() + let receivedEventsExpectation = expectation(description: "Received events") + let eventListener = Listener(expectation: receivedEventsExpectation) try subscription?.add(listener: eventListener) try subscription?.addSymbols("AAPL") - wait(seconds: 2) + wait(for: [receivedEventsExpectation], timeout: 2) } func testConnection() throws { + // For token-based authorization, use the following address format: + // "demo.dxfeed.com:7300[login=entitle:token]" let endpoint = try DXEndpoint.builder() .withProperty("dxfeed.address", "demo.dxfeed.com:7300") .build() let subscription = try endpoint.getFeed()?.createSubscription(EventCode.quote) - let eventListener = Listener() + let receivedEventsExpectation = expectation(description: "Received events") + let eventListener = Listener(expectation: receivedEventsExpectation) try subscription?.add(listener: eventListener) try subscription?.addSymbols("AAPL") - wait(seconds: 2) + wait(for: [receivedEventsExpectation], timeout: 2) } - - - - func testPerformanceExample() throws { // This is an example of a performance test case. self.measure {