Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci+fix: Test Rails 6.1 & 7.0 on Ruby 3.X runtimes #310

Merged
merged 6 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 85 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ executors:
- image: s12v/sns
- image: softwaremill/elasticmq-native
- image: mongo:5-focal
ruby_30_mysql2:
docker:
- image: cimg/ruby:3.0-node
environment:
DATABASE_URL: "mysql2://[email protected]:3306/ci_test"
- image: mariadb
environment:
MYSQL_DATABASE: 'ci_test'
MYSQL_USER: 'root'
MYSQL_PASSWORD: ''
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_PASSWORD: ''
MYSQL_ROOT_HOST: '%'
ruby_30_postgres:
docker:
- image: cimg/ruby:3.0-node
environment:
DATABASE_URL: "postgres://postgres:[email protected]:5432/ci_test"
- image: postgres
environment:
POSTGRES_PASSWORD: 'test'
POSTGRES_DB: 'ci_test'
ruby_31:
docker:
- image: cimg/ruby:3.1-node
Expand All @@ -68,6 +90,28 @@ executors:
- image: s12v/sns
- image: softwaremill/elasticmq-native
- image: mongo:5-focal
ruby_31_mysql2:
docker:
- image: cimg/ruby:3.1-node
environment:
DATABASE_URL: "mysql2://[email protected]:3306/ci_test"
- image: mariadb
environment:
MYSQL_DATABASE: 'ci_test'
MYSQL_USER: 'root'
MYSQL_PASSWORD: ''
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_PASSWORD: ''
MYSQL_ROOT_HOST: '%'
ruby_31_postgres:
docker:
- image: cimg/ruby:3.1-node
environment:
DATABASE_URL: "postgres://postgres:[email protected]:5432/ci_test"
- image: postgres
environment:
POSTGRES_PASSWORD: 'test'
POSTGRES_DB: 'ci_test'
ruby_32:
docker:
- image: cimg/ruby:3.2-node
Expand All @@ -83,6 +127,28 @@ executors:
- image: s12v/sns
- image: softwaremill/elasticmq-native
- image: mongo:5-focal
ruby_32_mysql2:
docker:
- image: cimg/ruby:3.2-node
environment:
DATABASE_URL: "mysql2://[email protected]:3306/ci_test"
- image: mariadb
environment:
MYSQL_DATABASE: 'ci_test'
MYSQL_USER: 'root'
MYSQL_PASSWORD: ''
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_PASSWORD: ''
MYSQL_ROOT_HOST: '%'
ruby_32_postgres:
docker:
- image: cimg/ruby:3.2-node
environment:
DATABASE_URL: "postgres://postgres:[email protected]:5432/ci_test"
- image: postgres
environment:
POSTGRES_PASSWORD: 'test'
POSTGRES_DB: 'ci_test'

commands:
setup:
Expand Down Expand Up @@ -279,7 +345,7 @@ workflows:
- stack: ruby_32
gemfile: "./gemfiles/sinatra_14.gemfile"

rails:
rails_ruby_2:
jobs:
- test_apprisal:
matrix:
Expand All @@ -292,3 +358,21 @@ workflows:
- "./gemfiles/rails_60.gemfile"
- "./gemfiles/rails_52.gemfile"
- "./gemfiles/rails_50.gemfile"
rails_ruby_3:
jobs:
- test_apprisal:
matrix:
parameters:
stack:
- ruby_30
- ruby_30_postgres
- ruby_30_mysql2
- ruby_31
- ruby_31_postgres
- ruby_31_mysql2
- ruby_32
- ruby_32_postgres
- ruby_32_mysql2
gemfile:
- "./gemfiles/rails_61.gemfile"
- "./gemfiles/rails_70.gemfile"
22 changes: 22 additions & 0 deletions gemfiles/rails_61.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file was generated by Appraisal

# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021

source "https://rubygems.org"

gem "rake"
gem "minitest", "5.9.1"
gem "minitest-reporters"
gem "webmock"
gem "puma"
gem "rubocop", "~> 1.9"
gem "rack-test"
gem "simplecov", "~> 0.21.2"
gem "mail", ">= 2.8.1"
gem "rails", ">= 6.1", "< 7.0"
gem "mysql2", "0.5.5"
gem "pg"
gem "sqlite3", "~> 1.4"

gemspec path: "../"
19 changes: 19 additions & 0 deletions gemfiles/rails_70.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# (c) Copyright IBM Corp. 2023

source "https://rubygems.org"

gem "rake"
gem "minitest", "5.9.1"
gem "minitest-reporters"
gem "webmock"
gem "puma"
gem "rubocop", "~> 1.9"
gem "rack-test"
gem "simplecov", "~> 0.21.2"
gem "mail", ">= 2.8.1"
gem "rails", ">= 7.0"
gem "mysql2", "0.5.5"
gem "pg"
gem "sqlite3", "~> 1.4"

