Skip to content

Commit

Permalink
Fix flaky specs
Browse files Browse the repository at this point in the history
  • Loading branch information
alextwoods committed Sep 7, 2023
1 parent 8e6aac3 commit 90e9a03
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
4 changes: 2 additions & 2 deletions gems/aws-sdk-core/spec/aws/plugins/retries/clock_skew_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module Plugins
let(:server_time) { (Time.now.utc + 1000).to_s }
it 'updates the corrections' do
subject.update_clock_correction(context)
expect(subject.clock_correction(endpoint)).to be_within(1).of(1000)
expect(subject.clock_correction(endpoint)).to be_within(5).of(1000)
end

it 'does not update corrections for other end points' do
Expand All @@ -90,7 +90,7 @@ module Plugins
let(:server_time) { (Time.now.utc + 1000).to_s }
it 'updates the skew' do
subject.update_estimated_skew(context)
expect(subject.estimated_skew(endpoint)).to be_within(1).of(1000)
expect(subject.estimated_skew(endpoint)).to be_within(5).of(1000)
end
end
end
Expand Down
26 changes: 18 additions & 8 deletions gems/aws-sdk-s3/spec/object/download_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,14 @@ module S3
end

n_calls = 0
mutex = Mutex.new
callback = proc do |bytes, part_sizes, total|
expect(bytes.size).to eq(4)
expect(part_sizes.size).to eq(4)
expect(total).to eq(20*one_meg)
n_calls += 1
mutex.synchronize do
expect(bytes.size).to eq(4)
expect(part_sizes.size).to eq(4)
expect(total).to eq(20*one_meg)
n_calls += 1
end
end

large_obj.download_file(path, progress_callback: callback)
Expand Down Expand Up @@ -218,10 +221,11 @@ module S3
end

it 'raises an error when checksum validation fails on multipart' do
thread = double(value: nil)
client.stub_responses(:get_object, {body: 'body', checksum_sha1: 'invalid'})

thread = double(value: nil)
allow(thread).to receive(:abort_on_exception=)
expect(Thread).to receive(:new).and_yield.and_return(thread)
allow(thread).to receive(:abort_on_exception)

expect do
large_obj.download_file(path)
Expand All @@ -230,12 +234,15 @@ module S3

it 'calls on_checksum_validated on single part' do
callback_data = {called: 0}
mutex = Mutex.new
client.stub_responses(
:get_object,
{body: 'body', checksum_sha1: 'Agg/RXngimEkJcDBoX7ket14O5Q='}
)
callback = proc do |_alg, _resp|
callback_data[:called] += 1
mutex.synchronize do
callback_data[:called] += 1
end
end

small_obj.download_file(path, on_checksum_validated: callback)
Expand All @@ -252,8 +259,11 @@ module S3
checksum_sha1: 'Agg/RXngimEkJcDBoX7ket14O5Q='
}
)
mutex = Mutex.new
callback = proc do |_alg, _resp|
callback_data[:called] += 1
mutex.synchronize do
callback_data[:called] += 1
end
end

large_obj.download_file(path, on_checksum_validated: callback)
Expand Down
33 changes: 21 additions & 12 deletions gems/aws-sdk-s3/spec/object/upload_stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,14 @@ module S3
client.stub_responses(:create_multipart_upload, upload_id: 'id')
client.stub_responses(:complete_multipart_upload)
result = []
mutex = Mutex.new
allow(client).to receive(:upload_part) do |part|
result << [
part[:part_number],
part[:body].read.size
]
mutex.synchronize do
result << [
part[:part_number],
part[:body].read.size
]
end
end.and_return(double(:upload_part, etag: 'etag'))
object.upload_stream(part_size: 7 * 1024 * 1024) do |write_stream|
17.times { write_stream << one_mb }
Expand All @@ -195,11 +198,14 @@ module S3
client.stub_responses(:create_multipart_upload, upload_id: 'id')
client.stub_responses(:complete_multipart_upload)
result = []
mutex = Mutex.new
allow(client).to receive(:upload_part) do |part|
result << [
part[:part_number],
part[:body].read.size
]
mutex.synchronize do
result << [
part[:part_number],
part[:body].read.size
]
end
end.and_return(double(:upload_part, etag: 'etag'))
object.upload_stream do |write_stream|
17.times { write_stream << one_mb }
Expand Down Expand Up @@ -375,11 +381,14 @@ module S3
client.stub_responses(:create_multipart_upload, upload_id: 'id')
client.stub_responses(:complete_multipart_upload)
result = []
mutex = Mutex.new
allow(client).to receive(:upload_part) do |part|
result << [
part[:part_number],
part[:body].read.size
]
mutex.synchronize do
result << [
part[:part_number],
part[:body].read.size
]
end
end.and_return(double(:upload_part, etag: 'etag'))
object.upload_stream(tempfile: true) do |write_stream|
17.times { write_stream << one_mb }
Expand Down
1 change: 1 addition & 0 deletions gems/aws-sdk-sqs/spec/queue_poller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def sample_message(n = nil)

it 'polls until :idle_timeout seconds have past without messages' do
now = Time.now
allow(Time).to receive(:now).and_return(now)
one_minute_later = now + 61
expect(client).to receive(:receive_message).exactly(10).times.
and_return(client.stub_data(:receive_message))
Expand Down

0 comments on commit 90e9a03

Please sign in to comment.