Skip to content

Commit

Permalink
Merge pull request #41 from solarwindscloud/NH-47948
Browse files Browse the repository at this point in the history
NH-47948: refactor test process of ruby agent
  • Loading branch information
xuan-cao-swi authored Jul 28, 2023
2 parents 8bd6e67 + 2568498 commit 6cb15b6
Show file tree
Hide file tree
Showing 45 changed files with 492 additions and 1,342 deletions.
58 changes: 0 additions & 58 deletions .github/workflows/docker-images.yml

This file was deleted.

7 changes: 1 addition & 6 deletions .github/workflows/test_on_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ jobs:
image: ghcr.io/${{ github.repository }}/apm_ruby_ubuntu

env:
SW_APM_GEM_TEST: true
SW_APM_REPORTER: file
SW_APM_COLLECTOR: /tmp/sw_apm_traces.bson
SW_APM_REPORTER_FILE_SINGLE: false
OBOE_STAGING: true
TEST_RUNS_TO_FILE: "true"
SW_APM_SERVICE_KEY: ${{ secret.DUMMY_SW_APM_SERVICE_KEY }}

steps:
- name: Checkout ${{ github.ref }}
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/verify_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ on:
description: 'Solarwinds apm version'

env:
SW_APM_GEM_TEST: true
SW_APM_REPORTER: file
SW_APM_COLLECTOR: /tmp/sw_apm_traces.bson
SW_APM_REPORTER_FILE_SINGLE: false
TEST_RUNS_TO_FILE: "true"
SW_APM_SERVICE_KEY: ${{ secrets.APM_RUBY_INSTALL_TESTING_SWO_KEY }}
SW_APM_COLLECTOR: apm.collector.cloud.solarwinds.com
MODE: ${{ github.event.inputs.install-registry }}
SOLARWINDS_APM_VERSION: ${{ github.event.inputs.solarwinds-version }}

Expand Down Expand Up @@ -61,7 +58,7 @@ jobs:
Name=xuan-cao-ec2-runner
verify_installation:
needs:
needs:
- start_arm64_runner
strategy:
fail-fast: false
Expand Down Expand Up @@ -93,6 +90,7 @@ jobs:
- hostname: rb3.0.2-ubuntu2204
image: ubuntu:22.04
exclude:
# alpine not yet supported on self-hosted runners https://github.com/actions/runner/issues/801
- hostname: rb3.0.6-alpine3.16
arch: arm64
- hostname: rb3.2.2-alpine3.17
Expand All @@ -111,7 +109,7 @@ jobs:
working-directory: .github/workflows/scripts
run: ./verify_install.sh
shell: sh


terminate_arm64_runner:
if: ${{ always() }}
Expand All @@ -130,4 +128,3 @@ jobs:
action: terminate
github-token: ${{ secrets.CI_GITHUB_TOKEN }}
matrix: ${{ needs.start_arm64_runner.outputs.matrix }} # passing a matrix will terminate all runners, not just one

86 changes: 50 additions & 36 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

The descriptions below assume you are in the locally cloned project root directory, i.e. `swotel-ruby`.

## Prerequisites

Prerequisites
* Docker
* Docker Compose

### Minimal Setup to Build the Gem
## Minimal Setup to Build the Gem

Start a standard ruby container with the working tree bind-mounted:
```bash
Expand All @@ -28,11 +27,12 @@ bundle install
bundle exec rake build_gem
```

### Comprehensive Testing and Debugging Setup
## Local Dev Environment Setup

This sets up a ruby development environment on your laptop, which we'll describe for [rbenv](https://github.com/rbenv/rbenv). Feel free to use other tools such as RVM. This setup is required to run the dev, linting and testing steps below.

This requires a ruby development environment set up on your laptop, which we'll describe for [rbenv](https://github.com/rbenv/rbenv). Feel free to use other tools such as RVM.
### 1. Install rbenv

#### Install rbenv
Mac
```bash
brew install rbenv ruby-build
Expand All @@ -50,7 +50,7 @@ echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc # for bash
echo 'eval "$(~/.rbenv/bin/rbenv init - zsh)"' >> ~/.zshrc # for zsh
```

#### Install and Set Ruby Runtime
### 2. Install and Set Ruby Runtime

Install ruby from rbenv:
```bash
Expand All @@ -76,7 +76,9 @@ rbenv global 3.1.2 # set the default Ruby version for this machine
rbenv local 3.1.2 # set the Ruby version for this directory
```

#### Run Test/Debug Containers
## Run Development Containers

Currently supports ubuntu development environment

Install bundler, configure it to skip unneeded groups then install the project dependencies:
```bash
Expand All @@ -85,9 +87,9 @@ bundle config set --local without development test
bundle install
```

Start the testing/debugging container and supporting services:
Starting the container
```bash
bundle exec rake docker
bundle exec rake docker_dev
```

In the container:
Expand Down Expand Up @@ -115,43 +117,55 @@ It will produce the file `rubocop_result.txt`. Issues found should be addressed

## Testing

