Skip to content

Commit

Permalink
test: start simplecov before library code is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
zvkemp committed Jan 28, 2025
1 parent ce01f6d commit 7ce0306
Show file tree
Hide file tree
Showing 61 changed files with 94 additions and 35 deletions.
17 changes: 17 additions & 0 deletions .github/actions/test_gem/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ inputs:
required: false
type: boolean
default: false
coverage:
description: Enforce SimpleCov
required: false
type: boolean
default: true
minimum_coverage:
description: Minimum test coverage
required: false
type: string
default: 85
build:
description: Build gem
required: false
Expand Down Expand Up @@ -153,6 +163,13 @@ runs:
bundle exec rake rubocop
working-directory: "${{ steps.setup.outputs.gem_dir }}"

- name: Coverage
shell: bash
if: "${{ inputs.coverage == 'true' }}"
# This starts a new simplecov run which tracks nothing of its own,
# but merges with the existing coverage reports generated during testing.
run: "bundle exec ruby -rsimplecov -e 'SimpleCov.minimum_coverage(${{ inputs.minimum_coverage }})'"

- name: Build Gem
shell: bash
if: "${{ inputs.build == 'true' }}"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci-instrumentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ jobs:
- name: "Test Ruby 3.1"
uses: ./.github/actions/test_gem
with:
gem: "opentelemetry-instrumentation-${{ matrix.gem }}"
gem: "opentelemetry-instrumentation-${{ matrix.gem }}"
ruby: "3.1"
yard: true
rubocop: true
coverage: true
build: true
- name: "JRuby Filter"
id: jruby_skip
Expand Down
14 changes: 14 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'digest'

digest = Digest::MD5.new
digest.update('test')
digest.update(ENV.fetch('BUNDLE_GEMFILE', 'gemfile')) if ENV['APPRAISAL_INITIALIZED']

ENV['ENABLE_COVERAGE'] ||= '1'

if ENV['ENABLE_COVERAGE'].to_i.positive?
SimpleCov.command_name(digest.hexdigest)
SimpleCov.start do
add_filter %r{^/test/}
end
end
1 change: 1 addition & 0 deletions helpers/mysql/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/action_mailer/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'logger'
require 'bundler/setup'
Bundler.require(:default, :development, :test)
Expand Down
1 change: 1 addition & 0 deletions instrumentation/action_pack/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'logger'
require 'bundler/setup'
Bundler.require(:default, :development, :test)
Expand Down
1 change: 1 addition & 0 deletions instrumentation/action_view/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'logger'
require 'bundler/setup'
Bundler.require(:default, :development, :test)
Expand Down
1 change: 1 addition & 0 deletions instrumentation/active_job/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: Apache-2.0
ENV['OTEL_LOG_LEVEL'] ||= 'fatal'

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/active_record/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/active_support/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/all/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/aws_lambda/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/aws_sdk/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
4 changes: 1 addition & 3 deletions instrumentation/base/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

SimpleCov.start
SimpleCov.minimum_coverage 85

require 'opentelemetry-instrumentation-base'
require 'minitest/autorun'

Expand Down
1 change: 1 addition & 0 deletions instrumentation/bunny/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/concurrent_ruby/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/dalli/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/delayed_job/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'logger'
require 'bundler/setup'
Bundler.require(:default, :development, :test)
Expand Down
1 change: 1 addition & 0 deletions instrumentation/ethon/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/excon/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/faraday/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/grape/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/graphql/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/grpc/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/gruf/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'opentelemetry/sdk'
require 'minitest/autorun'
require 'webmock/minitest'
Expand Down
1 change: 1 addition & 0 deletions instrumentation/http/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/http_client/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/httpx/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/koala/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/lmdb/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/mongo/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/mysql2/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/net_http/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'net/http'
require 'bundler/setup'
Bundler.require(:default, :development, :test)
Expand Down
1 change: 1 addition & 0 deletions instrumentation/pg/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/que/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/racecar/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/rack/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)
require 'rack/events'
Expand Down
6 changes: 5 additions & 1 deletion instrumentation/rails/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ namespace :test do
t.libs << 'test/railtie'
t.test_files = FileList['test/railtie/**/*_test.rb']
end

task :start_coverage do
require 'simplecov'
end
end

desc 'Run all tests'
task test: %i[test:instrumentation test:railtie]
task test: %i[test:start_coverage test:instrumentation test:railtie]

YARD::Rake::YardocTask.new do |t|
t.stats_options = ['--list-undoc']
Expand Down
1 change: 1 addition & 0 deletions instrumentation/rails/test/instrumentation/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: Apache-2.0

require 'logger'
require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
4 changes: 2 additions & 2 deletions instrumentation/rails/test/railtie/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
ENV['RAILS_ENV'] = 'test'

require 'logger'
require 'simplecov'

require 'bundler/setup'
Bundler.require(:default, :development, :test)

require_relative '../../test/railtie/dummy/config/environment'
require 'rails/test_help'

SimpleCov.start
1 change: 1 addition & 0 deletions instrumentation/rake/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
1 change: 1 addition & 0 deletions instrumentation/rdkafka/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'simplecov'
require 'bundler/setup'
Bundler.require(:default, :development, :test)

Expand Down
Loading

0 comments on commit 7ce0306

Please sign in to comment.