Skip to content
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
4 changes: 0 additions & 4 deletions .github/workflows/rubocop-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ jobs:
with:
ruby-version: '3.1.0'

# This step is not necessary if you add the gem to your Gemfile
- name: Install Code Scanning integration
run: bundle add code-scanning-rubocop --skip-install

- name: Install dependencies
run: |
bundle install
Expand Down
29 changes: 9 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,14 @@ On the host machine, you can use the `docker_tests` Rake task to run the test su

### Run Test Suite

Run the test suite:
Run the test suite (some test cases rely on env `APM_RUBY_TEST_KEY`):

```bash
# run tests in a ruby:3.1.0-bullseye container
bundle exec rake docker_tests

# run tests in a ruby:2.7.5 container
bundle exec rake 'docker_tests[2.7.5]'
bundle exec rake 'docker_tests[,,,APM_RUBY_TEST_KEY=your_service_key]'

# run tests in a ruby:3.2-alpine linux/amd64 container
bundle exec rake 'docker_tests[3.2-alpine,,linux/amd64]'
bundle exec rake 'docker_tests[3.2-alpine,,linux/amd64,APM_RUBY_TEST_KEY=your_service_key]'
```

Test logs are written to the project's `log` directory, which is bind mounted and available on the host machine.
Expand All @@ -159,25 +156,17 @@ In the container, set up the environment:
test/test_setup.sh
```

To run the full suite:
To run the full suite (some test cases rely on env `APM_RUBY_TEST_KEY`):

```bash
test/run_tests.sh
APM_RUBY_TEST_KEY=your_service_key test/run_tests.sh
```

To run a single test file:
To run a single test file or single test case:

```bash
# most tests require just the unit.gemfile dependencies
BUNDLE_GEMFILE=gemfiles/unit.gemfile bundle update

BUNDLE_GEMFILE=gemfiles/unit.gemfile bundle exec ruby -I test test/opentelemetry/solarwinds_propagator_test.rb
```

To run a specific test with 'trace_state_header' inside test case name:

```bash
BUNDLE_GEMFILE=gemfiles/unit.gemfile bundle update

BUNDLE_GEMFILE=gemfiles/unit.gemfile bundle exec ruby -I test test/opentelemetry/solarwinds_propagator_test.rb -n /trace_state_header/
bundle update
bundle exec ruby -I test test/opentelemetry/solarwinds_propagator_test.rb
bundle exec ruby -I test test/opentelemetry/solarwinds_propagator_test.rb -n /trace_state_header/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice you're already updating CONTRIB. How about noting the required env vars when running tests locally?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

