Skip to content

Commit

Permalink
remove debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazhvera committed Nov 28, 2023
1 parent 2a05556 commit a1be80f
Showing 1 changed file with 26 additions and 43 deletions.
69 changes: 26 additions & 43 deletions bin/mqtt5_canary/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <aws/common/command_line_parser.h>
#include <aws/common/mutex.h>
#include <condition_variable>
#include <inttypes.h>
#include <ctime>
#include <inttypes.h>
#include <iostream>

#define AWS_MQTT5_CANARY_CLIENT_CREATION_SLEEP_TIME 10000000
Expand Down Expand Up @@ -365,7 +365,6 @@ static int s_AwsMqtt5CanaryOperationStart(struct AwsMqtt5CanaryTestClient *testC
{
if (testClient->isConnected)
{
fprintf(stderr, "%ju: ID:%s already started", std::time(0), testClient->clientId.c_str());
return AWS_OP_SUCCESS;
}

Expand All @@ -389,10 +388,9 @@ static int s_AwsMqtt5CanaryOperationStart(struct AwsMqtt5CanaryTestClient *testC
// If the connection operation failed eventually, "withClientConnectionFailureCallback"
// will set the flag to false.
testClient->isConnected = true;
fprintf(stderr, "%ju: ID:%s client started ... \n", std::time(0), testClient->clientId.c_str());
return AWS_OP_SUCCESS;
}
fprintf(stderr, "%ju: ID:%s client start failed \n", std::time(0), testClient->clientId.c_str());
AWS_LOGF_ERROR(AWS_LS_MQTT5_CANARY, "ID:%s Start Failed", testClient->clientId.c_str());
return AWS_OP_ERR;
}

Expand All @@ -418,7 +416,12 @@ OnSubscribeCompletionHandler subscribe_completion = [](int errorcode, std::share
if (errorcode != 0)
{
++g_statistic.subscribe_failed;
fprintf(stderr, "%ju: Subscribe failed with errorcode: %d, %s\n", std::time(0), errorcode, aws_error_str(errorcode));
fprintf(
stderr,
"%ju: Subscribe failed with errorcode: %d, %s\n",
std::time(0),
errorcode,
aws_error_str(errorcode));
return;
}
++g_statistic.subscribe_succeed;
Expand Down Expand Up @@ -456,12 +459,14 @@ static int s_AwsMqtt5CanaryOperationSubscribe(struct AwsMqtt5CanaryTestClient *t

++g_statistic.totalOperations;
++g_statistic.subscribe_attempt;
AWS_LOGF_INFO(AWS_LS_MQTT5_CANARY, "ID:%s Subscribe to topic: %s", testClient->clientId.c_str(), topicArray);

if (testClient->client->Subscribe(packet, subscribe_completion))
{
return AWS_OP_SUCCESS;
}
++g_statistic.subscribe_failed;
fprintf(stderr, "%ju: ID:%s Subscribe Failed\n", std::time(0), testClient->clientId.c_str());
AWS_LOGF_ERROR(AWS_LS_MQTT5_CANARY, "ID:%s Subscribe Failed", testClient->clientId.c_str());
return AWS_OP_ERR;
}

Expand Down Expand Up @@ -490,10 +495,11 @@ static int s_AwsMqtt5CanaryOperationUnsubscribeBad(struct AwsMqtt5CanaryTestClie
if (packet->getReasonCodes()[0] == AWS_MQTT5_UARC_SUCCESS)
{
++g_statistic.unsub_succeed;
fprintf(
stderr,
AWS_LOGF_ERROR(
AWS_LS_MQTT5_CANARY,
"%ju: ID:%s Unsubscribe Bad Server Failed with errorcode : %s\n",
std::time(0), testClient->clientId.c_str(),
std::time(0),
testClient->clientId.c_str(),
packet->getReasonString()->c_str());
}
}))
Expand Down Expand Up @@ -543,16 +549,6 @@ static int s_AwsMqtt5CanaryOperationUnsubscribe(struct AwsMqtt5CanaryTestClient
return AWS_OP_ERR;
}

OnPublishCompletionHandler publish_completion = [](int errorcode, std::shared_ptr<PublishResult>) {
if (errorcode != 0)
{
++g_statistic.publish_failed;
fprintf(stderr, "%ju: ID: Publish failed with errorcode: %d, %s\n", std::time(0), errorcode, aws_error_str(errorcode));
return;
}
++g_statistic.publish_succeed;
};

/* Help function for Publish Operation. Do not call it directly for operations. */
static int s_AwsMqtt5CanaryOperationPublish(
struct AwsMqtt5CanaryTestClient *testClient,
Expand All @@ -579,7 +575,7 @@ static int s_AwsMqtt5CanaryOperationPublish(
uint8_t payload_data[AWS_MQTT5_CANARY_PAYLOAD_SIZE_MAX];
for (i = 0; i < payload_size; i++)
{
payload_data[i] = 'a';
payload_data[i] = rand() % 128 + 1;
}
ByteCursor payload = ByteCursorFromArray(payload_data, payload_size);

Expand All @@ -594,12 +590,17 @@ static int s_AwsMqtt5CanaryOperationPublish(

++g_statistic.totalOperations;
++g_statistic.publish_attempt;
const char * client_id = testClient->clientId.c_str();
const char *client_id = testClient->clientId.c_str();
if (testClient->client->Publish(packetPublish, [client_id](int errorcode, std::shared_ptr<PublishResult> packet) {
if (errorcode != 0)
{
++g_statistic.publish_failed;
fprintf(stderr, "%ju: ID: %s Publish failed with errorcode: %d, %s\n", std::time(0), client_id, errorcode, aws_error_str(errorcode));
AWS_LOGF_INFO(
AWS_LS_MQTT5_CANARY,
"ID: %s Publish failed with errorcode: %d, %s\n",
client_id,
errorcode,
aws_error_str(errorcode));
return;
}
++g_statistic.publish_succeed;
Expand All @@ -610,7 +611,7 @@ static int s_AwsMqtt5CanaryOperationPublish(
return AWS_OP_SUCCESS;
}
++g_statistic.publish_failed;
fprintf(stderr, "%ju: ID:%s Publish Failed\n", std::time(0), testClient->clientId.c_str());
AWS_LOGF_INFO(AWS_LS_MQTT5_CANARY, "ID:%s Publish Failed\n", testClient->clientId.c_str());
return AWS_OP_ERR;
}

Expand Down Expand Up @@ -941,7 +942,6 @@ int main(int argc, char **argv)
eventData.negotiatedSettings->getClientId().length());
clients[i].settings = eventData.negotiatedSettings;

fprintf(stderr, "%ju: ID:%s client Connection Success \n", std::time(0), clients[i].clientId.c_str());
AWS_LOGF_INFO(
AWS_LS_MQTT5_CANARY, "ID:%s Lifecycle Event: Connection Success", clients[i].clientId.c_str());
});
Expand All @@ -955,32 +955,15 @@ int main(int argc, char **argv)
clients[i].clientId.c_str(),
eventData.errorCode,
aws_error_debug_str(eventData.errorCode));

fprintf(
stderr,
"%ju: ID:%s client Connection failed with error code %d(%s)\n",
std::time(0), clients[i].clientId.c_str(),
eventData.errorCode,
aws_error_debug_str(eventData.errorCode));
});

