Commit 0cc6610a15ac9dc8d0b3b8988806e609213e1a2d
1 parent
2677a728
Stablized test_retained_tree
It was flakey. I also ported it to the new test client.
Showing
1 changed file
with
32 additions
and
18 deletions
FlashMQTests/tst_maintests.cpp
| @@ -489,33 +489,47 @@ void MainTests::test_retained_removed() | @@ -489,33 +489,47 @@ void MainTests::test_retained_removed() | ||
| 489 | */ | 489 | */ |
| 490 | void MainTests::test_retained_tree() | 490 | void MainTests::test_retained_tree() |
| 491 | { | 491 | { |
| 492 | - TwoClientTestContext testContext; | 492 | + FlashMQTestClient sender; |
| 493 | + sender.start(); | ||
| 493 | 494 | ||
| 494 | - QByteArray payload = "We are testing"; | ||
| 495 | - const QString topic1 = "TopicA/B"; | ||
| 496 | - const QString topic2 = "Topic/C"; | ||
| 497 | - const QString topic3 = "TopicB/C"; | ||
| 498 | - const QStringList topics {topic1, topic2, topic3}; | 495 | + std::string payload = "We are testing"; |
| 496 | + const std::string topic1 = "TopicA/B"; | ||
| 497 | + const std::string topic2 = "Topic/C"; | ||
| 498 | + const std::string topic3 = "TopicB/C"; | ||
| 499 | + const std::list<std::string> topics {topic1, topic2, topic3}; | ||
| 499 | 500 | ||
| 500 | - testContext.connectSender(); | ||
| 501 | - testContext.publish(topic1, payload, true); | ||
| 502 | - testContext.publish(topic2, payload, true); | ||
| 503 | - testContext.publish(topic3, payload, true); | 501 | + sender.connectClient(ProtocolVersion::Mqtt311); |
| 504 | 502 | ||
| 505 | - testContext.connectReceiver(); | ||
| 506 | - testContext.subscribeReceiver("+/+"); | ||
| 507 | - testContext.waitReceiverReceived(1); | 503 | + Publish p1(topic1, payload, 0); |
| 504 | + p1.retain = true; | ||
| 505 | + sender.publish(p1); | ||
| 506 | + | ||
| 507 | + Publish p2(topic2, payload, 0); | ||
| 508 | + p2.retain = true; | ||
| 509 | + sender.publish(p2); | ||
| 510 | + | ||
| 511 | + Publish p3(topic3, payload, 0); | ||
| 512 | + p3.retain = true; | ||
| 513 | + sender.publish(p3); | ||
| 514 | + | ||
| 515 | + FlashMQTestClient receiver; | ||
| 516 | + receiver.start(); | ||
| 517 | + receiver.connectClient(ProtocolVersion::Mqtt5); | ||
| 518 | + | ||
| 519 | + receiver.subscribe("+/+", 0); | ||
| 520 | + | ||
| 521 | + receiver.waitForMessageCount(3); | ||
| 508 | 522 | ||
| 509 | - QCOMPARE(testContext.receivedMessages.count(), topics.count()); | 523 | + QCOMPARE(receiver.receivedPublishes.size(), topics.size()); |
| 510 | 524 | ||
| 511 | - for (const QString &s : topics) | 525 | + for (const std::string &s : topics) |
| 512 | { | 526 | { |
| 513 | - bool r = std::any_of(testContext.receivedMessages.begin(), testContext.receivedMessages.end(), [&](QMQTT::Message &msg) | 527 | + bool r = std::any_of(receiver.receivedPublishes.begin(), receiver.receivedPublishes.end(), [&](MqttPacket &pack) |
| 514 | { | 528 | { |
| 515 | - return msg.topic() == s && msg.payload() == payload; | 529 | + return pack.getTopic() == s && pack.getPayloadCopy() == payload; |
| 516 | }); | 530 | }); |
| 517 | 531 | ||
| 518 | - QVERIFY2(r, formatString("%s not found in retained messages.", s.toStdString().c_str()).c_str()); | 532 | + QVERIFY2(r, formatString("%s not found in retained messages.", s.c_str()).c_str()); |
| 519 | } | 533 | } |
| 520 | 534 | ||
| 521 | } | 535 | } |