```
40 changes: 34 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,45 @@

source 'https://rubygems.org'

# this Gemfile is very minimal
# use rake commands or gemfiles in the gemfiles directory for testing

gem 'rake', '>= 0.9.0'
gem 'rake'

group :development, :test do
if RUBY_VERSION < '3.0.0'
gem 'ffi', '<= 1.16.3' # set this version due to ffi 1.17.0 need rubygems version > 3 (https://rubygems.org/gems/ffi/versions/1.17.0-arm-linux-musl)
gem 'google-protobuf', '< 3.25.4'
elsif RUBY_VERSION < '3.1.0'
gem 'ffi', '<= 1.17'
else
gem 'ffi'
end
gem 'benchmark-ips', '>= 2.7.2'
gem 'bson'
gem 'byebug', '>= 8.0.0'
gem 'irb', '>= 1.0.0' # if RUBY_VERSION >= '2.6.0'
gem 'e2mmap'
gem 'get_process_mem'
gem 'irb', '>= 1.0.0'
gem 'logging'
gem 'lumberjack'
gem 'memory_profiler'
gem 'rubocop'
gem 'minitest', '< 5.25.0'
gem 'minitest-debugger', require: false
gem 'minitest-focus', '>= 1.1.2'
gem 'minitest-hooks', '>= 1.5.0'
gem 'minitest-reporters', '< 1.0.18'
gem 'mocha'
gem 'rack-cache'
gem 'rack-test'
gem 'rubocop', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rake', require: false
gem 'code-scanning-rubocop', '~> 0.6.1'
gem 'simplecov', require: false, group: :test
gem 'simplecov-console', require: false, group: :test
gem 'webmock' if RUBY_VERSION >= '2.0.0'
gem 'base64' if RUBY_VERSION >= '3.4.0'

gem 'opentelemetry-propagator-b3'
gem 'opentelemetry-test-helpers'

gemspec
end
21 changes: 16 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,27 @@ argument can be used to override the image architecture if multi-platform is sup
tag: any available image tag e.g. 3.2-bookworm, 2.7.5-alpine3.15, etc. default: 3.1-bullseye.
runtests: true or false. default: true.
platform: run image for specified OS/Arch, e.g. linux/amd64. default: none.
env_vars: comma-separated list of environment variables in KEY=VALUE format. default: none.

Example:
bundle exec rake docker_tests
bundle exec rake 'docker_tests[3.3-rc]'
bundle exec rake 'docker_tests[,false]'
bundle exec rake 'docker_tests[2.7.6-alpine3.15,,linux/amd64]'"
task :docker_tests, [:tag, :runtests, :platform] do |_, args|
bundle exec rake 'docker_tests[,,,APM_RUBY_TEST_KEY=your_service_key]'
bundle exec rake 'docker_tests[3.3-rc,,,APM_RUBY_TEST_KEY=your_service_key]'
bundle exec rake 'docker_tests[,false,,APM_RUBY_TEST_KEY=your_service_key]'
bundle exec rake 'docker_tests[2.7.6-alpine3.15,,linux/amd64,APM_RUBY_TEST_KEY=your_service_key]'
bundle exec rake 'docker_tests[3.1-bullseye,true,,APM_RUBY_TEST_KEY=your_service_key]'"
task :docker_tests, [:tag, :runtests, :platform, :env_vars] do |_, args|
args.with_defaults(tag: '3.1-bullseye', runtests: 'true')
opt = +' --rm --tty --volume $PWD:/code/ruby-solarwinds --workdir /code/ruby-solarwinds'
opt << " --platform #{args.platform}" unless args.platform.to_s.empty?

# Add custom environment variables if provided
unless args.env_vars.to_s.empty?
env_vars = args.env_vars.split(',').map(&:strip)
env_vars.each do |env_var|
opt << " -e #{env_var}" if env_var.include?('=')
end
end

if args.runtests == 'true'
opt << ' --entrypoint test/test_setup.sh -e RUN_TESTS=1'
else
Expand Down
51 changes: 0 additions & 51 deletions gemfiles/test_gems.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/unit.gemfile

This file was deleted.

2 changes: 0 additions & 2 deletions test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ ARG BUNDLE_RUBYGEMS__PKG__GITHUB__COM
ENV TZ=America/Vancouver
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ENV SW_APM_REPORTER=file

# install OS packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
Expand Down
3 changes: 3 additions & 0 deletions test/api/custom_instrumentation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
it 'test_custom_instrumentation_simple_case' do
class MyClass
include SolarWindsAPM::API::Tracer

def new_method(param1, param2)
param1 + param2
end
Expand All @@ -54,6 +55,7 @@ def new_method(param1, param2)
it 'test_custom_instrumentation_simple_case_with_custom_name_and_options' do
class MyClass
include SolarWindsAPM::API::Tracer

def new_method(param1, param2)
param1 + param2
end
Expand Down Expand Up @@ -83,6 +85,7 @@ def self.new_method(param1, param2)

class << self
include SolarWindsAPM::API::Tracer

add_tracer :new_method, 'custom_name', { attributes: { 'foo' => 'bar' }, kind: :unknown }
end
end
Expand Down
12 changes: 10 additions & 2 deletions test/api/tracing_ready_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@
@memory_exporter = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
OpenTelemetry.tracer_provider.add_span_processor(OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(@memory_exporter))

if ENV.key?('APM_RUBY_TEST_STAGING_KEY')
collector = 'https://apm.collector.st-ssp.solarwinds.com:443'
headers = ENV['APM_RUBY_TEST_STAGING_KEY']
else
collector = 'https://apm.collector.cloud.solarwinds.com:443'
headers = ENV.fetch('APM_RUBY_TEST_KEY', nil)
end

@config = {
collector: 'https://apm.collector.st-ssp.solarwinds.com:443',
collector: collector,
service: 'test-ruby',
headers: "Bearer #{ENV.fetch('APM_RUBY_TEST_STAGING_KEY', nil)}",
headers: "Bearer #{headers}",
tracing_mode: true,
trigger_trace_enabled: true
}
Expand Down
21 changes: 2 additions & 19 deletions test/initest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,11 @@
require 'minitest/spec'
require 'minitest/reporters'
require './lib/solarwinds_apm/logger'
require 'simplecov'
SimpleCov.start

ENV['SW_APM_SERVICE_KEY'] = 'this-is-a-dummy-api-token-for-testing-111111111111111111111111111111111:test-service'

# write to a file as well as STDOUT (comes in handy with docker runs)
# This approach preserves the coloring of pass fail, which the cli
# `./run_tests.sh 2>&1 | tee -a test/docker_test.log` does not
if ENV['TEST_RUNS_TO_FILE']
FileUtils.mkdir_p('log') # create if it doesn't exist
$out_file = if ENV['TEST_RUNS_FILE_NAME']
File.new(ENV['TEST_RUNS_FILE_NAME'], 'a')
else
File.new("log/test_direct_runs_#{Time.now.strftime('%Y%m%d_%H_%M')}.log", 'a')
end
$out_file.sync = true
$stdout.sync = true

def $stdout.write(string)
$out_file.write(string)
super
end
end

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

$LOAD_PATH.unshift("#{Dir.pwd}/lib/")
Expand Down
Loading