diff --git a/Gemfile b/Gemfile index 44278e2..4f83974 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,8 @@ gem "puma", "~> 5.0" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] +gem "async" + group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", platforms: %i[ mri mingw x64_mingw ] @@ -27,4 +29,3 @@ group :development do # Speed up commands on slow machines / big apps [https://github.com/rails/spring] # gem "spring" end - diff --git a/Gemfile.lock b/Gemfile.lock index 39cc5d7..19db3ff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -66,19 +66,27 @@ GEM i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) + async (2.0.1) + console (~> 1.10) + io-event (~> 1.0.0) + timers (~> 4.1) builder (3.2.4) concurrent-ruby (1.1.9) + console (1.14.0) + fiber-local crass (1.0.6) debug (1.4.0) irb (>= 1.3.6) reline (>= 0.2.7) digest (3.1.0) erubi (1.10.0) + fiber-local (1.0.0) globalid (1.0.0) activesupport (>= 5.0) i18n (1.10.0) concurrent-ruby (~> 1.0) io-console (0.5.11) + io-event (1.0.5) io-wait (0.2.1) irb (1.4.1) reline (>= 0.3.0) @@ -155,6 +163,7 @@ GEM strscan (3.0.1) thor (1.2.1) timeout (0.2.0) + timers (4.3.3) tzinfo (2.0.4) concurrent-ruby (~> 1.0) websocket-driver (0.7.5) @@ -166,6 +175,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + async debug puma (~> 5.0) rails (~> 7.0.2, >= 7.0.2.3) diff --git a/README.md b/README.md index 7db80e4..ba82124 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,23 @@ # README -This README would normally document whatever steps are necessary to get the -application up and running. +Run `rails t test/models/my_model_test.rb` -Things you may want to cover: +The output is: -* Ruby version +``` + r t test/models/my_model_test.rb +Running 1 tests in a single process (parallelization threshold is 50) +Run options: --seed 2478 -* System dependencies +# Running: -* Configuration +uninitialized constant MyModelTest::MyModel -* Database creation + MyModel.run_something + ^^^^^^^ +uninitialized constant MyModelTest::MyModel -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... + MyModel.run_something + ^^^^^^^ +something +``` diff --git a/app/models/my_model.rb b/app/models/my_model.rb new file mode 100644 index 0000000..54c65f8 --- /dev/null +++ b/app/models/my_model.rb @@ -0,0 +1,5 @@ +class MyModel + def self.run_something + puts "something" + end +end diff --git a/config/environments/test.rb b/config/environments/test.rb index eb2f171..33e8d1f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -14,7 +14,7 @@ # Eager loading loads your whole application. When running a single test locally, # this probably isn't necessary. It's a good idea to do in a continuous integration # system, or in some way before deploying your code. - config.eager_load = ENV["CI"].present? + config.eager_load = false # Setting to true fixes the test failure # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true diff --git a/test/models/my_model_test.rb b/test/models/my_model_test.rb new file mode 100644 index 0000000..cb15097 --- /dev/null +++ b/test/models/my_model_test.rb @@ -0,0 +1,15 @@ +require "test_helper" + +class MyModelTest < ActiveSupport::TestCase + test "async run" do + Async do |task| + 3.times do |i| + task.async do + MyModel.run_something + rescue => e + puts e + end + end + end.wait + end +end