mqtt5Options.WithClientDisconnectionCallback([&clients, i](const OnDisconnectionEventData &eventdata) {
clients[i].isConnected = false;
fprintf(
stderr,
"%ju: ID:%s client Disconnected with error code %d(%s)\n",
std::time(0), clients[i].clientId.c_str(),
eventdata.errorCode,
aws_error_debug_str(eventdata.errorCode));
AWS_LOGF_INFO(AWS_LS_MQTT5_CANARY, "ID:%s Lifecycle Event: Disconnect", clients[i].clientId.c_str());
});

mqtt5Options.WithClientStoppedCallback([&clients, i](const OnStoppedEventData &) {
clients[i].isConnected = false;
fprintf(
stderr,
"%ju: ID:%s client Stopped.\n",
std::time(0), clients[i].clientId.c_str());
AWS_LOGF_INFO(AWS_LS_MQTT5_CANARY, "ID:%s Lifecycle Event: Stopped", clients[i].clientId.c_str());
});

Expand All @@ -995,13 +978,13 @@ int main(int argc, char **argv)
s_AwsMqtt5CanaryOperationTable.operationByOperationType[AWS_MQTT5_CANARY_OPERATION_START];
if ((*operation_fn)(&clients[i], appCtx.allocator) == AWS_OP_ERR)
{
fprintf(stderr, "ID:%s Operation Failed.", client.clientId.c_str());
AWS_LOGF_ERROR(AWS_LS_MQTT5_CANARY, "ID:%s Operation Failed.", client.clientId.c_str());
}

aws_thread_current_sleep(AWS_MQTT5_CANARY_CLIENT_CREATION_SLEEP_TIME);
}

printf("Clients created\n");
fprintf(stderr, "Clients created\n");

/**********************************************************
* TESTING
Expand Down

0 comments on commit a1be80f

Please sign in to comment.