22
22
from gcloud .environment_vars import PUBSUB_EMULATOR
23
23
from gcloud .environment_vars import TESTS_PROJECT
24
24
from gcloud import pubsub
25
+
25
26
from system_test_utils import EmulatorCreds
27
+ from system_test_utils import unique_resource_id
26
28
27
29
28
- DEFAULT_TOPIC_NAME = 'subscribe-me%d' % ( 1000 * time . time (), )
30
+ DEFAULT_TOPIC_NAME = 'subscribe-me' + unique_resource_id ( '-' )
29
31
30
32
31
33
class Config (object ):
@@ -58,7 +60,7 @@ def tearDown(self):
58
60
doomed .delete ()
59
61
60
62
def test_create_topic (self ):
61
- topic_name = 'a-new-topic%d' % ( 1000 * time . time (), )
63
+ topic_name = 'a-new-topic' + unique_resource_id ( '-' )
62
64
topic = Config .CLIENT .topic (topic_name )
63
65
self .assertFalse (topic .exists ())
64
66
topic .create ()
@@ -68,9 +70,9 @@ def test_create_topic(self):
68
70
69
71
def test_list_topics (self ):
70
72
topics_to_create = [
71
- 'new%d' % ( 1000 * time . time (), ),
72
- 'newer%d' % ( 1000 * time . time (), ),
73
- 'newest%d' % ( 1000 * time . time (), ),
73
+ 'new' + unique_resource_id ( ),
74
+ 'newer' + unique_resource_id ( ),
75
+ 'newest' + unique_resource_id ( ),
74
76
]
75
77
for topic_name in topics_to_create :
76
78
topic = Config .CLIENT .topic (topic_name )
@@ -89,7 +91,7 @@ def test_create_subscription_defaults(self):
89
91
self .assertFalse (topic .exists ())
90
92
topic .create ()
91
93
self .to_delete .append (topic )
92
- SUBSCRIPTION_NAME = 'subscribing-now-%d' % ( 1000 * time . time (), )
94
+ SUBSCRIPTION_NAME = 'subscribing-now' + unique_resource_id ( '-' )
93
95
subscription = topic .subscription (SUBSCRIPTION_NAME )
94
96
self .assertFalse (subscription .exists ())
95
97
subscription .create ()
@@ -103,7 +105,7 @@ def test_create_subscription_w_ack_deadline(self):
103
105
self .assertFalse (topic .exists ())
104
106
topic .create ()
105
107
self .to_delete .append (topic )
106
- SUBSCRIPTION_NAME = 'subscribing-now-%d' % ( 1000 * time . time (), )
108
+ SUBSCRIPTION_NAME = 'subscribing-now' + unique_resource_id ( )
107
109
subscription = topic .subscription (SUBSCRIPTION_NAME , ack_deadline = 120 )
108
110
self .assertFalse (subscription .exists ())
109
111
subscription .create ()
@@ -121,9 +123,9 @@ def test_list_subscriptions(self):
121
123
empty , _ = topic .list_subscriptions ()
122
124
self .assertEqual (len (empty ), 0 )
123
125
subscriptions_to_create = [
124
- 'new%d' % ( 1000 * time . time (), ),
125
- 'newer%d' % ( 1000 * time . time (), ),
126
- 'newest%d' % ( 1000 * time . time (), ),
126
+ 'new' + unique_resource_id ( ),
127
+ 'newer' + unique_resource_id ( ),
128
+ 'newest' + unique_resource_id ( ),
127
129
]
128
130
for subscription_name in subscriptions_to_create :
129
131
subscription = topic .subscription (subscription_name )
@@ -142,7 +144,7 @@ def test_message_pull_mode_e2e(self):
142
144
self .assertFalse (topic .exists ())
143
145
topic .create ()
144
146
self .to_delete .append (topic )
145
- SUBSCRIPTION_NAME = 'subscribing-now-%d' % ( 1000 * time . time (), )
147
+ SUBSCRIPTION_NAME = 'subscribing-now' + unique_resource_id ( '-' )
146
148
subscription = topic .subscription (SUBSCRIPTION_NAME )
147
149
self .assertFalse (subscription .exists ())
148
150
subscription .create ()
@@ -170,7 +172,7 @@ def _by_timestamp(message):
170
172
self .assertEqual (message2 .attributes ['extra' ], EXTRA_2 )
171
173
172
174
def test_topic_iam_policy (self ):
173
- topic_name = 'test-topic-iam-policy-topic-%d' % ( 1000 * time . time (), )
175
+ topic_name = 'test-topic-iam-policy-topic' + unique_resource_id ( '-' )
174
176
topic = Config .CLIENT .topic (topic_name )
175
177
topic .create ()
176
178
count = 5
@@ -185,7 +187,7 @@ def test_topic_iam_policy(self):
185
187
self .assertEqual (new_policy .viewers , policy .viewers )
186
188
187
189
def test_subscription_iam_policy (self ):
188
- topic_name = 'test-sub-iam-policy-topic-%d' % ( 1000 * time . time (), )
190
+ topic_name = 'test-sub-iam-policy-topic' + unique_resource_id ( '-' )
189
191
topic = Config .CLIENT .topic (topic_name )
190
192
topic .create ()
191
193
count = 5
@@ -194,7 +196,7 @@ def test_subscription_iam_policy(self):
194
196
count -= 1
195
197
self .assertTrue (topic .exists ())
196
198
self .to_delete .append (topic )
197
- SUB_NAME = 'test-sub-iam-policy-sub-%d' % ( 1000 * time . time (), )
199
+ SUB_NAME = 'test-sub-iam-policy-sub' + unique_resource_id ( '-' )
198
200
subscription = topic .subscription (SUB_NAME )
199
201
subscription .create ()
200
202
count = 5
@@ -209,8 +211,8 @@ def test_subscription_iam_policy(self):
209
211
self .assertEqual (new_policy .viewers , policy .viewers )
210
212
211
213
def test_fetch_delete_subscription_w_deleted_topic (self ):
212
- TO_DELETE = 'delete-me-%d' % ( 1000 * time . time (), )
213
- ORPHANED = 'orphaned-%d' % ( 1000 * time . time (), )
214
+ TO_DELETE = 'delete-me' + unique_resource_id ( '-' )
215
+ ORPHANED = 'orphaned' + unique_resource_id ( '-' )
214
216
topic = Config .CLIENT .topic (TO_DELETE )
215
217
topic .create ()
216
218
subscription = topic .subscription (ORPHANED )
0 commit comments