Skip to content

Commit 079e199

Browse files
committed
fix: removed loop_times
1 parent ea714d9 commit 079e199

1 file changed

Lines changed: 30 additions & 19 deletions

File tree

spec/channel_batch_updater_spec.rb

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,6 @@
44
require 'stream-chat'
55

66
describe StreamChat::ChannelBatchUpdater do
7-
def loop_times(times)
8-
loop do
9-
begin
10-
yield()
11-
return
12-
rescue StandardError, RSpec::Expectations::ExpectationNotMetError
13-
raise if times.zero?
14-
end
15-
16-
sleep(1)
17-
times -= 1
18-
end
19-
end
20-
217
def rate_limit_error?(task)
228
result = task['result']
239
return false unless result.is_a?(Hash)
@@ -149,13 +135,18 @@ def wait_for_task(task_id, timeout_seconds: 120)
149135
wait_for_task(task_id)
150136

151137
# Verify members were added
152-
loop_times(120) do
138+
120.times do |i|
153139
@channel1.refresh_state
154140
ch1_member_ids = @channel1.members.map { |m| m['user']['id'] }
155141

156142
member_ids.each do |member_id|
157143
expect(ch1_member_ids).to include(member_id)
158144
end
145+
break
146+
rescue StandardError, RSpec::Expectations::ExpectationNotMetError => e
147+
raise e if i == 119
148+
149+
sleep(1)
159150
end
160151
end
161152
end
@@ -168,12 +159,17 @@ def wait_for_task(task_id, timeout_seconds: 120)
168159
@channel2.add_members(members_to_add)
169160

170161
# Verify members were added
171-
loop_times(60) do
162+
60.times do |i|
172163
@channel1.refresh_state
173164
expect(@channel1.members.length).to eq(2)
174165

175166
@channel2.refresh_state
176167
expect(@channel2.members.length).to eq(2)
168+
break
169+
rescue StandardError, RSpec::Expectations::ExpectationNotMetError => e
170+
raise e if i == 59
171+
172+
sleep(1)
177173
end
178174

179175
# Verify member IDs match
@@ -200,11 +196,16 @@ def wait_for_task(task_id, timeout_seconds: 120)
200196
wait_for_task(task_id)
201197

202198
# Verify member was removed
203-
loop_times(120) do
199+
120.times do |i|
204200
@channel1.refresh_state
205201
ch1_member_ids = @channel1.members.map { |m| m['user']['id'] }
206202

207203
expect(ch1_member_ids).not_to include(member_to_remove)
204+
break
205+
rescue StandardError, RSpec::Expectations::ExpectationNotMetError => e
206+
raise e if i == 119
207+
208+
sleep(1)
208209
end
209210
end
210211
end
@@ -217,9 +218,14 @@ def wait_for_task(task_id, timeout_seconds: 120)
217218
@channel2.add_members(members_to_add)
218219

219220
# Wait for members to be added
220-
loop_times(60) do
221+
60.times do |i|
221222
@channel1.refresh_state
222223
expect(@channel1.members.length).to eq(2)
224+
break
225+
rescue StandardError, RSpec::Expectations::ExpectationNotMetError => e
226+
raise e if i == 59
227+
228+
sleep(1)
223229
end
224230

225231
# Archive channels for one member
@@ -237,12 +243,17 @@ def wait_for_task(task_id, timeout_seconds: 120)
237243
wait_for_task(task_id)
238244

239245
# Verify archived_at is set for the member
240-
loop_times(120) do
246+
120.times do |i|
241247
@channel1.refresh_state
242248
member = @channel1.members.find { |m| m['user']['id'] == member_to_archive }
243249

244250
expect(member).not_to be_nil
245251
expect(member['archived_at']).not_to be_nil
252+
break
253+
rescue StandardError, RSpec::Expectations::ExpectationNotMetError => e
254+
raise e if i == 119
255+
256+
sleep(1)
246257
end
247258
end
248259
end

0 commit comments

Comments
 (0)