From dd3254d515c26291bc19ae103b6e8d2ce0e58fef Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Tue, 7 Apr 2020 16:45:12 -0700 Subject: [PATCH 1/2] [iot] fix: mitigate flaky tests * use uuid1 instead of time for resource name * correctly use the pytest marker * mark another test as flaky --- iot/api-client/manager/manager_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iot/api-client/manager/manager_test.py b/iot/api-client/manager/manager_test.py index c29d6e3c425..78067d3e039 100644 --- a/iot/api-client/manager/manager_test.py +++ b/iot/api-client/manager/manager_test.py @@ -20,7 +20,6 @@ # Add command receiver for bootstrapping device registry / device for testing sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'mqtt_example')) # noqa -from flaky import flaky from google.cloud import pubsub import pytest @@ -33,7 +32,7 @@ es_cert_path = 'resources/ec_public.pem' rsa_cert_path = 'resources/rsa_cert.pem' rsa_private_path = 'resources/rsa_private.pem' # Must match rsa_cert -topic_id = 'test-device-events-{}'.format(int(time.time())) +topic_id = 'test-device-events-{}'.format(uuid.uuid1()) project_id = os.environ['GCLOUD_PROJECT'] service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS'] @@ -202,6 +201,7 @@ def test_add_delete_unauth_device(test_topic, capsys): assert 'UNAUTH' in out +@pytest.mark.flaky(max_runs=5, min_passes=1) def test_add_config_unauth_device(test_topic, capsys): device_id = device_id_template.format('UNAUTH') manager.open_registry( @@ -363,7 +363,7 @@ def test_add_patch_delete_es256(test_topic, capsys): service_account_json, project_id, cloud_region, registry_id) -@flaky(max_runs=5, min_passes=1) +@pytest.mark.flaky(max_runs=5, min_passes=1) def test_send_command(test_topic, capsys): device_id = device_id_template.format('RSA256') manager.create_registry( From bacfb620c28b579e38cb156baeaa74edde599f12 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Wed, 8 Apr 2020 10:10:34 -0700 Subject: [PATCH 2/2] use uuid4 --- iot/api-client/manager/manager_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iot/api-client/manager/manager_test.py b/iot/api-client/manager/manager_test.py index 78067d3e039..cdd8613943b 100644 --- a/iot/api-client/manager/manager_test.py +++ b/iot/api-client/manager/manager_test.py @@ -32,7 +32,7 @@ es_cert_path = 'resources/ec_public.pem' rsa_cert_path = 'resources/rsa_cert.pem' rsa_private_path = 'resources/rsa_private.pem' # Must match rsa_cert -topic_id = 'test-device-events-{}'.format(uuid.uuid1()) +topic_id = 'test-device-events-{}'.format(uuid.uuid4()) project_id = os.environ['GCLOUD_PROJECT'] service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS']