Skip to content

Commit

Permalink
get tests working again
Browse files Browse the repository at this point in the history
  • Loading branch information
pcai committed Sep 29, 2024
1 parent 792db0a commit 4405a38
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 55 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby
{
"name": "Ruby",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/ruby:1-3.3-bullseye"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "ruby --version",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
81 changes: 45 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,51 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby:
- '2.5.8'
- '2.7.2'
- '3.0.0'
- '3.1.2'
- 'head'
gemfile:
- gemfiles/rails_5_1.gemfile
- gemfiles/rails_5_2.gemfile
- gemfiles/rails_6_0.gemfile
- gemfiles/rails_6_1.gemfile
- gemfiles/rails_7_0.gemfile
- gemfiles/rails_head.gemfile
exclude:
- ruby: "2.5.8"
gemfile: gemfiles/rails_7_0.gemfile
- ruby: "2.5.8"
gemfile: gemfiles/rails_head.gemfile
- ruby: "2.7.2"
gemfile: gemfiles/rails_head.gemfile
- ruby: "3.0.0"
gemfile: gemfiles/rails_5_1.gemfile
- ruby: "3.0.0"
gemfile: gemfiles/rails_5_2.gemfile
- ruby: "3.1.2"
gemfile: gemfiles/rails_5_1.gemfile
- ruby: "3.1.2"
gemfile: gemfiles/rails_5_2.gemfile
- ruby: "3.1.2"
gemfile: gemfiles/rails_6_0.gemfile
- ruby: "head"
gemfile: gemfiles/rails_5_1.gemfile
- ruby: "head"
gemfile: gemfiles/rails_5_2.gemfile
- ruby: "head"
gemfile: gemfiles/rails_6_0.gemfile
include:
- ruby: "2.5"
gemfile: gemfiles/rails_5_1.gemfile
- ruby: "2.5"
gemfile: gemfiles/rails_5_2.gemfile
# - ruby: "2.5"
# gemfile: gemfiles/rails_6_0.gemfile
# - ruby: "2.5"
# gemfile: gemfiles/rails_6_1.gemfile
- ruby: "2.7"
gemfile: gemfiles/rails_5_1.gemfile
- ruby: "2.7"
gemfile: gemfiles/rails_5_2.gemfile
- ruby: "2.7"
gemfile: gemfiles/rails_6_0.gemfile
- ruby: "2.7"
gemfile: gemfiles/rails_6_1.gemfile
- ruby: "2.7"
gemfile: gemfiles/rails_7_0.gemfile
- ruby: "3.0"
gemfile: gemfiles/rails_6_0.gemfile
- ruby: "3.0"
gemfile: gemfiles/rails_6_1.gemfile
- ruby: "3.0"
gemfile: gemfiles/rails_7_0.gemfile
- ruby: "3.1"
gemfile: gemfiles/rails_6_0.gemfile
- ruby: "3.1"
gemfile: gemfiles/rails_6_1.gemfile
- ruby: "3.1"
gemfile: gemfiles/rails_7_0.gemfile
- ruby: "3.2"
gemfile: gemfiles/rails_6_0.gemfile
- ruby: "3.2"
gemfile: gemfiles/rails_6_1.gemfile
- ruby: "3.2"
gemfile: gemfiles/rails_7_0.gemfile
- ruby: "3.3"
gemfile: gemfiles/rails_6_0.gemfile
- ruby: "3.3"
gemfile: gemfiles/rails_6_1.gemfile
- ruby: "3.3"
gemfile: gemfiles/rails_7_0.gemfile
- ruby: "head"
gemfile: gemfiles/rails_head.gemfile
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
steps:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD

- Repair tests, support ruby-statistics in ruby < 3.0 (https://github.com/zombocom/derailed_benchmarks/pull/241)

## 2.1.2

- Support rails 7 for bundle exec derailed exec mem (https://github.com/zombocom/derailed_benchmarks/pull/212)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source 'https://rubygems.org'
gemspec

group :development, :test do
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
gem "sqlite3", '~> 1.4', :platform => [:ruby, :mswin, :mingw]
gem "activerecord-jdbcsqlite3-adapter", '~> 1.3.13', :platform => :jruby
gem "test-unit", "~> 3.0"
end
15 changes: 13 additions & 2 deletions derailed_benchmarks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,26 @@ Gem::Specification.new do |gem|
gem.add_dependency "rack", ">= 1"
gem.add_dependency "rake", "> 10", "< 14"
gem.add_dependency "thor", ">= 0.19", "< 2"
gem.add_dependency "ruby-statistics", ">= 4.0"
if RUBY_VERSION >= '3.0'
gem.add_dependency "ruby-statistics", ">= 4.0"
else
gem.add_dependency "ruby-statistics", ">= 2.1"
end
gem.add_dependency "mini_histogram", ">= 0.3.0"
gem.add_dependency "dead_end", ">= 0"
gem.add_dependency "rack-test", ">= 0"
gem.add_dependency "base64", ">= 0"
gem.add_dependency "mutex_m", ">= 0"
gem.add_dependency "bigdecimal", ">= 0"
gem.add_dependency "drb", ">= 0"
gem.add_dependency "logger", ">= 0"
gem.add_dependency "ostruct", ">= 0"
gem.add_dependency "ruby2_keywords", ">= 0"

gem.add_development_dependency "appraisal"
gem.add_development_dependency "webrick", ">= 0"
gem.add_development_dependency "capybara", "~> 2"
gem.add_development_dependency "m"
gem.add_development_dependency "rails", "> 3", "<= 7"
gem.add_development_dependency "rails", "> 3", "< 7.1"
gem.add_development_dependency "devise", "> 3", "< 6"
end
3 changes: 2 additions & 1 deletion gemfiles/rails_6_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ source "https://rubygems.org"
gem "rails", "~> 6.0.0"

group :development, :test do
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
gem "sqlite3", '~> 1.4', platform: [:ruby, :mswin, :mingw]
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", platform: :jruby
gem "test-unit", "~> 3.0"
gem "psych", "~> 3.0"
end

gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_6_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gem "net-imap", require: false
gem "net-pop", require: false

group :development, :test do
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
gem "sqlite3", '~> 1.4', platform: [:ruby, :mswin, :mingw]
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", platform: :jruby
gem "test-unit", "~> 3.0"
end
Expand Down
4 changes: 2 additions & 2 deletions gemfiles/rails_7_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

source "https://rubygems.org"

gem "rails", "~> 7.0"
gem "rails", "~> 7.0.0"

group :development, :test do
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
gem "sqlite3", '~> 1.4', platform: [:ruby, :mswin, :mingw]
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", platform: :jruby
gem "test-unit", "~> 3.0"
end
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_head.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ group :development, :test do
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", platform: :jruby
gem "test-unit", "~> 3.0"
gem "rackup"
end

gemspec path: "../"
Expand Down
11 changes: 8 additions & 3 deletions lib/derailed_benchmarks/load_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
ActiveRecord::Migrator.migrations_paths = DERAILED_APP.paths['db/migrate'].to_a
ActiveRecord::Migration.verbose = true

if Rails.version >= "6.0"
# https://github.com/plataformatec/devise/blob/master/test/orm/active_record.rb
if Rails.version >= "7.1"
ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths).migrate
elsif Rails.version >= "6.0"
ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths, ActiveRecord::SchemaMigration).migrate
elsif Rails.version.start_with?("5.2")
ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths).migrate
Expand Down Expand Up @@ -90,15 +93,17 @@
CURL_HTTP_HEADER_ARGS = HTTP_HEADERS.map { |http_header_name, value| "-H \"#{http_header_name}: #{value}\"" }.join(" ")

