forked from Nasdaq/active_record_proxy_adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
253 lines (198 loc) · 8.48 KB
/
Rakefile
File metadata and controls
253 lines (198 loc) · 8.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "uri"
require "redis"
RSpec::Core::RakeTask.new(:spec)
require "rubocop/rake_task"
RuboCop::RakeTask.new
task default: %i[spec rubocop]
desc "Prepares the database environment for use"
task :environment do
$LOAD_PATH << File.expand_path("lib", __dir__)
require "active_record_proxy_adapters"
require "active_record_proxy_adapters/core"
require_relative "spec/test_helper"
require "active_record_proxy_adapters/connection_handling"
ActiveSupport.on_load(:active_record) do
TestHelper.setup_active_record_config
$stdout.puts "Environment loaded: #{TestHelper.env_name}"
end
end
namespace :db do # rubocop:disable Metrics/BlockLength
desc "Drops all databases"
task drop: %i[drop:postgresql drop:mysql2 drop:trilogy drop:sqlite3]
namespace :drop do
desc "Drops the postgresql database"
task postgresql: :environment do
TestHelper.drop_postgresql_database
end
desc "Drops the mysql database"
task mysql2: :environment do
TestHelper.drop_mysql2_database
end
desc "Drops the trilogy database"
task trilogy: :environment do
TestHelper.drop_trilogy_database
end
desc "Drops the sqlite3 database"
task sqlite3: :environment do
TestHelper.drop_sqlite3_database
end
end
desc "Creates all databases"
task create: %i[create:postgresql create:mysql2 create:trilogy create:sqlite3]
namespace :create do
desc "Creates the postgresql database"
task postgresql: :environment do
TestHelper.create_postgresql_database
end
desc "Creates the mysql database"
task mysql2: :environment do
TestHelper.create_mysql2_database
end
desc "Creates the trilogy database"
task trilogy: :environment do
TestHelper.create_trilogy_database
end
desc "Creates the sqlite3 database"
task sqlite3: :environment do
TestHelper.create_sqlite3_database
end
end
namespace :schema do # rubocop:disable Metrics/BlockLength
desc "Loads all schemas onto their respective databases"
task load: %i[load:postgresql load:mysql2 load:trilogy load:sqlite3]
namespace :load do
desc "Loads the schema into the postgresql database from schema_path. Default is db/postgresql_structure.sql"
task :postgresql, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/postgresql_structure.sql")
TestHelper.load_postgresql_schema(args.schema_path)
end
desc "Loads the schema into the mysql database from schema_path. Default is db/mysql_structure.sql"
task :mysql2, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/mysql_structure.sql")
TestHelper.load_mysql2_schema(args.schema_path)
end
desc "Loads the schema into the trilogy database from schema_path. Default is db/mysql_structure.sql"
task :trilogy, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/mysql_structure.sql")
TestHelper.load_trilogy_schema(args.schema_path)
end
desc "Loads the schema into the sqlite3 database from schema_path. Default is db/sqlite3_structure.sql"
task :sqlite3, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/sqlite3_structure.sql")
TestHelper.load_sqlite3_schema(args.schema_path)
end
end
desc "Dumps all schemas onto their respective files"
task dump: %i[dump:postgresql dump:mysql2 dump:trilogy dump:sqlite3]
namespace :dump do
desc "Dump the schema from the postgresql database onto schema_path. Default is db/postgresql_structure.sql"
task :postgresql, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/postgresql_structure.sql")
TestHelper.dump_postgresql_schema(args.schema_path)
end
desc "Dump the schema from the mysql database onto schema_path. Default is db/mysql_structure.sql"
task :mysql2, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/mysql_structure.sql")
TestHelper.dump_mysql2_schema(args.schema_path)
end
desc "Dump the schema from the trilogy database onto schema_path. Default is db/mysql_structure.sql"
task :trilogy, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/mysql_structure.sql")
TestHelper.dump_trilogy_schema(args.schema_path)
end
desc "Dump the schema from the sqlite3 database onto schema_path. Default is db/sqlite3_structure.sql"
task :sqlite3, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/sqlite3_structure.sql")
TestHelper.dump_sqlite3_schema(args.schema_path)
end
end
end
desc "Creates a all databases and loads their schemas"
task setup: %i[create schema:load]
namespace :setup do
desc "Creates the postgresql database and loads the schema"
task postgresql: %i[create:postgresql schema:load:postgresql]
desc "Creates the mysql2 database and loads the schema"
task mysql2: %i[create:mysql2 schema:load:mysql2]
desc "Creates the trilogy database and loads the schema"
task trilogy: %i[create:trilogy schema:load:trilogy]
end
end
namespace :coverage do
desc "Collates all result sets generated by the different test runners"
task :report do
require "simplecov"
require_relative "spec/simple_cov_groups"
SimpleCov.collate Dir["coverage/**/.resultset.json"] do
SIMPLE_COV_GROUPS.call
end
end
end
namespace :benchmark do # rubocop:disable Metrics/BlockLength
namespace :cache_store do # rubocop:disable Metrics/BlockLength
desc "Runs all cache store benchmark suites"
task :run, %i[iterations] => %i[environment] do |_, args|
iterations = args[:iterations]&.to_i
%w[null:run memory:run file:run redis:run memcached:run].each do |task_name|
task("benchmark:cache_store:#{task_name}").execute(iterations: iterations)
puts "\n" * 2
puts "=" * 83
puts "\n" * 2
end
end
namespace :null do
desc "Runs the NullStore benchmark suite"
task :run, %i[iterations] => %i[environment] do |_, args|
require_relative "spec/benchmark/cache_store"
store_class = ActiveSupport::Cache::NullStore
$stdout.puts "Benchmarking proxy pattern matching with #{store_class} cache store..."
CacheStoreBenchmark.run(store_class.new, iterations: args[:iterations]&.to_i)
end
end
namespace :memory do
desc "Runs the MemoryStore benchmark suite"
task :run, %i[iterations] => %i[environment] do |_, args|
require_relative "spec/benchmark/cache_store"
store_class = ActiveSupport::Cache::MemoryStore
CacheStoreBenchmark.run(store_class.new, iterations: args[:iterations]&.to_i)
end
end
namespace :file do
desc "Runs the FileStore benchmark suite"
task :run, %i[iterations] => %i[environment] do |_, args|
require_relative "spec/benchmark/cache_store"
store_class = ActiveSupport::Cache::FileStore
Dir.mktmpdir do |tempdir_path|
CacheStoreBenchmark.run(store_class.new(tempdir_path), iterations: args[:iterations]&.to_i)
end
end
end
namespace :redis do
desc "Runs the RedisCacheStore benchmark suite"
task :run, %i[iterations] => %i[environment] do |_, args|
require_relative "spec/benchmark/cache_store"
redis_uri = URI.parse(ENV.fetch("REDIS_URL", "redis://localhost:6379/0"))
redis = Redis.new(url: redis_uri.to_s)
redis_store = ActiveSupport::Cache::RedisCacheStore.new(redis: redis)
redis_store.read("connected?")
unless redis.connected?
abort("Redis is not connected. Please ensure Redis is running and accessible at #{redis_uri}.")
end
CacheStoreBenchmark.run(redis_store, iterations: args[:iterations]&.to_i)
end
end
namespace :memcached do
desc "Runs the MemCacheStore benchmark suite"
task :run, %i[iterations] => %i[environment] do |_, args|
require_relative "spec/benchmark/cache_store"
memcached_uri = URI.parse(ENV.fetch("MEMCACHED_URL", "localhost:11211"))
memcached_store = ActiveSupport::Cache::MemCacheStore.new(memcached_uri.to_s)
memcached_store.clear
CacheStoreBenchmark.run(memcached_store, iterations: args[:iterations]&.to_i)
end
end
end
end