Skip to content

Commit

Permalink
improve test for connection(wait first events)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Nov 30, 2023
1 parent 36996b6 commit 2cef689
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions DXFeedFrameworkTests/DXConnectionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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 {
Expand Down

0 comments on commit 2cef689

Please sign in to comment.