-
Notifications
You must be signed in to change notification settings - Fork 80
/
Rakefile
166 lines (143 loc) · 4.9 KB
/
Rakefile
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
# frozen_string_literal: true
require "bundler/gem_tasks"
# ==========================================================
# Packaging
# ==========================================================
GEMSPEC = eval(File.read("semian.gemspec")) # rubocop:disable Security/Eval
require "rubygems/package_task"
Gem::PackageTask.new(GEMSPEC) do |_pkg|
end
# ==========================================================
# Ruby Extension
# ==========================================================
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
require "semian/platform"
if Semian.sysv_semaphores_supported?
require "rake/extensiontask"
Rake::ExtensionTask.new("semian", GEMSPEC) do |ext|
ext.ext_dir = "ext/semian"
ext.lib_dir = "lib/semian"
end
desc "Build gem"
task build: :compile
else
desc "Build gem"
task :build do # rubocop:disable Rake/DuplicateTask
end
end
# ==========================================================
# Testing
# ==========================================================
require "rake/testtask"
Rake::TestTask.new("test") do |t|
t.libs = ["lib", "test"]
t.pattern = "test/**/*_test.rb"
t.warning = false
if ENV["CI"] || ENV["VERBOSE"]
t.options = "-v"
end
end
namespace :test do
Rake::TestTask.new("semian") do |t|
t.description = "Run common library tests without adapters"
t.libs = ["lib", "test"]
t.pattern = "test/*_test.rb"
t.warning = false
if ENV["CI"] || ENV["VERBOSE"]
t.options = "-v"
end
end
desc "Parallel tests. Use TEST_WORKERS and TEST_WORKER_NUM. TEST_WORKER_NUM in range from 1..TEST_WORKERS"
task :parallel do
workers = ENV.fetch("TEST_WORKERS", 1).to_i
worker = ENV.fetch("TEST_WORKER_NUM", 1).to_i
buckets = Array.new(workers) { [] }
# Fill the buckets
i = 0
files = Dir["test/*_test.rb"].entries.sort { |f| File.size(f) }
files.each do |f|
i = 0 if buckets.size == i
buckets[i] << f
i += 1
end
if worker < 1 || worker > workers
raise "TEST_WORKER_NUM is not correct: #{worker}. " \
"Check that it greater or equal 1 and less or equal TEST_WORKERS: #{workers}"
end
files = buckets[worker - 1].join(" ")
args = "-Ilib:test -r 'rake/rake_test_loader.rb' #{files} -v #{ENV.fetch("TESTOPTS", "")}"
ruby args do |ok, status|
if !ok && status.respond_to?(:signaled?) && status.signaled?
raise SignalException, status.termsig
elsif !ok
status = "Command failed with status (#{status.exitstatus})"
details = ": [ruby #{args}]"
message = status + details
raise message
end
end
end
end
# ==========================================================
# Documentation
# ==========================================================
require "rdoc/task"
RDoc::Task.new do |rdoc|
rdoc.rdoc_files.include("lib/*.rb", "ext/semian/*.c")
end
# ==========================================================
# Examples
# ==========================================================
namespace :examples do
desc "Run examples for net_http"
task :net_http do
Dir["examples/net_http/*.rb"].entries.each do |f|
ruby f do |ok, status|
if !ok && status.respond_to?(:signaled?) && status.signaled?
raise SignalException, status.termsig
elsif !ok
status = "Command failed with status (#{status.exitstatus})"
details = ": [ruby #{f}]"
message = status + details
raise message
end
end
end
end
desc "Run examples for activerecord-trilogy-adapter"
task :activerecord_trilogy_adapter do
Dir["examples/activerecord_trilogy_adapter/*.rb"].entries.each do |f|
ruby f do |ok, status|
if !ok && status.respond_to?(:signaled?) && status.signaled?
raise SignalException, status.termsig
elsif !ok
status = "Command failed with status (#{status.exitstatus})"
details = ": [ruby #{f}]"
message = status + details
raise message
end
end
end
end
end
desc "Run examples"
task examples: ["examples:net_http", "examples:activerecord_trilogy_adapter"]
task default: :build
task default: :test # rubocop:disable Rake/DuplicateTask
desc "Generate flamegrpahs for different versions"
task :flamegraph do
script = "scripts/benchmarks/flamegraph.rb"
flamegraph_parse_command = "flamegraph.pl --countname=ms --width=1400"
%x(ruby #{script} | #{flamegraph_parse_command} > without_semian.svg)
["v0.15.0", "v0.16.0", "v0.17.0", "main"].each do |ver|
%x(WITH_CIRCUIT_BREAKER_ENABLED=1 SEMIAN_VERSION=#{ver} ruby #{script} \
| #{flamegraph_parse_command} > semian_#{ver}_enabled.svg)
end
end
desc "Run benchmarks for specific versions"
task :benchmark do
["v0.15.0", "v0.16.0", "v0.17.0", "main"].each do |ver|
ruby "scripts/benchmarks/net_http_acquire_benchmarker.rb SEMIAN_VERSION=#{ver}"
ruby "scripts/benchmarks/lru_benchmarker.rb SEMIAN_VERSION=#{ver}"
end
end