From b970c2d159ee2cf308be2d9d6a67f4bcb8b81c29 Mon Sep 17 00:00:00 2001
From: Vera Xia <zhvxia@amazon.com>
Date: Mon, 11 Apr 2022 09:53:16 -0700
Subject: [PATCH] use a random id for client id to prevent conflicts between
 tests

---
 .../IntegrationTestAutoReconnectResubscribe.py            | 6 ++++--
 .../IntegrationTestConfigurablePublishMessageQueueing.py  | 6 ++++--
 .../IntegrationTests/IntegrationTestJobsClient.py         | 3 ++-
 .../IntegrationTests/IntegrationTestMQTTConnection.py     | 8 ++++++--
 ...tegrationTestOfflineQueueingForSubscribeUnsubscribe.py | 4 ++--
 .../IntegrationTests/IntegrationTestProgressiveBackoff.py | 6 ++++--
 .../IntegrationTests/IntegrationTestShadow.py             | 6 ++++--
 7 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/test-integration/IntegrationTests/IntegrationTestAutoReconnectResubscribe.py b/test-integration/IntegrationTests/IntegrationTestAutoReconnectResubscribe.py
index 1ee251a..83b66c2 100644
--- a/test-integration/IntegrationTests/IntegrationTestAutoReconnectResubscribe.py
+++ b/test-integration/IntegrationTests/IntegrationTestAutoReconnectResubscribe.py
@@ -30,6 +30,8 @@
 from TestToolLibrary.skip import Python2VersionLowerThan
 from TestToolLibrary.skip import Python3VersionLowerThan
 
+CLIENT_ID_PUB = "integrationTestMQTT_ClientPub" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
+CLIENT_ID_SUB = "integrationTestMQTT_ClientSub" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
 
 # Callback unit
 class callbackUnit:
@@ -148,9 +150,9 @@ def threadBRuntime(self, pyCoreClient, callback):
 
 # Init Python core and connect
 myMQTTClientManager = MQTTClientManager.MQTTClientManager()
