Skip to content

Commit

Permalink
Update OmniTests.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
bragelbytes committed Mar 22, 2024
1 parent 39cc449 commit 038025d
Showing 1 changed file with 194 additions and 0 deletions.
194 changes: 194 additions & 0 deletions Tests/OmniTests/OmniTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,200 @@ final class OmniTests: XCTestCase {
}
}

func testOmniClientToEchoServerLargeMessage() async
{
do
{
let clientConfigPath = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("OmniClientConfig.json")
let clientMessage = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
let logger = Logger(label: "Omni")
let client = Omni(logger: logger)

let clientConfig = try OmniClientConfig(path: clientConfigPath.path)
print("☞ Parsed Omni Client config")

let connection = try await client.connect(config: clientConfig)
print("☞ Omni Client connected to the server.")

try await connection.writeString(string: clientMessage)
print("☞ Omni Client wrote to the server.")

let response = try await connection.read()
print("☞ Omni Client read from the server: \(response.string)")

XCTAssertEqual(clientMessage, response.string)
}
catch
{
print("Omni Echo test encountered an error: \(error)")
XCTFail()
}
}

func testOmniClientToEchoServerLargeMessage100Times() async
{
do
{
let clientConfigPath = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("OmniClientConfig.json")
let clientMessage = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
let logger = Logger(label: "Omni")
let client = Omni(logger: logger)

let clientConfig = try OmniClientConfig(path: clientConfigPath.path)
print("☞ Parsed Omni Client config")

let connection = try await client.connect(config: clientConfig)
print("☞ Omni Client connected to the server.")

for messageCount in 1...100
{
try await connection.writeString(string: clientMessage)
print("☞ Omni Client wrote to the server \(messageCount) time/s.")

let response = try await connection.read()
print("☞ Omni Client read from the server: \(response.string)")

XCTAssertEqual(clientMessage, response.string)
}
}
catch
{
print("Omni Echo test encountered an error: \(error)")
XCTFail()
}
}

func testOmniClientToEchoServerMultipleTimesThenRead() async
{
do
{
let clientConfigPath = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("OmniClientConfig.json")
let clientMessage = "pass"
let logger = Logger(label: "Omni")
let client = Omni(logger: logger)

var messageCount = 1

let clientConfig = try OmniClientConfig(path: clientConfigPath.path)
print("☞ Parsed Omni Client config")

let connection = try await client.connect(config: clientConfig)
print("☞ Omni Client connected to the server.")

while (messageCount <= 10)
{
try await connection.writeString(string: clientMessage)
print("☞ Omni Client wrote to the server \(messageCount) time/s.")
messageCount += 1
}

let response = try await connection.read()
print("☞ Omni Client read from the server: \(response.string)")

XCTAssertEqual(clientMessage, response.string)
}
catch
{
print("Omni Echo test encountered an error: \(error)")
XCTFail()
}
}

func testOmniClientToEchoServerWrite100Times() async
{
do
{
let clientConfigPath = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("OmniClientConfig.json")
let clientMessage = "pass"
let logger = Logger(label: "Omni")
let client = Omni(logger: logger)

let clientConfig = try OmniClientConfig(path: clientConfigPath.path)
print("☞ Parsed Omni Client config")

let connection = try await client.connect(config: clientConfig)
print("☞ Omni Client connected to the server.")

for messageCount in 1...100
{
try await connection.writeString(string: clientMessage)
print("☞ Omni Client wrote to the server \(messageCount) time/s.")
}
}
catch
{
print("Omni Echo test encountered an error: \(error)")
XCTFail()
}
}

func testOmniClientToEchoServerWriteAndRead100Times() async
{
do
{
let clientConfigPath = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("OmniClientConfig.json")
let clientMessage = "pass"
let logger = Logger(label: "Omni")
let client = Omni(logger: logger)

let clientConfig = try OmniClientConfig(path: clientConfigPath.path)
print("☞ Parsed Omni Client config")

let connection = try await client.connect(config: clientConfig)
print("☞ Omni Client connected to the server.")

for messageCount in 1...100
{
try await connection.writeString(string: clientMessage)
print("☞ Omni Client wrote to the server \(messageCount) time/s.")

let response = try await connection.read()
print("☞ Omni Client read from the server: \(response.string)")

XCTAssertEqual(clientMessage, response.string)
}
}
catch
{
print("Omni Echo test encountered an error: \(error)")
XCTFail()
}
}

func testOmniClientToEchoServerWrite100TimesThenRead() async
{
do
{
let clientConfigPath = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("OmniClientConfig.json")
let clientMessage = "pass"
let logger = Logger(label: "Omni")
let client = Omni(logger: logger)

let clientConfig = try OmniClientConfig(path: clientConfigPath.path)
print("☞ Parsed Omni Client config")

let connection = try await client.connect(config: clientConfig)
print("☞ Omni Client connected to the server.")

for messageCount in 1...100
{
try await Task.sleep(nanoseconds: 1000000)
try await connection.writeString(string: clientMessage)
print("☞ Omni Client wrote to the server \(messageCount) time/s.")
}

let response = try await connection.read()
print("☞ Omni Client read from the server: \(response.string)")

XCTAssertEqual(clientMessage, response.string)
}
catch
{
print("Omni Echo test encountered an error: \(error)")
XCTFail()
}
}

func testGenerateConfigs() throws
{
do
Expand Down

0 comments on commit 038025d

Please sign in to comment.