Skip to content

Commit 0df4aef

Browse files
author
Bret Ambrose
committed
Test fixes and move submodule to fix branch for CI testing
1 parent aac457a commit 0df4aef

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

tests/Mqtt5ClientTest.cpp

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,8 @@ AWS_TEST_CASE(Mqtt5NegotiatedSettingsRejoinAlways, s_TestMqtt5NegotiatedSettings
14991499
*/
15001500
static int s_TestMqtt5SubUnsub(Aws::Crt::Allocator *allocator, void *)
15011501
{
1502+
ApiHandle apiHandle(allocator);
1503+
15021504
int receivedCount = 0;
15031505
std::mutex receivedLock;
15041506
std::condition_variable receivedSignal;
@@ -1554,8 +1556,10 @@ static int s_TestMqtt5SubUnsub(Aws::Crt::Allocator *allocator, void *)
15541556
allocator, TEST_TOPIC, ByteCursorFromByteBuf(payload), Mqtt5::QOS::AWS_MQTT5_QOS_AT_LEAST_ONCE, allocator);
15551557
ASSERT_TRUE(mqtt5Client->Publish(publish));
15561558

1557-
std::unique_lock<std::mutex> lock(receivedLock);
1558-
receivedSignal.wait(lock, [&receivedCount]() -> bool { return receivedCount >= 1; });
1559+
{
1560+
std::unique_lock<std::mutex> lock(receivedLock);
1561+
receivedSignal.wait(lock, [&receivedCount]() -> bool { return receivedCount >= 1; });
1562+
}
15591563

15601564
std::promise<std::shared_ptr<UnSubAckPacket>> unsubscribed;
15611565
Vector<String> topics;
@@ -1592,6 +1596,8 @@ AWS_TEST_CASE(Mqtt5SubUnsub, s_TestMqtt5SubUnsub)
15921596
*/
15931597
static int s_TestMqtt5WillTest(Aws::Crt::Allocator *allocator, void *)
15941598
{
1599+
ApiHandle apiHandle(allocator);
1600+
15951601
bool receivedWill = false;
15961602
std::mutex receivedLock;
15971603
std::condition_variable receivedSignal;
@@ -1676,8 +1682,10 @@ static int s_TestMqtt5WillTest(Aws::Crt::Allocator *allocator, void *)
16761682
ASSERT_TRUE(publisherClient->Stop(disconnect));
16771683
publisherContext.stoppedPromise.get_future().get();
16781684

1679-
std::unique_lock<std::mutex> lock(receivedLock);
1680-
receivedSignal.wait(lock, [&receivedWill]() -> bool { return receivedWill; });
1685+
{
1686+
std::unique_lock<std::mutex> lock(receivedLock);
1687+
receivedSignal.wait(lock, [&receivedWill]() -> bool { return receivedWill; });
1688+
}
16811689

16821690
ASSERT_TRUE(subscriberClient->Stop());
16831691
subscriberContext.stoppedPromise.get_future().get();
@@ -1695,6 +1703,8 @@ AWS_TEST_CASE(Mqtt5WillTest, s_TestMqtt5WillTest)
16951703
*/
16961704
static int s_TestMqtt5NullPublish(Aws::Crt::Allocator *allocator, void *)
16971705
{
1706+
ApiHandle apiHandle(allocator);
1707+
16981708
Mqtt5TestContext testContext = createTestContext(allocator, MQTT5CONNECT_DIRECT_IOT_CORE);
16991709
if (testContext.testDirective == AWS_OP_SKIP)
17001710
{
@@ -1726,6 +1736,8 @@ AWS_TEST_CASE(Mqtt5NullPublish, s_TestMqtt5NullPublish)
17261736
*/
17271737
static int s_TestMqtt5NullSubscribe(Aws::Crt::Allocator *allocator, void *)
17281738
{
1739+
ApiHandle apiHandle(allocator);
1740+
17291741
Mqtt5TestContext testContext = createTestContext(allocator, MQTT5CONNECT_DIRECT_IOT_CORE);
17301742
if (testContext.testDirective == AWS_OP_SKIP)
17311743
{
@@ -1757,6 +1769,8 @@ AWS_TEST_CASE(Mqtt5NullSubscribe, s_TestMqtt5NullSubscribe)
17571769
*/
17581770
static int s_TestMqtt5NullUnsubscribe(Aws::Crt::Allocator *allocator, void *)
17591771
{
1772+
ApiHandle apiHandle(allocator);
1773+
17601774
Mqtt5TestContext testContext = createTestContext(allocator, MQTT5CONNECT_DIRECT_IOT_CORE);
17611775
if (testContext.testDirective == AWS_OP_SKIP)
17621776
{
@@ -1821,6 +1835,8 @@ AWS_TEST_CASE(Mqtt5ReuseUnsubscribePacket, s_TestMqtt5ReuseUnsubscribePacket)
18211835
*/
18221836
static int s_TestMqtt5QoS1SubPub(Aws::Crt::Allocator *allocator, void *)
18231837
{
1838+
ApiHandle apiHandle(allocator);
1839+
18241840
const int MESSAGE_NUMBER = 10;
18251841
const String TEST_TOPIC = "test/s_TestMqtt5QoS1SubPub" + Aws::Crt::UUID().ToString();
18261842
std::vector<std::promise<void>> receivedMessages;
@@ -1923,6 +1939,7 @@ AWS_TEST_CASE(Mqtt5QoS1SubPub, s_TestMqtt5QoS1SubPub)
19231939
static int s_TestMqtt5RetainSetAndClear(Aws::Crt::Allocator *allocator, void *)
19241940
{
19251941
ApiHandle apiHandle(allocator);
1942+
19261943
const Aws::Crt::String TEST_TOPIC = "test/s_TestMqtt5RetainSetAndClear" + Aws::Crt::UUID().ToString();
19271944
const Aws::Crt::String RETAIN_MESSAGE = "This is a retained message";
19281945
std::promise<void> receivedRetainedMessage;
@@ -2527,14 +2544,15 @@ AWS_TEST_CASE(
25272544
*/
25282545
static int s_TestMqtt5to3AdapterDirectConnectionMinimalThroughMqtt5(Aws::Crt::Allocator *allocator, void *)
25292546
{
2547+
ApiHandle apiHandle(allocator);
2548+
25302549
Mqtt5TestEnvVars mqtt5TestVars(allocator, MQTT5CONNECT_DIRECT);
25312550
if (!mqtt5TestVars)
25322551
{
25332552
printf("Environment Variables are not set for the test, skip the test");
25342553
return AWS_OP_SKIP;
25352554
}
25362555

2537-
ApiHandle apiHandle(allocator);
25382556
Aws::Crt::Io::SocketOptions socketOptions;
25392557
socketOptions.SetConnectTimeoutMs(3000);
25402558
Mqtt5::Mqtt5ClientOptions mqtt5Options(allocator);
@@ -2636,15 +2654,15 @@ AWS_TEST_CASE(Mqtt5to3AdapterWithIoTConnectionThroughMqtt5, s_TestMqtt5to3Adapte
26362654
*/
26372655
static int s_TestMqtt5to3AdapterDirectConnectionWithMutualTLSThroughMqtt5(Aws::Crt::Allocator *allocator, void *)
26382656
{
2657+
ApiHandle apiHandle(allocator);
2658+
26392659
Mqtt5TestEnvVars mqtt5TestVars(allocator, MQTT5CONNECT_DIRECT_IOT_CORE);
26402660
if (!mqtt5TestVars)
26412661
{
26422662
printf("Environment Variables are not set for the test, skip the test");
26432663
return AWS_OP_SKIP;
26442664
}
26452665

2646-
ApiHandle apiHandle(allocator);
2647-
26482666
Mqtt5::Mqtt5ClientOptions mqtt5Options(allocator);
26492667
mqtt5Options.WithHostName(mqtt5TestVars.m_hostname_string);
26502668
mqtt5Options.WithPort(443);
@@ -2742,7 +2760,11 @@ static int s_TestMqtt5to3AdapterOperations(Aws::Crt::Allocator *allocator, void
27422760
testContext.stoppedPromise.get_future().get();
27432761

27442762
// no second publish
2745-
ASSERT_TRUE(received == 1);
2763+
{
2764+
std::lock_guard<std::mutex> lock(mutex);
2765+
ASSERT_TRUE(received == 1);
2766+
}
2767+
27462768
return AWS_OP_SUCCESS;
27472769
}
27482770
AWS_TEST_CASE(Mqtt5to3AdapterOperations, s_TestMqtt5to3AdapterOperations)
@@ -2867,14 +2889,19 @@ static int s_TestMqtt5to3AdapterMultipleAdapters(Aws::Crt::Allocator *allocator,
28672889
published.get_future().get();
28682890

28692891
// wait for message received
2870-
std::unique_lock<std::mutex> lock(mutex);
2871-
cv.wait(lock, [&received1, &received2]() { return received1 > 0 && received2 > 0; });
2892+
{
2893+
std::unique_lock<std::mutex> lock(mutex);
2894+
cv.wait(lock, [&received1, &received2]() { return received1 > 0 && received2 > 0; });
2895+
}
28722896

28732897
ASSERT_TRUE(mqtt5Client->Stop());
28742898
testContext.stoppedPromise.get_future().get();
28752899

2876-
ASSERT_TRUE(received1 == 1);
2877-
ASSERT_TRUE(received2 == 1);
2900+
{
2901+
std::lock_guard<std::mutex> lock(mutex);
2902+
ASSERT_TRUE(received1 == 1);
2903+
ASSERT_TRUE(received2 == 1);
2904+
}
28782905

28792906
return AWS_OP_SUCCESS;
28802907
}

0 commit comments

Comments
 (0)