Skip to content

Commit

Permalink
Merge branch 'mqtt5-negative-time' into mqtt5-enum-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sbSteveK committed May 2, 2024
2 parents 4ae919f + 8ce38fd commit 597fce6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Source/AwsCommonRuntimeKit/mqtt/Mqtt5Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Mqtt5Client {
if rawValue != nil {
var errorCode: Int32 = 0

if let disconnectPacket = disconnectPacket {
if let disconnectPacket {
try disconnectPacket.validateConversionToNative()

disconnectPacket.withCPointer { disconnectPointer in
Expand Down
8 changes: 4 additions & 4 deletions Source/AwsCommonRuntimeKit/mqtt/Mqtt5Packets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public class PublishPacket: CStruct {
}

func validateConversionToNative() throws {
if let _messageExpiryInterval = messageExpiryInterval {
if _messageExpiryInterval < 0 || _messageExpiryInterval > Double(UInt32.max) {
if let messageExpiryInterval {
if messageExpiryInterval < 0 || messageExpiryInterval > Double(UInt32.max) {
throw MqttError.validation(message: "Invalid sessionExpiryInterval value")
}
}
Expand Down Expand Up @@ -680,8 +680,8 @@ public class DisconnectPacket: CStruct {
self.userProperties = userProperties
}
func validateConversionToNative() throws {
if let _sessionExpiryInterval = sessionExpiryInterval {
if _sessionExpiryInterval < 0 || _sessionExpiryInterval > Double(UInt32.max) {
if let sessionExpiryInterval {
if sessionExpiryInterval < 0 || sessionExpiryInterval > Double(UInt32.max) {
throw MqttError.validation(message: "Invalid sessionExpiryInterval value")
}
}
Expand Down
82 changes: 34 additions & 48 deletions Source/AwsCommonRuntimeKit/mqtt/Mqtt5Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -908,26 +908,22 @@ public class MqttConnectOptions: CStruct {
}

func validateConversionToNative() throws {
if let _keepAliveInterval = self.keepAliveInterval {
if _keepAliveInterval < 0 || _keepAliveInterval > Double(UInt16.max) {
if let keepAliveInterval {
if keepAliveInterval < 0 || keepAliveInterval > Double(UInt16.max) {
throw MqttError.validation(message: "Invalid keepAliveInterval value")
}
}

if let _sessionExpiryInterval = self.sessionExpiryInterval {
do {
_ = try _sessionExpiryInterval.secondUInt32()
} catch {
throw MqttError.validation(message: "Invalid sessionExpiryInterval value")
}
do {
_ = try sessionExpiryInterval?.secondUInt32()
} catch {
throw MqttError.validation(message: "Invalid sessionExpiryInterval value")
}

if let _willDelayInterval = self.willDelayInterval {
do {
_ = try _willDelayInterval.secondUInt32()
} catch {
throw MqttError.validation(message: "Invalid willDelayInterval value")
}
do {
_ = try willDelayInterval?.secondUInt32()
} catch {
throw MqttError.validation(message: "Invalid willDelayInterval value")
}
}

Expand Down Expand Up @@ -1227,52 +1223,42 @@ public class MqttClientOptions: CStructWithUserData {
}

func validateConversionToNative() throws {
if let _connectOptions = self.connectOptions {
try _connectOptions.validateConversionToNative()
if let connectOptions {
try connectOptions.validateConversionToNative()
}

if let _minReconnectDelay = self.minReconnectDelay {
do {
_ = try _minReconnectDelay.millisecondUInt64()
} catch {
throw MqttError.validation(message: "Invalid minReconnectDelay value")
}
do {
_ = try minReconnectDelay?.millisecondUInt64()
} catch {
throw MqttError.validation(message: "Invalid minReconnectDelay value")
}

if let _maxReconnectDelay = self.maxReconnectDelay {
do {
_ = try _maxReconnectDelay.millisecondUInt64()
} catch {
throw MqttError.validation(message: "Invalid maxReconnectDelay value")
}
do {
_ = try maxReconnectDelay?.millisecondUInt64()
} catch {
throw MqttError.validation(message: "Invalid maxReconnectDelay value")
}

if let _minConnectedTimeToResetReconnectDelay = self.minConnectedTimeToResetReconnectDelay {
do {
_ = try _minConnectedTimeToResetReconnectDelay.millisecondUInt64()
} catch {
throw MqttError.validation(message: "Invalid minConnectedTimeToResetReconnectDelay value")
}
do {
_ = try minConnectedTimeToResetReconnectDelay?.millisecondUInt64()
} catch {
throw MqttError.validation(message: "Invalid minConnectedTimeToResetReconnectDelay value")
}

if let _pingTimeout = self.pingTimeout {
do {
_ = try _pingTimeout.millisecondUInt32()
} catch {
throw MqttError.validation(message: "Invalid pingTimeout value")
}
do {
_ = try pingTimeout?.millisecondUInt32()
} catch {
throw MqttError.validation(message: "Invalid pingTimeout value")
}

if let _connackTimeout = self.connackTimeout {
do {
_ = try _connackTimeout.millisecondUInt32()
} catch {
throw MqttError.validation(message: "Invalid connackTimeout value")
}
do {
_ = try connackTimeout?.millisecondUInt32()
} catch {
throw MqttError.validation(message: "Invalid connackTimeout value")
}

if let _ackTimeout = self.ackTimeout {
if _ackTimeout < 0 || _ackTimeout > Double(UInt32.max) {
if let ackTimeout {
if ackTimeout < 0 || ackTimeout > Double(UInt32.max) {
throw MqttError.validation(message: "Invalid ackTimeout value")
}
}
Expand Down
7 changes: 1 addition & 6 deletions Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ class Mqtt5ClientTests: XCBaseTestCase {

/// stop client and check for discconnection and stopped lifecycle events
func disconnectClientCleanup(client: Mqtt5Client, testContext: MqttTestContext, disconnectPacket: DisconnectPacket? = nil) throws -> Void {
if let _disconnectPacket = disconnectPacket {
try client.stop(disconnectPacket: _disconnectPacket)
} else {
try client.stop()
}
try client.stop(disconnectPacket: disconnectPacket)

if testContext.semaphoreDisconnection.wait(timeout: .now() + 5) == .timedOut {
print("Disconnection timed out after 5 seconds")
Expand All @@ -49,7 +45,6 @@ class Mqtt5ClientTests: XCBaseTestCase {
/// stop client and check for stopped lifecycle event
func stopClient(client: Mqtt5Client, testContext: MqttTestContext) throws -> Void {
try client.stop()

if testContext.semaphoreStopped.wait(timeout: .now() + 5) == .timedOut {
print("Stop timed out after 5 seconds")
XCTFail("Stop timed out")
Expand Down

0 comments on commit 597fce6

Please sign in to comment.