Skip to content

Commit

Permalink
revert pubsub test
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazhvera committed May 13, 2024
1 parent ae7634a commit 67807ab
Showing 1 changed file with 47 additions and 34 deletions.
81 changes: 47 additions & 34 deletions Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1514,48 +1514,61 @@ class Mqtt5ClientTests: XCBaseTestCase {
/*
* [Op-UC4] Multi-sub unsub
*/
func testMqtt5MultiSubUnsub() async throws {
let inputHost = try getEnvironmentVarOrSkipTest(environmentVarName: "AWS_TEST_MQTT5_DIRECT_MQTT_HOST")
let inputPort = try getEnvironmentVarOrSkipTest(environmentVarName: "AWS_TEST_MQTT5_DIRECT_MQTT_PORT")

func testMqtt5SubUnsub() async throws {
try skipIfPlatformDoesntSupportTLS()
let inputHost = try getEnvironmentVarOrSkipTest(environmentVarName: "AWS_TEST_MQTT5_IOT_CORE_HOST")
let inputCert = try getEnvironmentVarOrSkipTest(environmentVarName: "AWS_TEST_MQTT5_IOT_CORE_RSA_CERT")
let inputKey = try getEnvironmentVarOrSkipTest(environmentVarName: "AWS_TEST_MQTT5_IOT_CORE_RSA_KEY")

let tlsOptions = try TLSContextOptions.makeMTLS(
certificatePath: inputCert,
privateKeyPath: inputKey
)
let tlsContext = try TLSContext(options: tlsOptions, mode: .client)

let clientOptions = MqttClientOptions(
hostName: inputHost,
port: UInt32(inputPort)!)

port: UInt32(8883),
tlsCtx: tlsContext)

let testContext = MqttTestContext()
let client = try createClient(clientOptions: clientOptions, testContext: testContext)
try connectClient(client: client, testContext: testContext)

let topic1 = "test/MQTT5_Binding_Swift_" + UUID().uuidString
let topic2 = "test/MQTT5_Binding_Swift_" + UUID().uuidString
let subscriptions = [Subscription(topicFilter: topic1, qos: QoS.atLeastOnce, noLocal: false),
Subscription(topicFilter: topic2, qos: QoS.atMostOnce, noLocal: false)]
let subscribePacket = SubscribePacket(subscriptions: subscriptions)


let topic = "test/MQTT5_Binding_Swift_" + UUID().uuidString
let subscribePacket = SubscribePacket(topicFilter: topic, qos: QoS.atLeastOnce, noLocal: false)
let subackPacket: SubackPacket =
try await withTimeout(client: client, seconds: 2, operation: {
try await client.subscribe(subscribePacket: subscribePacket)
})

let expectedSubacKEnums = [SubackReasonCode.grantedQos1, SubackReasonCode.grantedQos0]
try compareEnums(arrayOne: subackPacket.reasonCodes, arrayTwo: expectedSubacKEnums)
print("SubackPacket received with results")
for i in 0..<subackPacket.reasonCodes.count {
print("Index:\(i) result:\(subackPacket.reasonCodes[i])")
try await withTimeout(client: client, seconds: 2, operation: {
try await client.subscribe(subscribePacket: subscribePacket)
})
print("SubackPacket received with result \(subackPacket.reasonCodes[0])")

let publishPacket = PublishPacket(qos: QoS.atLeastOnce, topic: topic, payload: "Hello World".data(using: .utf8))
let publishResult: PublishResult =
try await withTimeout(client: client, seconds: 2, operation: {
try await client.publish(publishPacket: publishPacket)
})

if let puback = publishResult.puback {
print("PubackPacket received with result \(puback.reasonCode)")
} else {
XCTFail("PublishResult missing.")
return
}

let unsubscribeTopics = [topic1, topic2, "fake_topic1"]
let unsubscribePacket = UnsubscribePacket(topicFilters: unsubscribeTopics)
let unsubackPacket: UnsubackPacket =
try await withTimeout(client: client, seconds: 2, operation: {
try await client.unsubscribe(unsubscribePacket: unsubscribePacket)
})

print("UnsubackPacket received with results")
for i in 0..<unsubackPacket.reasonCodes.count {
print("Index:\(i) result:\(unsubackPacket.reasonCodes[i])")

if testContext.semaphorePublishReceived.wait(timeout: .now() + 5) == .timedOut {
print("Publish not received after 5 seconds")
XCTFail("Publish packet not received on subscribed topic")
return
}


let unsubscribePacket = UnsubscribePacket(topicFilter: topic)
let unsubackPacket: UnsubackPacket =
try await withTimeout(client: client, seconds: 2, operation: {
try await client.unsubscribe(unsubscribePacket: unsubscribePacket)
})
print("UnsubackPacket received with result \(unsubackPacket.reasonCodes[0])")

try disconnectClientCleanup(client: client, testContext: testContext)
}

Expand Down

0 comments on commit 67807ab

Please sign in to comment.