require 'rack/test'
require 'rack/file'

DERAILED_APP = DerailedBenchmarks.add_auth(Object.class_eval { remove_const(:DERAILED_APP) })
if server = ENV["USE_SERVER"]
@port = (3000..3900).to_a.sample
puts "Port: #{ @port.inspect }"
puts "Server: #{ server.inspect }"
thread = Thread.new do
Rack::Server.start(app: DERAILED_APP, :Port => @port, environment: "none", server: server)
# rack 3 doesn't have Rack::Server
require 'rackup' unless defined?(Rack::Server)
server_class = defined?(Rack::Server) ? Rack::Server : Rackup::Server
server_class.start(app: DERAILED_APP, :Port => @port, environment: "none", server: server)
end
sleep 1

Expand Down
7 changes: 6 additions & 1 deletion lib/derailed_benchmarks/stats_from_dir.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# frozen_string_literal: true

require 'bigdecimal'
require 'ruby-statistics'
# keep this in sync with gemspec
if RUBY_VERSION >= '3.0'
require 'ruby-statistics'
else
require 'statistics'
end
require 'stringio'
require 'mini_histogram'
require 'mini_histogram/plot'
Expand Down
14 changes: 7 additions & 7 deletions test/integration/tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def rake(cmd, options = {})
test 'rails perf:library from git' do
# BUNDLE_GEMFILE="$(pwd)/gemfiles/rails_git.gemfile" bundle exec m test/integration/tasks_test.rb:<linenumber>

