Skip to content

Commit b346b78

Browse files
committed
Make unit tests pass without BMQ_ENABLE_MSG_GROUPID
The unit tests currently assume that message group IDs are enabled, and since have updated our build system to no longer enable this feature, the unit tests now fail in CI. This patch guards the message group ID tests with preprocessor conditionals, disabling the parts of tests that try to set and check message group IDs. When `BMQ_ENABLE_MSG_GROUPID` is set, these parts of the unit tests run again. Signed-off-by: Patrick M. Niedzielski <[email protected]>
1 parent a05d038 commit b346b78

File tree

5 files changed

+139
-3
lines changed

5 files changed

+139
-3
lines changed

src/groups/bmq/bmqimp/bmqimp_event.t.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,9 @@ static void test8_putEventBuilder()
10771077
bmqp::Crc32c::initialize();
10781078

10791079
bdlbb::PooledBlobBufferFactory bufferFactory(1024, s_allocator_p);
1080+
#ifdef BMQ_ENABLE_MSG_GROUPID
10801081
const bmqp::Protocol::MsgGroupId k_MSG_GROUP_ID("gid:0", s_allocator_p);
1082+
#endif
10811083
const int k_PROPERTY_VAL_ENCODING = 3;
10821084
const bsl::string k_PROPERTY_VAL_ID = "myCoolId";
10831085
const unsigned int k_CRC32 = 123;
@@ -1106,8 +1108,10 @@ static void test8_putEventBuilder()
11061108

11071109
builder.startMessage();
11081110
builder.setMessagePayload(k_PAYLOAD, k_PAYLOAD_LEN)
1109-
.setMessageProperties(&msgProps)
1110-
.setMsgGroupId(k_MSG_GROUP_ID);
1111+
.setMessageProperties(&msgProps);
1112+
#ifdef BMQ_ENABLE_MSG_GROUPID
1113+
builder.setMsgGroupId(k_MSG_GROUP_ID);
1114+
#endif
11111115

11121116
struct Test {
11131117
int d_line;
@@ -1149,8 +1153,10 @@ static void test8_putEventBuilder()
11491153
s_allocator_p,
11501154
bmqt::CompressionAlgorithmType::e_NONE);
11511155

1156+
#ifdef BMQ_ENABLE_MSG_GROUPID
11521157
ASSERT_EQ(builder.msgGroupId().isNull(), false);
11531158
ASSERT_EQ(builder.msgGroupId().value(), k_MSG_GROUP_ID);
1159+
#endif
11541160

11551161
ASSERT_EQ(builder.unpackedMessageSize(), k_PAYLOAD_LEN);
11561162

@@ -1232,11 +1238,13 @@ static void test8_putEventBuilder()
12321238
ASSERT_EQ(prop.getPropertyAsInt64("timestamp"), test.d_timeStamp);
12331239
}
12341240

1241+
#ifdef BMQ_ENABLE_MSG_GROUPID
12351242
bmqp::Protocol::MsgGroupId msgGroupId(s_allocator_p);
12361243
ASSERT_EQ(putIter.hasMsgGroupId(), true);
12371244
ASSERT_EQ(putIter.extractMsgGroupId(&msgGroupId), true);
12381245
ASSERT_EQ(msgGroupId, k_MSG_GROUP_ID);
12391246
ASSERT_EQ(putIter.isValid(), true);
1247+
#endif
12401248
}
12411249

12421250
ASSERT_EQ(true, putIter.isValid());

