Skip to content

Commit

Permalink
Fix some test memory leaks, code convention, msvc warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhill committed Jan 25, 2021
1 parent 7d5ae63 commit 7fe18e4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
6 changes: 3 additions & 3 deletions tests/0105-transactions_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static void do_test_txn_recoverable_errors (void) {
*/
static void do_test_txn_endtxn_errors (void) {
rd_kafka_t *rk = NULL;
rd_kafka_mock_cluster_t *mcluster;
rd_kafka_mock_cluster_t *mcluster = NULL;
rd_kafka_resp_err_t err;
struct {
size_t error_cnt;
Expand Down Expand Up @@ -519,7 +519,7 @@ static void do_test_txn_endtxn_errors (void) {
*/
static void do_test_txn_endtxn_infinite (void) {
rd_kafka_t *rk;
rd_kafka_mock_cluster_t *mcluster;
rd_kafka_mock_cluster_t *mcluster = NULL;
const char *txnid = "myTxnId";
int i;

Expand Down Expand Up @@ -598,7 +598,7 @@ static void do_test_txn_endtxn_infinite (void) {
*/
static void do_test_txn_endtxn_timeout (void) {
rd_kafka_t *rk;
rd_kafka_mock_cluster_t *mcluster;
rd_kafka_mock_cluster_t *mcluster = NULL;
const char *txnid = "myTxnId";
int i;

Expand Down
4 changes: 4 additions & 0 deletions tests/0113-cooperative_rebalance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ class DefaultRebalanceCb : public RdKafka::RebalanceCb {
int64_t ts_last_assign; /**< Timestamp of last rebalance assignment */
map<Toppar,int> msg_cnt; /**< Number of consumed messages per partition. */

~DefaultRebalanceCb () {
reset_msg_cnt();
}

DefaultRebalanceCb ():
assign_call_cnt(0),
revoke_call_cnt(0),
Expand Down
36 changes: 20 additions & 16 deletions tests/0114-sticky_partitioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@
* messages to verify it takes effect.
*/
static void do_test_sticky_partitioning (int sticky_delay) {

std::string topic = Test::mk_topic_name(__FILE__, 1);
Test::create_topic(NULL, topic.c_str(), 3, 1);

RdKafka::Conf *conf;
Test::conf_init(&conf, NULL, 0);

Test::conf_set(conf, "sticky.partitioning.linger.ms", tostr() << sticky_delay);
Test::conf_set(conf, "sticky.partitioning.linger.ms",
tostr() << sticky_delay);

std::string errstr;
RdKafka::Producer *p = RdKafka::Producer::create(conf, errstr);
Expand All @@ -60,6 +61,7 @@ static void do_test_sticky_partitioning (int sticky_delay) {
RdKafka::Consumer *c = RdKafka::Consumer::create(conf, errstr);
if (!c)
Test::Fail("Failed to create Consumer: " + errstr);
delete conf;

RdKafka::Topic *t = RdKafka::Topic::create(c, topic, NULL, errstr);
if (!t)
Expand Down Expand Up @@ -131,41 +133,43 @@ static void do_test_sticky_partitioning (int sticky_delay) {

for(int i = 0; i < 3; i++){

/* Partitions must receive 100+ messages to be deemed 'active'. This
* is because while topics are being updated, it is possible for some
* number of messages to be partitioned to joining partitions before
* they become available. This can cause some initial turnover in
* selecting a sticky partition. This behavior is acceptable, and is
* not important for the purpose of this segment of the test. */
/* Partitions must receive 100+ messages to be deemed 'active'. This
* is because while topics are being updated, it is possible for some
* number of messages to be partitioned to joining partitions before
* they become available. This can cause some initial turnover in
* selecting a sticky partition. This behavior is acceptable, and is
* not important for the purpose of this segment of the test. */

if(partition_msgcnt[i] > (msgrate - 1)) num_partitions_active++;
if (partition_msgcnt[i] > (msgrate - 1))
num_partitions_active++;
}

Test::Say("Partition Message Count: \n");
for(int i = 0; i < 3; i++){
Test::Say(tostr() << " " << i << ": " <<
Test::Say(tostr() << " " << i << ": " <<
partition_msgcnt[i] << "\n");
}

/* When sticky.partitioning.linger.ms is long (greater than expected
* length of run), one partition should be sticky and receive messages. */
if (sticky_delay == 5000 &&
num_partitions_active > 1)
Test::Fail(tostr()
<< "Expected only 1 partition to receive msgs"
<< " but " << num_partitions_active
Test::Fail(tostr()
<< "Expected only 1 partition to receive msgs"
<< " but " << num_partitions_active
<< " partitions received msgs.");
/* When sticky.partitioning.linger.ms is short (sufficiently smaller than

/* When sticky.partitioning.linger.ms is short (sufficiently smaller than
* length of run), it is extremely likely that all partitions are sticky
* at least once and receive messages. */
if (sticky_delay == 1000 &&
num_partitions_active <= 1)
Test::Fail(tostr()
Test::Fail(tostr()
<< "Expected more than one partition to receive msgs"
<< " but only " << num_partitions_active
<< " partition received msgs.");

delete t;
delete p;
delete c;
}
Expand Down

0 comments on commit 7fe18e4

Please sign in to comment.