Skip to content

Commit

Permalink
Fix Dynamoid::AdapterPlugin::AwsSdkV3::UntilPastTableStatus issue
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed May 25, 2019
1 parent 40ced91 commit 6397e99
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/dynamoid/adapter_plugin/aws_sdk_v3.rb
Expand Up @@ -356,7 +356,7 @@ def delete_item(table_name, key, options = {})
# @since 1.0.0
def delete_table(table_name, options = {})
resp = client.delete_table(table_name: table_name)
UntilPastTableStatus.new(table_name, :deleting).call if options[:sync] &&
UntilPastTableStatus.new(client, table_name, :deleting).call if options[:sync] &&
(status = PARSE_TABLE_STATUS.call(resp, :table_description)) &&
status == TABLE_STATUSES[:deleting]
table_cache.delete(table_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb
Expand Up @@ -62,7 +62,7 @@ def call
end
resp = client.create_table(client_opts)
options[:sync] = true if !options.key?(:sync) && ls_indexes.present? || gs_indexes.present?
UntilPastTableStatus.new(table_name, :creating).call if options[:sync] &&
UntilPastTableStatus.new(client, table_name, :creating).call if options[:sync] &&
(status = PARSE_TABLE_STATUS.call(resp, :table_description)) &&
status == TABLE_STATUSES[:creating]
# Response to original create_table, which, if options[:sync]
Expand Down
Expand Up @@ -4,9 +4,10 @@ module Dynamoid
module AdapterPlugin
class AwsSdkV3
class UntilPastTableStatus
attr_reader :table_name, :status
attr_reader :client, :table_name, :status

def initialize(table_name, status = :creating)
def initialize(client, table_name, status = :creating)
@client = client
@table_name = table_name
@status = status
end
Expand Down
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require 'spec_helper'
require 'dynamoid/adapter_plugin/aws_sdk_v3'

describe Dynamoid::AdapterPlugin::AwsSdkV3::UntilPastTableStatus do
describe 'call' do
context 'table creation' do
let(:client) { double('client') }
let(:response_creating) { double('response#creating', table: creating_table) }
let(:response_active) { double('response#active', table: active_table) }
let(:creating_table) { double('creating_table', table_status: 'CREATING') }
let(:active_table) { double('creating_table', table_status: 'ACTIVE') }

it 'wait until table is created', config: { sync_retry_max_times: 60 } do
expect(client).to receive(:describe_table)
.with(table_name: :dogs).exactly(3).times
.and_return(response_creating, response_creating, response_active)

described_class.new(client, :dogs, :creating).call
end

it 'stops if exceeded Dynamoid.config.sync_retry_max_times attempts limit',
config: { sync_retry_max_times: 5 } do

expect(client).to receive(:describe_table)
.exactly(6).times
.and_return(*[response_creating]*6)

described_class.new(client, :dogs, :creating).call
end

it 'uses :sync_retry_max_times seconds to delay attempts',
config: { sync_retry_wait_seconds: 2, sync_retry_max_times: 3 } do

service = described_class.new(client, :dogs, :creating)
allow(client).to receive(:describe_table).and_return(response_creating).exactly(4).times
expect(service).to receive(:sleep).with(2).exactly(4).times

service.call
end
end
end
end

0 comments on commit 6397e99

Please sign in to comment.