activerecord-aurora-serverless-adapter 6.0.0 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -3
- data/activerecord-aurora-serverless-adapter.gemspec +4 -1
- data/lib/active_record/connection_adapters/aurora_serverless/client.rb +25 -0
- data/lib/active_record/connection_adapters/aurora_serverless/version.rb +1 -1
- data/test/aasa_helper.rb +160 -0
- data/test/aurora-serverless/bin/aurora-serverless.ts +17 -0
- data/test/aurora-serverless/cdk.context.json +3 -0
- data/test/aurora-serverless/cdk.json +3 -0
- data/test/aurora-serverless/lib/aurora-serverless-stack.ts +194 -0
- data/test/aurora-serverless/package-lock.json +6485 -0
- data/test/aurora-serverless/package.json +21 -0
- data/test/aurora-serverless/tsconfig.json +23 -0
- data/test/bin/_deploy-aurora +8 -0
- data/test/bin/_wakeup +17 -0
- data/test/bin/deploy-aurora +8 -0
- data/test/bin/wakeup +8 -0
- data/test/cases/aasa/mysql_client_test.rb +59 -0
- data/test/cases/aasa/mysql_result_test.rb +63 -0
- data/test/cases/aasa/mysql_types_test.rb +135 -0
- data/test/cases/coerced_tests.rb +142 -0
- data/test/config.yml +20 -0
- data/test/support/aasa_coerceable.rb +53 -0
- data/test/support/aasa_env.rb +11 -0
- data/test/support/aasa_fixtures.rb +9 -0
- data/test/support/aasa_minitest.rb +39 -0
- data/test/support/aasa_paths.rb +47 -0
- data/test/support/aasa_rake.rb +102 -0
- metadata +39 -2
data/test/config.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
default_connection: mysql
|
2
|
+
|
3
|
+
connections:
|
4
|
+
mysql:
|
5
|
+
arunit:
|
6
|
+
database: 'activerecord_unittest'
|
7
|
+
adapter: aurora_serverless
|
8
|
+
secret_arn: <%= ENV['AASA_SECRET_ARN'] %>
|
9
|
+
resource_arn: <%= ENV['AASA_RESOURCE_ARN'] %>
|
10
|
+
# HTTP has no true sessions. Ensure base state.
|
11
|
+
variables:
|
12
|
+
foreign_key_checks: 1
|
13
|
+
arunit2:
|
14
|
+
database: 'activerecord_unittest2'
|
15
|
+
adapter: aurora_serverless
|
16
|
+
secret_arn: <%= ENV['AASA_SECRET_ARN2'] %>
|
17
|
+
resource_arn: <%= ENV['AASA_RESOURCE_ARN2'] %>
|
18
|
+
# HTTP has no true sessions. Ensure base state.
|
19
|
+
variables:
|
20
|
+
foreign_key_checks: 1
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module AASA
|
2
|
+
module Coerceable
|
3
|
+
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
cattr_accessor :coerced_tests, instance_accessor: false
|
8
|
+
self.coerced_tests = []
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
def coerce_tests!(*methods)
|
14
|
+
methods.each do |method|
|
15
|
+
self.coerced_tests.push(method)
|
16
|
+
coerced_test_warning(method)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def coerce_all_tests!
|
21
|
+
once = false
|
22
|
+
instance_methods(false).each do |method|
|
23
|
+
next unless method.to_s =~ /\Atest/
|
24
|
+
undef_method(method)
|
25
|
+
once = true
|
26
|
+
end
|
27
|
+
STDOUT.puts "🙉🙈🙊 Undefined all tests: #{self.name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def coerced_test_warning(method)
|
33
|
+
method = instance_methods(false).select { |m| m =~ method } if method.is_a?(Regexp)
|
34
|
+
Array(method).each do |m|
|
35
|
+
result = undef_method(m) if m && method_defined?(m)
|
36
|
+
if result.blank?
|
37
|
+
STDOUT.puts "🐳 Unfound coerced test: #{self.name}##{m}"
|
38
|
+
else
|
39
|
+
STDOUT.puts "🐵 Undefined coerced test: #{self.name}##{m}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module ActiveRecord
|
50
|
+
class TestCase < ActiveSupport::TestCase
|
51
|
+
include AASA::Coerceable
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# We need `ActiveRecord::ConnectionHandling::RAILS_ENV.call` to return
|
2
|
+
# nil just like when running the ActiveRecord suite. This allows the
|
3
|
+
# `DEFAULT_ENV.call` to return `default_env` propery for a lot fo tests.
|
4
|
+
#
|
5
|
+
module Rails
|
6
|
+
class << self
|
7
|
+
def env
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# The `citations` fixture exceeds our `max_allowed_packet` size
|
2
|
+
# and will raise a `Fixtures set is too large` error. Also, since
|
3
|
+
# we do not support batch operations, 65K inserts is just too slow.
|
4
|
+
#
|
5
|
+
if defined?(FIXTURES_ROOT)
|
6
|
+
citations_file = File.join FIXTURES_ROOT, 'citations.yml'
|
7
|
+
citations_data = File.read(citations_file).sub '65536.times', '1500.times'
|
8
|
+
File.open(citations_file, 'w') { |f| f.write(citations_data) }
|
9
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module AASA
|
2
|
+
module Mtr
|
3
|
+
|
4
|
+
def retry_foreign_key_checks?
|
5
|
+
defined?(::ActiveRecord) && defined?(::ARUnit2Model)
|
6
|
+
end
|
7
|
+
|
8
|
+
def retry_foreign_key_checks(count)
|
9
|
+
return unless retry_foreign_key_checks?
|
10
|
+
reset_foreign_key_check_for_class ActiveRecord::Base, count
|
11
|
+
reset_foreign_key_check_for_class ARUnit2Model, count
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset_foreign_key_check_for_class(model, count)
|
15
|
+
c = model.connection
|
16
|
+
return unless c
|
17
|
+
v = c.query_value "SELECT @@FOREIGN_KEY_CHECKS"
|
18
|
+
puts "[RETRY-FOREIGN_KEY_CHECKS] current: #{v}"
|
19
|
+
c.update "SET FOREIGN_KEY_CHECKS = 1"
|
20
|
+
sleep(count)
|
21
|
+
end
|
22
|
+
|
23
|
+
extend self
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Helpful to see test names for us vs dots.
|
29
|
+
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new()]
|
30
|
+
|
31
|
+
# There is something a little with how fixtures & foreign key checks
|
32
|
+
# are not session based with Aurora Serverless. Makes a little sense but
|
33
|
+
# even tho each connection (see config.yml) sets this up for us, some
|
34
|
+
# VERY small percentage of tests will fail. This helps?
|
35
|
+
#
|
36
|
+
Minitest::Retry.use! retry_count: 3, verbose: true
|
37
|
+
Minitest::Retry.on_retry do |klass, test_name, retry_count|
|
38
|
+
AASA::Mtr.retry_foreign_key_checks(retry_count)
|
39
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module AASA
|
2
|
+
module Paths
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def root_aasa
|
7
|
+
File.expand_path File.join(File.dirname(__FILE__), '..', '..')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_root_aasa
|
11
|
+
File.join root_aasa, 'test'
|
12
|
+
end
|
13
|
+
|
14
|
+
def root_activerecord
|
15
|
+
File.join Gem.loaded_specs['rails'].full_gem_path, 'activerecord'
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_load_paths
|
19
|
+
[
|
20
|
+
File.join(root_aasa, 'lib'),
|
21
|
+
File.join(root_aasa, 'test'),
|
22
|
+
File.join(root_activerecord, 'lib'),
|
23
|
+
File.join(root_activerecord, 'test')
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_to_load_paths!
|
28
|
+
test_load_paths.each { |p| $LOAD_PATH.unshift(p) unless $LOAD_PATH.include?(p) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def migrations_root
|
32
|
+
File.join test_root_aasa, 'migrations'
|
33
|
+
end
|
34
|
+
|
35
|
+
def arconfig_file
|
36
|
+
File.join test_root_aasa, 'config.yml'
|
37
|
+
end
|
38
|
+
|
39
|
+
def arconfig_file_env!
|
40
|
+
ENV['ARCONFIG'] = arconfig_file
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
AASA::Paths.add_to_load_paths!
|
47
|
+
AASA::Paths.arconfig_file_env!
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module AASA
|
2
|
+
module Rake
|
3
|
+
|
4
|
+
AASA_HELPER = 'test/aasa_helper.rb'
|
5
|
+
AASA_COERCED = 'test/cases/coerced_tests.rb'
|
6
|
+
|
7
|
+
AASA_ARUNIT2_TESTS = [
|
8
|
+
'test/cases/multi_db_migrator_test.rb',
|
9
|
+
'test/cases/connection_adapters/connection_handlers_multi_db_test.rb',
|
10
|
+
'test/cases/multiple_db_test.rb'
|
11
|
+
]
|
12
|
+
AASA_ARHABTM = ['test/cases/associations/has_and_belongs_to_many_associations_test.rb']
|
13
|
+
AASA_ARCONHANDLER = ['test/cases/connection_adapters/connection_handler_test.rb']
|
14
|
+
|
15
|
+
extend self
|
16
|
+
|
17
|
+
def env_ar_test_files
|
18
|
+
return unless ENV['TEST_FILES_AR'] && !ENV['TEST_FILES_AR'].empty?
|
19
|
+
@env_ar_test_files ||= begin
|
20
|
+
ENV['TEST_FILES_AR'].split(',').map { |file|
|
21
|
+
File.join AASA::Paths.root_activerecord, file.strip
|
22
|
+
}.sort
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def env_test_files
|
27
|
+
return unless ENV['TEST_FILES'] && !ENV['TEST_FILES'].empty?
|
28
|
+
@env_test_files ||= ENV['TEST_FILES'].split(',').map(&:strip)
|
29
|
+
end
|
30
|
+
|
31
|
+
def aasa_cases
|
32
|
+
@aasa_cases ||= Dir.glob('test/cases/aasa/*_test.rb')
|
33
|
+
end
|
34
|
+
|
35
|
+
def ar_cases
|
36
|
+
@ar_cases ||= begin
|
37
|
+
cases = Dir.glob("#{AASA::Paths.root_activerecord}/test/cases/**/*_test.rb")
|
38
|
+
cases.reject! { |x| x =~ /\/adapters\// }
|
39
|
+
cases.sort
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def ar_cases_isolated
|
44
|
+
ar_cases_unit2 + ar_cases_habtm + ar_cases_conhandler
|
45
|
+
end
|
46
|
+
|
47
|
+
def ar_cases_unit2
|
48
|
+
@ar_cases_unit2 ||= ar_files(AASA_ARUNIT2_TESTS)
|
49
|
+
end
|
50
|
+
|
51
|
+
def ar_cases_habtm
|
52
|
+
@ar_cases_isolated ||= ar_files(AASA_ARHABTM)
|
53
|
+
end
|
54
|
+
|
55
|
+
def ar_cases_conhandler
|
56
|
+
@ar_cases_conhandler ||= ar_files(AASA_ARCONHANDLER)
|
57
|
+
end
|
58
|
+
|
59
|
+
def ar_files(files)
|
60
|
+
files.map { |file|
|
61
|
+
File.join AASA::Paths.root_activerecord, file
|
62
|
+
}.select { |path|
|
63
|
+
File.exists?(path)
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_files
|
68
|
+
if env_ar_test_files
|
69
|
+
[AASA_HELPER] + env_ar_test_files + [AASA_COERCED]
|
70
|
+
elsif env_test_files
|
71
|
+
env_test_files
|
72
|
+
elsif ENV['ONLY_AASA']
|
73
|
+
aasa_cases
|
74
|
+
elsif ENV['ONLY_ACTIVERECORD']
|
75
|
+
if ENV['AASA_ARHABTM']
|
76
|
+
[AASA_HELPER] + ar_cases_habtm + [AASA_COERCED]
|
77
|
+
elsif ENV['AASA_ARCONHANDLER']
|
78
|
+
[AASA_HELPER] + ar_cases_conhandler + [AASA_COERCED]
|
79
|
+
elsif ENV['AASA_ARUNIT2']
|
80
|
+
[AASA_HELPER] + ar_cases_unit2 + [AASA_COERCED]
|
81
|
+
else
|
82
|
+
cases = (ar_cases - ar_cases_isolated)
|
83
|
+
cases = test_file_batches(cases)
|
84
|
+
[AASA_HELPER] + cases + [AASA_COERCED]
|
85
|
+
end
|
86
|
+
else
|
87
|
+
[AASA_HELPER] + ar_cases + [AASA_COERCED] + aasa_cases
|
88
|
+
end.uniq
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_file_batches(cases)
|
92
|
+
return cases unless ENV['AASA_BATCH']
|
93
|
+
groups = 3
|
94
|
+
index = ENV['AASA_BATCH'].to_i - 1
|
95
|
+
group = (cases.length / groups) + 1
|
96
|
+
cases = cases.each_slice(group).to_a[index]
|
97
|
+
raise "We have #{groups} groups and you requested #{index+1}" if cases.nil? || cases.empty?
|
98
|
+
cases
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-aurora-serverless-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.
|
4
|
+
version: 6.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: retriable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: appraisal
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,6 +204,29 @@ files:
|
|
190
204
|
- lib/active_record/connection_adapters/aurora_serverless_adapter.rb
|
191
205
|
- lib/activerecord-aurora-serverless-adapter.rb
|
192
206
|
- lib/mysql2.rb
|
207
|
+
- test/aasa_helper.rb
|
208
|
+
- test/aurora-serverless/bin/aurora-serverless.ts
|
209
|
+
- test/aurora-serverless/cdk.context.json
|
210
|
+
- test/aurora-serverless/cdk.json
|
211
|
+
- test/aurora-serverless/lib/aurora-serverless-stack.ts
|
212
|
+
- test/aurora-serverless/package-lock.json
|
213
|
+
- test/aurora-serverless/package.json
|
214
|
+
- test/aurora-serverless/tsconfig.json
|
215
|
+
- test/bin/_deploy-aurora
|
216
|
+
- test/bin/_wakeup
|
217
|
+
- test/bin/deploy-aurora
|
218
|
+
- test/bin/wakeup
|
219
|
+
- test/cases/aasa/mysql_client_test.rb
|
220
|
+
- test/cases/aasa/mysql_result_test.rb
|
221
|
+
- test/cases/aasa/mysql_types_test.rb
|
222
|
+
- test/cases/coerced_tests.rb
|
223
|
+
- test/config.yml
|
224
|
+
- test/support/aasa_coerceable.rb
|
225
|
+
- test/support/aasa_env.rb
|
226
|
+
- test/support/aasa_fixtures.rb
|
227
|
+
- test/support/aasa_minitest.rb
|
228
|
+
- test/support/aasa_paths.rb
|
229
|
+
- test/support/aasa_rake.rb
|
193
230
|
homepage: https://github.com/customink/activerecord-aurora-serverless-adapter
|
194
231
|
licenses:
|
195
232
|
- MIT
|