Start the testing/debugging container and supporting services:
```bash
bundle exec rake docker
```
### 1. Run Testing Directly With Default Ruby Version (3.1.0)

In the container:
Install bundler, configure it to skip unneeded groups then install the project dependencies:
```bash
# install project gem dependencies
gem install bundler
bundle config set --local without development test
bundle install
```

# run all tests
test/run_otel_tests/run_tests
Starting the test
```bash
bundle exec rake docker_test [alpine|debian|ubuntu|amazonlinux] [{ruby_version}]
```

# run just the ruby 2.7.5 tests
test/run_otel_tests/run_tests -r 2.7.5
Example of running ruby 3.1.0 on alpine
```bash
bundle exec rake docker_test alpine 3.1.0
```

### Run a specific test file, or a specific test
### 2. Run Test/Debug Containers

While coding and for debugging it may be helpful to run fewer tests.
To run single tests the env needs to be set up and use `ruby -I test`
This section is applied if you wish to run specific test.

One file:
Install bundler, configure it to skip unneeded groups then install the project dependencies:
```bash
rbenv local 2.7.5
export BUNDLE_GEMFILE=gemfiles/delayed_job.gemfile
export DBTYPE=mysql # optional, defaults to postgresql
bundle
bundle exec rake cfc # download, compile oboe_api, and link liboboe
bundle exec ruby -I test test/unit/otel_config_propagator_test.rb
gem install bundler
bundle config set --local without development test
bundle install
```

A specific test:
Start the testing/debugging container and supporting services:
```bash
rbenv global 2.7.5
export BUNDLE_GEMFILE=gemfiles/libraries.gemfile
export DBTYPE=mysql
bundle
bundle exec ruby -I test test/unit/otel_config_test.rb -n /test_resolve_propagators_with_defaults/
bundle exec rake docker [alpine|debian|ubuntu|amazonlinux]
```

The default ruby version is 3.1.0, but you can install other ruby version through rbenv e.g. `rbenv install 2.7.0 && rbenv local 2.7.0`


In the container, execute the script:
```bash
test/run_otel_tests/ruby_setup.sh # Install ruby

test/run_otel_tests/run_tests.sh # Run the all test case

bundle exec ruby -I test test/unit/otel_config_propagator_test.rb # One file

bundle exec ruby -I test test/unit/otel_config_test.rb -n /test_resolve_propagators_with_defaults/ # A specific test
```

### Trouble-shooting

You may need to run `. ~/.profile` again to apply `rbenv` globally to all shell sessions
33 changes: 24 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,44 @@ Rake::TestTask.new do |t|
t.test_files = FileList['test/unit/*_test.rb'] +
FileList['test/component/*_test.rb']
end

end

desc 'Run all test suites defined by travis'
task :docker_test => :docker_tests

desc 'Start docker container for testing, os accepts: alpine, debian, ubuntu, amazonlinux as args, default: ubuntu.
It also accepts custom ruby versions, e.g. 2.7.5, 3.1.0, 3.2.2. default: 3.1.0
Example: bundle exec rake docker_tests alpine 3.2.2'
task :docker_tests, :environment do
_arg1, arg2 = ARGV
_arg1, arg2, arg3 = ARGV
os = arg2 || 'ubuntu'
rversion = arg3 || '3.1.0'

Dir.chdir('test/run_otel_tests')
exec("docker-compose down -v --remove-orphans && docker-compose run --service-ports \
--name ruby_sw_apm_#{os} ruby_sw_apm_#{os}")
end
--entrypoint test/run_otel_tests/ruby_setup.sh -e RUBY_VERSION=#{rversion} \
--name ruby_sw_otel_apm_#{os} ruby_sw_otel_apm_#{os}")

task :docker_test => :docker_tests
end

desc 'Start docker container for testing and debugging, accepts: alpine, debian, centos as args, default: ubuntu'
desc 'Start minimal setup docker container, accepts: alpine, debian, ubuntu, amazonlinux as args, default: ubuntu
In this container, you can install different version of ruby and switch the version for running test.'
task :docker, :environment do
_arg1, arg2 = ARGV
_arg1, arg2= ARGV
os = arg2 || 'ubuntu'

Dir.chdir('test/run_otel_tests')
exec("docker-compose down -v --remove-orphans && docker-compose run --service-ports \
--name ruby_sw_otel_apm_#{os} ruby_sw_otel_apm_#{os}")
--name ruby_sw_otel_apm_#{os} ruby_sw_otel_apm_#{os}")

end

task :docker_development => :docker_dev
desc 'Start ubuntu docker container for testing and debugging.'
task :docker_dev, :environment do

Dir.chdir('test/run_otel_tests')
exec("docker-compose down -v --remove-orphans && docker-compose run --service-ports \
--name ruby_sw_otel_apm_ubuntu_development ruby_sw_otel_apm_ubuntu_development")
end

desc 'Stop all containers that were started for testing and debugging'
Expand Down
Loading

0 comments on commit 6cb15b6

Please sign in to comment.