gemspec path: "../"
4 changes: 2 additions & 2 deletions lib/instana/instrumentation/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module ActiveRecord
IGNORED_SQL = %w[BEGIN COMMIT SET].freeze
SANITIZE_REGEXP = /('[\s\S][^']*'|\d*\.\d+|\d+|NULL)/i.freeze

def log(sql, name = 'SQL', binds = [], *args)
def log(sql, name = 'SQL', binds = [], *args, **kwargs, &block)
call_payload = {
activerecord: {
adapter: @config[:adapter],
Expand All @@ -24,7 +24,7 @@ def log(sql, name = 'SQL', binds = [], *args)
call_payload[:activerecord][:binds] = mapped
end

maybe_trace(call_payload, name) { super(sql, name, binds, *args) }
maybe_trace(call_payload, name) { super(sql, name, binds, *args, **kwargs, &block) }
end

private
Expand Down
25 changes: 18 additions & 7 deletions test/instrumentation/rails_action_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@
class RailsActionMailerTest < Minitest::Test
class TestMailer < ActionMailer::Base
def sample_email
mail(
from: '[email protected]',
to: '[email protected]',
subject: 'Test Email',
body: 'Hello',
content_type: "text/html"
)
mail_version = Gem::Specification.find_by_name('mail').version
if mail_version >= Gem::Version.new('2.8.1')
Mail.new do
from '[email protected]'
to '[email protected]'
subject 'Test Email'
body 'Hello'
content_type "text/html"
end
else
mail(
from: '[email protected]',
to: '[email protected]',
subject: 'Test Email',
body: 'Hello',
content_type: "text/html"
)
end
end
end

Expand Down
40 changes: 40 additions & 0 deletions test/instrumentation/rails_action_view_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ def app

def setup
clear_all!
@framework_version = Gem::Specification.find_by_name('rails').version
@supported_framework_version = @framework_version < Gem::Version.new('6.1')
@execute_test_if_framework_version_is_supported = lambda {
unless @supported_framework_version
skip "Skipping this test because Rails version #{@framework_version} is not yet supported!"
end
}
@execute_test_only_if_framework_version_is_not_supported = lambda {
if @supported_framework_version
skip "Skipping this test because Rails version #{@framework_version} is already supported!"
end
}
end

def test_config_defaults
Expand All @@ -21,7 +33,25 @@ def test_config_defaults
assert_equal true, ::Instana.config[:action_view][:enabled]
end

def test_no_tracing_if_unsupported_version_only_render_is_ok
@execute_test_only_if_framework_version_is_not_supported.call

['/render_view', '/render_view_direct', '/render_partial', '/render_collection', '/render_file',
'/render_alternate_layout', '/render_json', '/render_xml',
'/render_rawbody', '/render_js'].each do |endpoint|
get endpoint
assert last_response.ok?
end

get '/render_partial_that_errors'
assert_equal false, last_response.ok?

spans = ::Instana.processor.queued_spans
assert_equal [], spans
end

def test_render_view
@execute_test_if_framework_version_is_supported.call
get '/render_view'
assert last_response.ok?

Expand All @@ -32,6 +62,7 @@ def test_render_view
end

def test_render_view_direct
@execute_test_if_framework_version_is_supported.call
get '/render_view_direct'
assert last_response.ok?

Expand All @@ -54,6 +85,7 @@ def test_render_nothing
end

def test_render_file
@execute_test_if_framework_version_is_supported.call
get '/render_file'
assert last_response.ok?

Expand All @@ -64,6 +96,7 @@ def test_render_file
end

def test_render_json
@execute_test_if_framework_version_is_supported.call
get '/render_json'
assert last_response.ok?

Expand All @@ -74,6 +107,7 @@ def test_render_json
end

def test_render_xml
@execute_test_if_framework_version_is_supported.call
get '/render_xml'
assert last_response.ok?

Expand All @@ -84,6 +118,7 @@ def test_render_xml
end

def test_render_body
@execute_test_if_framework_version_is_supported.call
get '/render_rawbody'
assert last_response.ok?

Expand All @@ -94,6 +129,7 @@ def test_render_body
end

def test_render_js
@execute_test_if_framework_version_is_supported.call
get '/render_js'
assert last_response.ok?

Expand All @@ -104,6 +140,7 @@ def test_render_js
end

def test_render_alternate_layout
@execute_test_if_framework_version_is_supported.call
get '/render_alternate_layout'
assert last_response.ok?

Expand All @@ -114,6 +151,7 @@ def test_render_alternate_layout
end

def test_render_partial
@execute_test_if_framework_version_is_supported.call
get '/render_partial'
assert last_response.ok?

Expand All @@ -124,6 +162,7 @@ def test_render_partial
end

def test_render_partial_that_errors
@execute_test_if_framework_version_is_supported.call
get '/render_partial_that_errors'
refute last_response.ok?

Expand All @@ -139,6 +178,7 @@ def test_render_partial_that_errors
end

def test_render_collection
@execute_test_if_framework_version_is_supported.call
get '/render_collection'
assert last_response.ok?

Expand Down
Loading
Loading