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

Reorganise Ruby tests #375

Merged
merged 3 commits into from
Dec 11, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
run: .github/workflows/start-mysql.sh

- name: Running Ruby tests
run: bundle exec ruby test/main.rb
run: bundle exec rake test

build-debs:
strategy:
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source "https://rubygems.org"

group :test do
gem "minitest"
gem "rake"
gem "mysql2"
gem "webrick"

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ GEM
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
rake (13.2.1)
ruby-progressbar (1.13.0)
tqdm (0.4.1)
webrick (1.8.1)
Expand All @@ -40,6 +41,7 @@ DEPENDENCIES
minitest-retry
mysql2
pry-byebug
rake
tqdm
webrick

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test-go:

test-ruby:
bundle install
bundle exec ruby test/main.rb
bundle exec rake test

test: test-go test-ruby

Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ Kindly take note of following options:
- `DEBUG=1`: To see more detailed debug output by `Ghostferry` live, as opposed
to only when the test fails. This is helpful for debugging hanging test.

Example:
Examples:

`DEBUG=1 ruby test/main.rb -v -n "TrivialIntegrationTests#test_logged_query_omits_columns"`
Run all tests

`rake test`

Run a single file

`rake test TEST=test/integration/trivial_test.rb`

or

`ruby -Itest test/integration/trivial_test.rb`

Run a specific test

`DEBUG=1 ruby -Itest test/integration/trivial_test.rb -n "TrivialIntegrationTest#test_logged_query_omits_columns"`
2 changes: 1 addition & 1 deletion test/integration/trivial_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class TrivialIntegrationTests < GhostferryTestCase
class TrivialIntegrationTest < GhostferryTestCase
Copy link
Member Author

Choose a reason for hiding this comment

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

TIL: ruby-lsp doesn't recognise test classes with plural names

def test_copy_data_without_any_writes_to_source
seed_simple_database_with_single_table

Expand Down
36 changes: 0 additions & 36 deletions test/main.rb

This file was deleted.

25 changes: 24 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
require "stringio"
require "logger"

require "minitest"
require "minitest/autorun"
require "minitest/reporters"
require "minitest/retry"
require "minitest/fail_fast"
require "minitest/hooks/test"
require "pry-byebug" unless ENV["CI"]

GO_CODE_PATH = File.join(File.absolute_path(File.dirname(__FILE__)), "lib", "go")
FIXTURE_PATH = File.join(File.absolute_path(File.dirname(__FILE__)), "fixtures")

def add_to_load_path(path)
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
end

test_path = File.expand_path(File.dirname(__FILE__))
test_lib_path = File.join(test_path, "lib")
lib_path = File.expand_path(File.join(test_path, "..", "lib"))
helpers_path = File.join(test_path, "helpers")

[test_path, test_lib_path, lib_path, helpers_path].each { add_to_load_path(_1) }

require "db_helper"
require "ghostferry_helper"
require "data_writer_helper"

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
Minitest::Retry.use!(exceptions_to_retry: [GhostferryHelper::Ghostferry::TimeoutError])

at_exit do
GhostferryHelper.remove_all_binaries
end

class LogCapturer
attr_reader :logger

Expand Down
Loading