Last active
March 15, 2020 17:42
-
-
Save tsub/72e60233ed82a8a453428ea7441e6017 to your computer and use it in GitHub Desktop.
Test codes to reproduce not thread-safe errors of Dynamoid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dynamoid' | |
Aws.config.update({ | |
region: 'us-west-2', | |
credentials: Aws::Credentials.new('test', 'test'), | |
}) | |
Dynamoid.configure do |config| | |
config.endpoint = 'http://localhost:8000' | |
end | |
Dynamoid.logger.level = Logger::INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
dynamodb: | |
image: amazon/dynamodb-local | |
ports: | |
- 8000:8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Document | |
include Dynamoid::Document | |
table name: :documents, key: :identifier | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
source 'https://rubygems.org' | |
gem 'dynamoid' | |
gem 'pry-byebug', platforms: :ruby | |
gem 'rake' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: https://rubygems.org/ | |
specs: | |
activemodel (5.2.3) | |
activesupport (= 5.2.3) | |
activesupport (5.2.3) | |
concurrent-ruby (~> 1.0, >= 1.0.2) | |
i18n (>= 0.7, < 2) | |
minitest (~> 5.1) | |
tzinfo (~> 1.1) | |
aws-eventstream (1.0.3) | |
aws-partitions (1.196.0) | |
aws-sdk-core (3.62.0) | |
aws-eventstream (~> 1.0, >= 1.0.2) | |
aws-partitions (~> 1.0) | |
aws-sigv4 (~> 1.1) | |
jmespath (~> 1.0) | |
aws-sdk-dynamodb (1.34.0) | |
aws-sdk-core (~> 3, >= 3.61.1) | |
aws-sigv4 (~> 1.1) | |
aws-sigv4 (1.1.0) | |
aws-eventstream (~> 1.0, >= 1.0.2) | |
byebug (11.0.1) | |
coderay (1.1.2) | |
concurrent-ruby (1.1.5) | |
dynamoid (3.2.0) | |
activemodel (>= 4) | |
aws-sdk-dynamodb (~> 1) | |
concurrent-ruby (>= 1.0) | |
null-logger | |
i18n (1.6.0) | |
concurrent-ruby (~> 1.0) | |
jmespath (1.4.0) | |
method_source (0.9.2) | |
minitest (5.11.3) | |
null-logger (0.1.5) | |
pry (0.12.2) | |
coderay (~> 1.1.0) | |
method_source (~> 0.9.0) | |
pry-byebug (3.7.0) | |
byebug (~> 11.0) | |
pry (~> 0.10) | |
rake (12.3.3) | |
thread_safe (0.3.6) | |
tzinfo (1.2.5) | |
thread_safe (~> 0.1) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
dynamoid | |
pry-byebug | |
rake | |
BUNDLED WITH | |
2.0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dynamoid' | |
require_relative 'config' | |
require_relative 'document' | |
def watchdog(name) | |
yield | |
rescue Exception => ex | |
puts "Thread name: \"#{name}\", Exception: \"#{ex}\"" | |
end | |
def safe_thread(name, &block) | |
Thread.new do | |
Thread.current.name = name | |
watchdog(name, &block) | |
end | |
end | |
100.times do |i| | |
safe_thread(i.to_s) do | |
puts 'debug' # To unlock Ruby's GVL | |
Document.where(identifier: 'hoge').first | |
end | |
end | |
loop do | |
sleep 5 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rake::Task.define_task(:environment) | |
require 'dynamoid/tasks' | |
require_relative 'config' | |
require_relative 'document' | |
namespace :dynamoid do | |
desc 'Insert db seeds into DynamoDB' | |
task :seed do | |
begin | |
Document.find('hoge') | |
rescue Dynamoid::Errors::RecordNotFound | |
Document.create(identifier: 'hoge') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to setup
How to reproduce errors