skip unless ENV['USING_RAILS_GIT']
skip # unless ENV['USING_RAILS_GIT']

env = { "TEST_COUNT" => 2, "DERAILED_SCRIPT_COUNT" => 2,
"SHAS_TO_TEST" => "fd9308a2925e862435859e1803e720e6eebe4bb6,aa85e897312396b5c6993d8092b9aff7faa93011"}
Expand All @@ -56,7 +56,7 @@ def rake(cmd, options = {})
test "rails perf:library with bad script" do
# BUNDLE_GEMFILE="$(pwd)/gemfiles/rails_git.gemfile" bundle exec m test/integration/tasks_test.rb:<linenumber>

skip unless ENV['USING_RAILS_GIT']
skip # unless ENV['USING_RAILS_GIT']

error = assert_raises {
env = { "DERAILED_SCRIPT" => "nopenopenop", "TEST_COUNT" => 2, "DERAILED_SCRIPT_COUNT" => 2,
Expand Down Expand Up @@ -120,18 +120,18 @@ def rake(cmd, options = {})
env = {
"PATH_TO_HIT" => 'foo_secret',
"TEST_COUNT" => "2",
"HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("admin:secret")}",
"HTTP_AUTHORIZATION" => "Basic #{Base64.strict_encode64("admin:secret")}",
"HTTP_CACHE_CONTROL" => "no-cache"
}
result = rake "perf:test", env: env
assert_match 'Endpoint: "foo_secret"', result
assert_match /"Authorization"=>"Basic YWRtaW46c2VjcmV0\\n"/ , result
assert_match /"Cache-Control"=>"no-cache"/ , result
assert_match (/"Authorization"=>"Basic YWRtaW46c2VjcmV0"/), result
assert_match (/"Cache-Control"=>"no-cache"/), result

env["USE_SERVER"] = "webrick"
result = rake "perf:test", env: env
assert_match /"Authorization"=>"Basic YWRtaW46c2VjcmV0\\n"/ , result
assert_match /"Cache-Control"=>"no-cache"/ , result
assert_match (/"Authorization"=>"Basic YWRtaW46c2VjcmV0"/), result
assert_match (/"Cache-Control"=>"no-cache"/), result
end

test 'USE_SERVER' do
Expand Down
4 changes: 3 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

# https://github.com/plataformatec/devise/blob/master/test/orm/active_record.rb
migrate_path = File.expand_path("../rails_app/db/migrate", __FILE__)
if Rails.version >= "6.0"
if Rails.version >= "7.1"
ActiveRecord::MigrationContext.new(migrate_path).migrate
elsif Rails.version >= "6.0"
ActiveRecord::MigrationContext.new(migrate_path, ActiveRecord::SchemaMigration).migrate
elsif Rails.version.start_with? "5.2"
ActiveRecord::MigrationContext.new(migrate_path).migrate
Expand Down

0 comments on commit 4405a38

Please sign in to comment.