From 5c263cd4bb96b57ac5b98caa60f727304c637149 Mon Sep 17 00:00:00 2001 From: Jan Grodowski Date: Thu, 5 Dec 2024 18:06:23 +0100 Subject: [PATCH 1/3] Use rake for running minitests, add vscode debugging with ruby-lsp --- .github/workflows/tests.yml | 2 +- .gitignore | 1 - .vscode/launch.json | 21 +++++++++++++++++++++ Gemfile | 1 + Gemfile.lock | 2 ++ Makefile | 2 +- README.md | 2 +- test/main.rb | 36 ------------------------------------ test/test_helper.rb | 24 +++++++++++++++++++++++- 9 files changed, 50 insertions(+), 41 deletions(-) create mode 100644 .vscode/launch.json delete mode 100644 test/main.rb diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6e354b2b..60729ddd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: diff --git a/.gitignore b/.gitignore index 3e50b25c..4c44b1a2 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ bin/ .vagrant/ build/ .bundle/ -.vscode/ .idea .ipynb_checkpoints diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..f8e5b40f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Minitest - current line", + "type": "ruby_lsp", + "request": "launch", + "program": "rake test ${file}:${lineNumber}" + }, + { + "name": "Minitest - current file", + "type": "ruby_lsp", + "request": "launch", + "program": "rake test ${file}" + } + ] + } + \ No newline at end of file diff --git a/Gemfile b/Gemfile index b3cdbf46..2903d26b 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" group :test do gem "minitest" + gem "rake" gem "mysql2" gem "webrick" diff --git a/Gemfile.lock b/Gemfile.lock index c83f95e1..fd69a5fa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -40,6 +41,7 @@ DEPENDENCIES minitest-retry mysql2 pry-byebug + rake tqdm webrick diff --git a/Makefile b/Makefile index e9480578..244f6bde 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 3febd576..357b1070 100644 --- a/README.md +++ b/README.md @@ -67,4 +67,4 @@ Kindly take note of following options: Example: -`DEBUG=1 ruby test/main.rb -v -n "TrivialIntegrationTests#test_logged_query_omits_columns"` +`DEBUG=1 rake test -v -n "TrivialIntegrationTests#test_logged_query_omits_columns"` diff --git a/test/main.rb b/test/main.rb deleted file mode 100644 index eaad9d0c..00000000 --- a/test/main.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true -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") -integration_path = File.join(test_path, "integration") -test_files = Dir.glob("#{integration_path}/**/*_test.rb") - -$LOAD_PATH.unshift(test_path) unless $LOAD_PATH.include?(test_path) -$LOAD_PATH.unshift(test_lib_path) unless $LOAD_PATH.include?(test_lib_path) -$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path) -$LOAD_PATH.unshift(helpers_path) unless $LOAD_PATH.include?(helpers_path) - -require "ghostferry_helper" - -require "minitest" -require "minitest/reporters" -require "minitest/retry" -require "minitest/fail_fast" -require "minitest/hooks/test" - -Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new -Minitest::Retry.use!(exceptions_to_retry: [GhostferryHelper::Ghostferry::TimeoutError]) - -test_files.each do |f| - require f -end - -exit_code = 1 - -at_exit do - GhostferryHelper.remove_all_binaries - exit(exit_code) -end - -exit_code = Minitest.run(ARGV) diff --git a/test/test_helper.rb b/test/test_helper.rb index 9b9f8b4f..4254f696 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,15 +1,37 @@ 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") +# TODO: simplify the load paths??? +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") +$LOAD_PATH.unshift(test_path) unless $LOAD_PATH.include?(test_path) +$LOAD_PATH.unshift(test_lib_path) unless $LOAD_PATH.include?(test_lib_path) +$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path) +$LOAD_PATH.unshift(helpers_path) unless $LOAD_PATH.include?(helpers_path) + 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 From 2558f57c061bae325e46cc8339bf5cb0e7e043ca Mon Sep 17 00:00:00 2001 From: Jan Grodowski Date: Fri, 6 Dec 2024 11:57:45 +0100 Subject: [PATCH 2/3] Tidy up load path setup in test_helper, cleanup --- .vscode/launch.json | 8 +------- README.md | 18 ++++++++++++++++-- test/integration/trivial_test.rb | 2 +- test/test_helper.rb | 19 ++++++++++--------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index f8e5b40f..d40d24a5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,17 +4,11 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { - "name": "Minitest - current line", - "type": "ruby_lsp", - "request": "launch", - "program": "rake test ${file}:${lineNumber}" - }, { "name": "Minitest - current file", "type": "ruby_lsp", "request": "launch", - "program": "rake test ${file}" + "program": "rake test TEST=${file}" } ] } diff --git a/README.md b/README.md index 357b1070..74258aa8 100644 --- a/README.md +++ b/README.md @@ -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 rake test -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"` diff --git a/test/integration/trivial_test.rb b/test/integration/trivial_test.rb index 246d31ba..59e95303 100644 --- a/test/integration/trivial_test.rb +++ b/test/integration/trivial_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class TrivialIntegrationTests < GhostferryTestCase +class TrivialIntegrationTest < GhostferryTestCase def test_copy_data_without_any_writes_to_source seed_simple_database_with_single_table diff --git a/test/test_helper.rb b/test/test_helper.rb index 4254f696..a3a5ba5a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,15 +11,16 @@ GO_CODE_PATH = File.join(File.absolute_path(File.dirname(__FILE__)), "lib", "go") FIXTURE_PATH = File.join(File.absolute_path(File.dirname(__FILE__)), "fixtures") -# TODO: simplify the load paths??? -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") -$LOAD_PATH.unshift(test_path) unless $LOAD_PATH.include?(test_path) -$LOAD_PATH.unshift(test_lib_path) unless $LOAD_PATH.include?(test_lib_path) -$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path) -$LOAD_PATH.unshift(helpers_path) unless $LOAD_PATH.include?(helpers_path) +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" From b45dcdad9c6adb56688bfc2c8418a99d37fc62d3 Mon Sep 17 00:00:00 2001 From: Jan Grodowski Date: Fri, 6 Dec 2024 16:34:57 +0100 Subject: [PATCH 3/3] Revert .vscode launch settings, not needed with rake running minitests --- .gitignore | 1 + .vscode/launch.json | 15 --------------- 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.gitignore b/.gitignore index 4c44b1a2..3e50b25c 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ bin/ .vagrant/ build/ .bundle/ +.vscode/ .idea .ipynb_checkpoints diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index d40d24a5..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Minitest - current file", - "type": "ruby_lsp", - "request": "launch", - "program": "rake test TEST=${file}" - } - ] - } - \ No newline at end of file