-clientPub = myMQTTClientManager.create_connected_mqtt_core("integrationTestMQTT_ClientPub", host, rootCA,
+clientPub = myMQTTClientManager.create_connected_mqtt_core(CLIENT_ID_PUB, host, rootCA,
                                                            certificate, privateKey, mode=mode)
-clientSub = myMQTTClientManager.create_connected_mqtt_core("integrationTestMQTT_ClientSub", host, rootCA,
+clientSub = myMQTTClientManager.create_connected_mqtt_core(CLIENT_ID_SUB, host, rootCA,
                                                            certificate, privateKey, mode=mode)
 
 if clientPub is None or clientSub is None:
diff --git a/test-integration/IntegrationTests/IntegrationTestConfigurablePublishMessageQueueing.py b/test-integration/IntegrationTests/IntegrationTestConfigurablePublishMessageQueueing.py
index 705df53..d6bfdc5 100644
--- a/test-integration/IntegrationTests/IntegrationTestConfigurablePublishMessageQueueing.py
+++ b/test-integration/IntegrationTests/IntegrationTestConfigurablePublishMessageQueueing.py
@@ -38,6 +38,8 @@
 from TestToolLibrary.skip import Python2VersionLowerThan
 from TestToolLibrary.skip import Python3VersionLowerThan
 
+CLIENT_ID_PUB = "integrationTestMQTT_ClientPub" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
+CLIENT_ID_SUB = "integrationTestMQTT_ClientSub" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
 
 # Class that implements the publishing thread: Thread A, with network failure
 # This thread will publish 3 messages first, and then keep publishing
@@ -287,9 +289,9 @@ def performConfigurableOfflinePublishQueueTest(clientPub, clientSub):
 
 # Init Python core and connect
 myMQTTClientManager = MQTTClientManager.MQTTClientManager()
-clientPub = myMQTTClientManager.create_connected_mqtt_core("integrationTestMQTT_ClientPub", host, rootCA,
+clientPub = myMQTTClientManager.create_connected_mqtt_core(CLIENT_ID_PUB, host, rootCA,
                                                            certificate, privateKey, mode=mode)
-clientSub = myMQTTClientManager.create_connected_mqtt_core("integrationTestMQTT_ClientSub", host, rootCA,
+clientSub = myMQTTClientManager.create_connected_mqtt_core(CLIENT_ID_SUB, host, rootCA,
                                                            certificate, privateKey, mode=mode)
 
 if clientPub is None or clientSub is None:
diff --git a/test-integration/IntegrationTests/IntegrationTestJobsClient.py b/test-integration/IntegrationTests/IntegrationTestJobsClient.py
index 9eb5690..18d8aa5 100644
--- a/test-integration/IntegrationTests/IntegrationTestJobsClient.py
+++ b/test-integration/IntegrationTests/IntegrationTestJobsClient.py
@@ -37,6 +37,7 @@
 import json
 
 IOT_JOBS_MQTT_RESPONSE_WAIT_SECONDS = 5
+CLIENT_ID = "integrationTestMQTT_Client" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
 
 class JobsMessageProcessor(object):
     def __init__(self, awsIoTMQTTThingJobsClient, clientToken):
@@ -168,7 +169,7 @@ def _test_send_response_confirm(self, sendResult):
 
 # Init Python core and connect
 myMQTTClientManager = MQTTClientManager.MQTTClientManager()
-client = myMQTTClientManager.create_connected_mqtt_client(mode, "integrationTestJobs_Client", host, (rootCA, certificate, privateKey))
+client = myMQTTClientManager.create_connected_mqtt_client(mode, CLIENT_ID, host, (rootCA, certificate, privateKey))
 
 clientId = 'AWSPythonkSDKTestThingClient'
 thingName = 'AWSPythonkSDKTestThing'
diff --git a/test-integration/IntegrationTests/IntegrationTestMQTTConnection.py b/test-integration/IntegrationTests/IntegrationTestMQTTConnection.py
index 9deb10e..252770f 100644
--- a/test-integration/IntegrationTests/IntegrationTestMQTTConnection.py
+++ b/test-integration/IntegrationTests/IntegrationTestMQTTConnection.py
@@ -30,6 +30,10 @@
 API_TYPE_SYNC = "sync"
 API_TYPE_ASYNC = "async"
 
+CLIENT_ID_PUB = "integrationTestMQTT_ClientPub" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
+CLIENT_ID_SUB = "integrationTestMQTT_ClientSub" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
+
+
 
 # Callback unit for subscribe
 class callbackUnit:
@@ -95,9 +99,9 @@ def _performPublish(self, pyCoreClient, topic, qos, payload):
 
 # Init Python core and connect
 myMQTTClientManager = MQTTClientManager.MQTTClientManager()
-clientPub = myMQTTClientManager.create_connected_mqtt_core("integrationTestMQTT_ClientPub", host, rootCA,
+clientPub = myMQTTClientManager.create_connected_mqtt_core(CLIENT_ID_PUB, host, rootCA,
                                                            certificate, privateKey, mode=mode)
-clientSub = myMQTTClientManager.create_connected_mqtt_core("integrationTestMQTT_ClientSub", host, rootCA,
+clientSub = myMQTTClientManager.create_connected_mqtt_core(CLIENT_ID_SUB, host, rootCA,
                                                            certificate, privateKey, mode=mode)
 
 if clientPub is None or clientSub is None:
diff --git a/test-integration/IntegrationTests/IntegrationTestOfflineQueueingForSubscribeUnsubscribe.py b/test-integration/IntegrationTests/IntegrationTestOfflineQueueingForSubscribeUnsubscribe.py
index 7e382b1..c06847d 100644
--- a/test-integration/IntegrationTests/IntegrationTestOfflineQueueingForSubscribeUnsubscribe.py
+++ b/test-integration/IntegrationTests/IntegrationTestOfflineQueueingForSubscribeUnsubscribe.py
@@ -51,8 +51,8 @@ def get_random_string(length):
 ROOT_CA = "./test-integration/Credentials/rootCA.crt"
 CERT = "./test-integration/Credentials/certificate.pem.crt"
 KEY = "./test-integration/Credentials/privateKey.pem.key"
-CLIENT_PUB_ID = "PySdkIntegTest_OfflineSubUnsub_pub"
-CLIENT_SUB_UNSUB_ID = "PySdkIntegTest_OfflineSubUnsub_subunsub"
+CLIENT_PUB_ID = "PySdkIntegTest_OfflineSubUnsub_pub" + get_random_string(4)
+CLIENT_SUB_UNSUB_ID = "PySdkIntegTest_OfflineSubUnsub_subunsub" + get_random_string(4)
 KEEP_ALIVE_SEC = 1
 EVENT_WAIT_TIME_OUT_SEC = 5
 
diff --git a/test-integration/IntegrationTests/IntegrationTestProgressiveBackoff.py b/test-integration/IntegrationTests/IntegrationTestProgressiveBackoff.py
index 9d57275..cd7b7ec 100644
--- a/test-integration/IntegrationTests/IntegrationTestProgressiveBackoff.py
+++ b/test-integration/IntegrationTests/IntegrationTestProgressiveBackoff.py
@@ -43,6 +43,8 @@
 from TestToolLibrary.skip import Python2VersionLowerThan
 from TestToolLibrary.skip import Python3VersionLowerThan
 
+CLIENT_ID_PUB = "integrationTestMQTT_ClientPub" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
+CLIENT_ID_SUB = "integrationTestMQTT_ClientSub" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
 
 # Class that implements all the related threads in the test in a controllable manner
 class threadPool:
@@ -234,9 +236,9 @@ def verifyBackoffTime(answerList, resultList):
 
 # Init Python core and connect
 myMQTTClientManager = MQTTClientManager.MQTTClientManager()
-clientPub = myMQTTClientManager.create_connected_mqtt_core("integrationTestMQTT_ClientPub", host, rootCA,
+clientPub = myMQTTClientManager.create_connected_mqtt_core(CLIENT_ID_PUB, host, rootCA,
                                                            certificate, privateKey, mode=mode)
-clientSub = myMQTTClientManager.create_connected_mqtt_core("integrationTestMQTT_ClientSub", host, rootCA,
+clientSub = myMQTTClientManager.create_connected_mqtt_core(CLIENT_ID_SUB, host, rootCA,
                                                            certificate, privateKey, mode=mode)
 
 if clientPub is None or clientSub is None:
diff --git a/test-integration/IntegrationTests/IntegrationTestShadow.py b/test-integration/IntegrationTests/IntegrationTestShadow.py
index 0b1885d..9e2c2a5 100644
--- a/test-integration/IntegrationTests/IntegrationTestShadow.py
+++ b/test-integration/IntegrationTests/IntegrationTestShadow.py
@@ -39,6 +39,8 @@
 
 # Global configuration
 TPS = 1  # Update speed, Spectre does not tolerate high TPS shadow operations...
+CLIENT_ID_PUB = "integrationTestMQTT_ClientPub" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
+CLIENT_ID_SUB = "integrationTestMQTT_ClientSub" + "".join(random.choice(string.ascii_lowercase) for i in range(4))
 
 
 # Class that manages the generation and chopping of the random string
@@ -163,9 +165,9 @@ def randomString(lengthOfString):
 
 # Init Python core and connect
 myMQTTClientManager = MQTTClientManager.MQTTClientManager()
-clientPub = myMQTTClientManager.create_connected_mqtt_core("integrationTestMQTT_ClientPub", host, rootCA,
+clientPub = myMQTTClientManager.create_connected_mqtt_core(CLIENT_ID_PUB, host, rootCA,
                                                            certificate, privateKey, mode=mode)
-clientSub = myMQTTClientManager.create_connected_mqtt_core("integrationTestMQTT_ClientSub", host, rootCA,
+clientSub = myMQTTClientManager.create_connected_mqtt_core(CLIENT_ID_SUB, host, rootCA,
                                                            certificate, privateKey, mode=mode)
 
 if clientPub is None or clientSub is None: