Skip to content

Commit 68b62b1

Browse files
committed
fix(pubsub): fix flakiness in pubsub_subscribe_avro_records samples tests
1 parent 9aafea6 commit 68b62b1

File tree

1 file changed

+10
-35
lines changed

1 file changed

+10
-35
lines changed

google-cloud-pubsub/samples/acceptance/schemas_test.rb

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,16 @@
109109
let(:avro_schema) { Avro::Schema.parse avsc_definition }
110110
let(:record) { { "name" => "Alaska", "post_abbr" => "AK" } }
111111

112-
it "supports pubsub_create_topic_with_schema, pubsub_publish_avro_records with binary encoding" do
112+
before do
113113
schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id,
114114
type: :AVRO,
115115
definition: avsc_definition
116116
@schema = schemas.create_schema parent: pubsub.project_path,
117117
schema: schema,
118118
schema_id: schema_id
119+
end
119120

120-
121+
it "supports pubsub_create_topic_with_schema, pubsub_publish_avro_records with binary encoding" do
121122
# pubsub_create_topic_with_schema
122123
assert_output "Topic projects/#{pubsub.project}/topics/#{topic_id} created.\n" do
123124
create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :BINARY
@@ -133,13 +134,6 @@
133134
end
134135

135136
it "supports pubsub_create_topic_with_schema, pubsub_publish_avro_records with JSON encoding" do
136-
schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id,
137-
type: :AVRO,
138-
definition: avsc_definition
139-
@schema = schemas.create_schema parent: pubsub.project_path,
140-
schema: schema,
141-
schema_id: schema_id
142-
143137
# pubsub_create_topic_with_schema
144138
assert_output "Topic projects/#{pubsub.project}/topics/#{topic_id} created.\n" do
145139
create_topic_with_schema topic_id: topic_id, schema_id: schema_id, message_encoding: :JSON
@@ -155,13 +149,6 @@
155149
end
156150

157151
it "supports pubsub_subscribe_avro_records with binary encoding" do
158-
schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id,
159-
type: :AVRO,
160-
definition: avsc_definition
161-
@schema = schemas.create_schema parent: pubsub.project_path,
162-
schema: schema,
163-
schema_id: schema_id
164-
165152
schema_settings = Google::Cloud::PubSub::V1::SchemaSettings.new schema: pubsub.schema_path(schema_id),
166153
encoding: :BINARY
167154

@@ -170,30 +157,24 @@
170157
schema_settings: schema_settings
171158

172159
@subscription = subscription_admin.create_subscription name: pubsub.subscription_path(random_subscription_id),
173-
topic: @topic.name
160+
topic: @topic.name,
161+
ack_deadline_seconds: 60
174162

175163
writer = Avro::IO::DatumWriter.new avro_schema
176164
buffer = StringIO.new
177165
writer.write record, Avro::IO::BinaryEncoder.new(buffer)
178166
publisher = pubsub.publisher @topic.name
179167
publisher.publish buffer
180-
sleep 5
181168

182169
# pubsub_subscribe_avro_records
183170
expect_with_retry "pubsub_subscribe_avro_records" do
184-
assert_output "Received a binary-encoded message:\n{\"name\"=>\"Alaska\", \"post_abbr\"=>\"AK\"}\n" do
171+
assert_output "Received a binary-encoded message:\n{\"name\" => \"Alaska\", \"post_abbr\" => \"AK\"}\n" do
185172
subscribe_avro_records subscription_id: @subscription.name, avsc_file: avsc_file
186173
end
187174
end
188175
end
189176

190177
it "supports pubsub_subscribe_avro_records with JSON encoding" do
191-
schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id,
192-
type: :AVRO,
193-
definition: avsc_definition
194-
@schema = schemas.create_schema parent: pubsub.project_path,
195-
schema: schema,
196-
schema_id: schema_id
197178
schema_settings = Google::Cloud::PubSub::V1::SchemaSettings.new schema: pubsub.schema_path(schema_id),
198179
encoding: :JSON
199180

@@ -202,28 +183,22 @@
202183
schema_settings: schema_settings
203184

204185
@subscription = subscription_admin.create_subscription name: pubsub.subscription_path(random_subscription_id),
205-
topic: @topic.name
186+
topic: @topic.name,
187+
ack_deadline_seconds: 60
206188

207189
publisher = pubsub.publisher @topic.name
208190
publisher.publish record.to_json
209-
sleep 5
210191

211192
# pubsub_subscribe_avro_records
212193
expect_with_retry "pubsub_subscribe_avro_records" do
213-
assert_output "Received a JSON-encoded message:\n{\"name\"=>\"Alaska\", \"post_abbr\"=>\"AK\"}\n" do
194+
assert_output "Received a JSON-encoded message:\n{\"name\" => \"Alaska\", \"post_abbr\" => \"AK\"}\n" do
214195
subscribe_avro_records subscription_id: @subscription.name, avsc_file: nil
215196
end
216197
end
217198
end
218199

219200
it "supports pubsub_commit_avro_schema & pubsub_commit_list_schema_revisions" do
220-
schema = Google::Cloud::PubSub::V1::Schema.new name: schema_id,
221-
type: :AVRO,
222-
definition: avsc_definition
223-
@schema = schemas.create_schema parent: pubsub.project_path,
224-
schema: schema,
225-
schema_id: schema_id
226-
201+
227202
rev_id = @schema.revision_id
228203

229204
schema1 = nil

0 commit comments

Comments
 (0)