src/groups/bmq/bmqimp/bmqimp_messagedumper.t.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,14 @@ struct Tester BSLS_CPP11_FINAL {
228228
/// is undefined unless a queue with the `uri` was created and inserted
229229
/// using a call to `insertQueue`, or if packing the message is
230230
/// unsuccessful.
231+
#ifdef BMQ_ENABLE_MSG_GROUPID
231232
void packPutMessage(const bslstl::StringRef& uri,
232233
const bslstl::StringRef& payload,
233234
const bslstl::StringRef& msgGroupId = "");
235+
#else
236+
void packPutMessage(const bslstl::StringRef& uri,
237+
const bslstl::StringRef& payload);
238+
#endif
234239

235240
/// Append to the CONFIRM event being built a CONFIRM message associated
236241
/// with the queue corresponding to the specified `uri`. The behavior
@@ -460,9 +465,14 @@ void Tester::appendAckMessage(const bslstl::StringRef& uri,
460465
BSLS_ASSERT_OPT(rc == 0);
461466
}
462467

468+
#ifdef BMQ_ENABLE_MSG_GROUPID
463469
void Tester::packPutMessage(const bslstl::StringRef& uri,
464470
const bslstl::StringRef& payload,
465471
const bslstl::StringRef& msgGroupId)
472+
#else
473+
void Tester::packPutMessage(const bslstl::StringRef& uri,
474+
const bslstl::StringRef& payload)
475+
#endif
466476
{
467477
// PRECONDITIONS
468478
BSLS_ASSERT_OPT(d_queueIdsByUri.find(uri) != d_queueIdsByUri.end() &&
@@ -481,10 +491,12 @@ void Tester::packPutMessage(const bslstl::StringRef& uri,
481491

482492
d_putEventBuilder.startMessage();
483493
d_putEventBuilder.setMessageGUID(guid).setMessagePayload(&msgPayload);
494+
#ifdef BMQ_ENABLE_MSG_GROUPID
484495
if (!msgGroupId.empty()) {
485496
bmqp::Protocol::MsgGroupId groupId(msgGroupId, d_allocator_p);
486497
d_putEventBuilder.setMsgGroupId(msgGroupId);
487498
}
499+
#endif
488500

489501
int rc = d_putEventBuilder.packMessage(queueId.id());
490502
BSLS_ASSERT_OPT(rc == 0);
@@ -1659,8 +1671,13 @@ static void test8_dumpPutEvent()
16591671
// messages.
16601672
tester.processDumpCommand("PUT ON");
16611673

1674+
#ifdef BMQ_ENABLE_MSG_GROUPID
16621675
tester.packPutMessage("bmq://bmq.test.mmap.fanout/q1", "abcd", "Group 1");
16631676
tester.packPutMessage("bmq://bmq.test.mmap.fanout/q1", "abcd", "Group 2");
1677+
#else
1678+
tester.packPutMessage("bmq://bmq.test.mmap.fanout/q1", "abcd");
1679+
tester.packPutMessage("bmq://bmq.test.mmap.fanout/q1", "abcd");
1680+
#endif
16641681
tester.packPutMessage("bmq://bmq.test.mmap.priority/q1", "efgh");
16651682
tester.packPutMessage("bmq://bmq.test.mmap.priority/q2", "ijkl");
16661683

@@ -1674,6 +1691,7 @@ static void test8_dumpPutEvent()
16741691

16751692
PVV(L_ << ": PUT event dump: " << out.str());
16761693

1694+
#ifdef BMQ_ENABLE_MSG_GROUPID
16771695
ASSERT_EQ(regexMatch(out.str(),
16781696
"PUT Message #1:.*"
16791697
"queue: bmq://bmq.test.mmap.fanout/q1.*"
@@ -1688,6 +1706,20 @@ static void test8_dumpPutEvent()
16881706
"abcd.*",
16891707
s_allocator_p),
16901708
true);
1709+
#else
1710+
ASSERT_EQ(regexMatch(out.str(),
1711+
"PUT Message #1:.*"
1712+
"queue: bmq://bmq.test.mmap.fanout/q1.*"
1713+
"abcd.*",
1714+
s_allocator_p),
1715+
true);
1716+
ASSERT_EQ(regexMatch(out.str(),
1717+
"PUT Message #2:.*"
1718+
"queue: bmq://bmq.test.mmap.fanout/q1.*"
1719+
"abcd.*",
1720+
s_allocator_p),
1721+
true);
1722+
#endif
16911723
ASSERT_EQ(regexMatch(out.str(),
16921724
"PUT Message #3:.*"
16931725
"queue: bmq://bmq.test.mmap.priority/q1.*"

src/groups/bmq/bmqp/bmqp_optionutil.t.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ static void test3_checkOptionsBlobSegment()
388388
}
389389
}
390390

391+
#ifdef BMQ_ENABLE_MSG_GROUPID
391392
static void test4_isValidMsgGroupId()
392393
// ------------------------------------------------------------------------
393394
// VALIDATE GROUPID LENGTH
@@ -426,6 +427,7 @@ static void test4_isValidMsgGroupId()
426427
ASSERT_EQ(Result::e_SUCCESS,
427428
bmqp::OptionUtil::isValidMsgGroupId(maxLength));
428429
}
430+
#endif
429431

430432
// ============================================================================
431433
// MAIN PROGRAM
@@ -439,7 +441,9 @@ int main(int argc, char* argv[])
439441

440442
switch (_testCase) {
441443
case 0:
444+
#ifdef BMQ_ENABLE_MSG_GROUPID
442445
case 4: test4_isValidMsgGroupId(); break;
446+
#endif
443447
case 3: test3_checkOptionsBlobSegment(); break;
444448
case 2: test2_basicOptionsBoxCanAdd(); break;
445449
case 1: test1_basicOptionMetaProperties(); break;

src/groups/bmq/bmqp/bmqp_pusheventbuilder.t.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,17 @@ using namespace bsl;
5858
// ----------------------------------------------------------------------------
5959
namespace {
6060

61+
#ifdef BMQ_ENABLE_MSG_GROUPID
6162
typedef bdlb::NullableValue<bmqp::Protocol::MsgGroupId> NullableMsgGroupId;
63+
#endif
6264

6365
struct Data {
6466
bmqt::MessageGUID d_guid;
6567
int d_qid;
6668
bmqp::Protocol::SubQueueInfosArray d_subQueueInfos;
69+
#ifdef BMQ_ENABLE_MSG_GROUPID
6770
NullableMsgGroupId d_msgGroupId;
71+
#endif
6872
bdlbb::Blob d_payload;
6973
int d_flags;
7074
bmqt::CompressionAlgorithmType::Enum d_compressionAlgorithmType;
@@ -82,7 +86,9 @@ Data::Data(bdlbb::BlobBufferFactory* bufferFactory,
8286
bslma::Allocator* allocator)
8387
: d_qid(-1)
8488
, d_subQueueInfos(allocator)
89+
#ifdef BMQ_ENABLE_MSG_GROUPID
8590
, d_msgGroupId(allocator)
91+
#endif
8692
, d_payload(bufferFactory, allocator)
8793
, d_flags(0)
8894
, d_compressionAlgorithmType(bmqt::CompressionAlgorithmType::e_NONE)
@@ -94,7 +100,9 @@ Data::Data(const Data& other, bslma::Allocator* allocator)
94100
: d_guid(other.d_guid)
95101
, d_qid(other.d_qid)
96102
, d_subQueueInfos(other.d_subQueueInfos, allocator)
103+
#ifdef BMQ_ENABLE_MSG_GROUPID
97104
, d_msgGroupId(other.d_msgGroupId, allocator)
105+
#endif
98106
, d_payload(other.d_payload, allocator)
99107
, d_flags(other.d_flags)
100108
, d_compressionAlgorithmType(other.d_compressionAlgorithmType)
@@ -142,6 +150,7 @@ void generateSubQueueInfos(bmqp::Protocol::SubQueueInfosArray* subQueueInfos,
142150
static_cast<unsigned int>(numSubQueueInfos));
143151
}
144152

153+
#ifdef BMQ_ENABLE_MSG_GROUPID
145154
/// Populate the specified `msgGroupId` with a random Group Id.
146155
static void generateMsgGroupId(bmqp::Protocol::MsgGroupId* msgGroupId)
147156
{
@@ -152,6 +161,7 @@ static void generateMsgGroupId(bmqp::Protocol::MsgGroupId* msgGroupId)
152161
oss << "gid:" << generateRandomInteger(0, 120);
153162
*msgGroupId = oss.str();
154163
}
164+
#endif
155165

156166
/// Append at least `atLeastLen` bytes to the specified `blob` and populate
157167
/// the specified `payloadLen` with the number of bytes appended.
@@ -200,6 +210,7 @@ appendMessage(size_t iteration,
200210
return rc; // RETURN
201211
}
202212

213+
#ifdef BMQ_ENABLE_MSG_GROUPID
203214
// Every 3rd iteration we don't add a Group Id.
204215
if (iteration % 3) {
205216
generateMsgGroupId(&data.d_msgGroupId.makeValue());
@@ -208,11 +219,14 @@ appendMessage(size_t iteration,
208219
return rc; // RETURN
209220
}
210221
}
222+
#endif
211223

212224
bdlbb::Blob payload(bufferFactory, allocator);
213225
const int blobSize = generateRandomInteger(0, 1024);
226+
#ifdef BMQ_ENABLE_MSG_GROUPID
214227
const bmqp::Protocol::MsgGroupId str(blobSize, 'x', allocator);
215228
bdlbb::BlobUtil::append(&payload, str.c_str(), blobSize);
229+
#endif
216230

217231
data.d_payload = payload;
218232

@@ -651,6 +665,7 @@ static void test4_buildEventWithMultipleMessages()
651665
ASSERT_EQ_D(i, D.d_subQueueInfos[i], retrievedSQInfos[i]);
652666
}
653667
}
668+
#ifdef BMQ_ENABLE_MSG_GROUPID
654669
const bool hasMsgGroupId = !D.d_msgGroupId.isNull();
655670
ASSERT_EQ(hasMsgGroupId,
656671
optionsView.find(bmqp::OptionType::e_MSG_GROUP_ID) !=
@@ -661,6 +676,7 @@ static void test4_buildEventWithMultipleMessages()
661676
optionsView.loadMsgGroupIdOption(&retrievedMsgGroupId));
662677
ASSERT_EQ(D.d_msgGroupId.value(), retrievedMsgGroupId);
663678
}
679+
#endif
664680
++dataIndex;
665681
}
666682

@@ -900,6 +916,7 @@ static void test7_buildEventOptionTooBig()
900916

901917
ASSERT_EQ(rc, bmqt::EventBuilderResult::e_OPTION_TOO_BIG);
902918

919+
#ifdef BMQ_ENABLE_MSG_GROUPID
903920
// Add another option larger than maximum allowed
904921
bmqp::Protocol::MsgGroupId msgGrIdBig1(bmqp::OptionHeader::k_MAX_SIZE + 1,
905922
'x',
@@ -916,7 +933,6 @@ static void test7_buildEventOptionTooBig()
916933

917934
rc = peb.addMsgGroupIdOption(msgGrIdBig2);
918935

919-
#ifdef BMQ_ENABLE_MSG_GROUPID
920936
ASSERT_EQ(rc, bmqt::EventBuilderResult::e_INVALID_MSG_GROUP_ID);
921937
#endif
922938

0 commit comments

Comments
 (0)