Skip to content

Commit 6397e99

Browse files
committed
Fix Dynamoid::AdapterPlugin::AwsSdkV3::UntilPastTableStatus issue
1 parent 40ced91 commit 6397e99

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

lib/dynamoid/adapter_plugin/aws_sdk_v3.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def delete_item(table_name, key, options = {})
356356
# @since 1.0.0
357357
def delete_table(table_name, options = {})
358358
resp = client.delete_table(table_name: table_name)
359-
UntilPastTableStatus.new(table_name, :deleting).call if options[:sync] &&
359+
UntilPastTableStatus.new(client, table_name, :deleting).call if options[:sync] &&
360360
(status = PARSE_TABLE_STATUS.call(resp, :table_description)) &&
361361
status == TABLE_STATUSES[:deleting]
362362
table_cache.delete(table_name)

lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def call
6262
end
6363
resp = client.create_table(client_opts)
6464
options[:sync] = true if !options.key?(:sync) && ls_indexes.present? || gs_indexes.present?
65-
UntilPastTableStatus.new(table_name, :creating).call if options[:sync] &&
65+
UntilPastTableStatus.new(client, table_name, :creating).call if options[:sync] &&
6666
(status = PARSE_TABLE_STATUS.call(resp, :table_description)) &&
6767
status == TABLE_STATUSES[:creating]
6868
# Response to original create_table, which, if options[:sync]

lib/dynamoid/adapter_plugin/aws_sdk_v3/until_past_table_status.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ module Dynamoid
44
module AdapterPlugin
55
class AwsSdkV3
66
class UntilPastTableStatus
7-
attr_reader :table_name, :status
7+
attr_reader :client, :table_name, :status
88

9-
def initialize(table_name, status = :creating)
9+
def initialize(client, table_name, status = :creating)
10+
@client = client
1011
@table_name = table_name
1112
@status = status
1213
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'dynamoid/adapter_plugin/aws_sdk_v3'
5+
6+
describe Dynamoid::AdapterPlugin::AwsSdkV3::UntilPastTableStatus do
7+
describe 'call' do
8+
context 'table creation' do
9+
let(:client) { double('client') }
10+
let(:response_creating) { double('response#creating', table: creating_table) }
11+
let(:response_active) { double('response#active', table: active_table) }
12+
let(:creating_table) { double('creating_table', table_status: 'CREATING') }
13+
let(:active_table) { double('creating_table', table_status: 'ACTIVE') }
14+
15+
it 'wait until table is created', config: { sync_retry_max_times: 60 } do
16+
expect(client).to receive(:describe_table)
17+
.with(table_name: :dogs).exactly(3).times
18+
.and_return(response_creating, response_creating, response_active)
19+
20+
described_class.new(client, :dogs, :creating).call
21+
end
22+
23+
it 'stops if exceeded Dynamoid.config.sync_retry_max_times attempts limit',
24+
config: { sync_retry_max_times: 5 } do
25+
26+
expect(client).to receive(:describe_table)
27+
.exactly(6).times
28+
.and_return(*[response_creating]*6)
29+
30+
described_class.new(client, :dogs, :creating).call
31+
end
32+
33+
it 'uses :sync_retry_max_times seconds to delay attempts',
34+
config: { sync_retry_wait_seconds: 2, sync_retry_max_times: 3 } do
35+
36+
service = described_class.new(client, :dogs, :creating)
37+
allow(client).to receive(:describe_table).and_return(response_creating).exactly(4).times
38+
expect(service).to receive(:sleep).with(2).exactly(4).times
39+
40+
service.call
41+
end
42+
end
43+
end
44+
end

0 commit comments

Comments
 (0)