From cd9f0f43d1b1d3c9717fed433571458c374c3923 Mon Sep 17 00:00:00 2001 From: Michael van Rooijen Date: Fri, 15 Nov 2024 10:52:56 +0100 Subject: [PATCH] Test against SolidQueue 1 --- .github/workflows/main.yml | 11 +- Appraisals | 6 + Rakefile | 2 +- gemfiles/solid_queue_1.gemfile | 20 ++ gemfiles/solid_queue_1.gemfile.lock | 288 ++++++++++++++++++ test/env/rails_solid_queue_1/.gitignore | 1 + test/env/rails_solid_queue_1/Rakefile | 3 + .../rails_solid_queue_1/app/jobs/basic_job.rb | 4 + .../app/jobs/blocked_job.rb | 7 + test/env/rails_solid_queue_1/bin/rails | 4 + test/env/rails_solid_queue_1/config.ru | 2 + .../rails_solid_queue_1/config/application.rb | 14 + test/env/rails_solid_queue_1/config/boot.rb | 3 + .../rails_solid_queue_1/config/database.yml | 6 + .../rails_solid_queue_1/config/environment.rb | 2 + ...0231021073152_create_solid_queue_tables.rb | 131 ++++++++ test/hirefire/macro/test_solid_queue.rb | 39 ++- 17 files changed, 529 insertions(+), 14 deletions(-) create mode 100644 gemfiles/solid_queue_1.gemfile create mode 100644 gemfiles/solid_queue_1.gemfile.lock create mode 100644 test/env/rails_solid_queue_1/.gitignore create mode 100644 test/env/rails_solid_queue_1/Rakefile create mode 100644 test/env/rails_solid_queue_1/app/jobs/basic_job.rb create mode 100644 test/env/rails_solid_queue_1/app/jobs/blocked_job.rb create mode 100755 test/env/rails_solid_queue_1/bin/rails create mode 100644 test/env/rails_solid_queue_1/config.ru create mode 100644 test/env/rails_solid_queue_1/config/application.rb create mode 100644 test/env/rails_solid_queue_1/config/boot.rb create mode 100644 test/env/rails_solid_queue_1/config/database.yml create mode 100644 test/env/rails_solid_queue_1/config/environment.rb create mode 100644 test/env/rails_solid_queue_1/db/migrate/20231021073152_create_solid_queue_tables.rb diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e5afce9..47e548e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -62,9 +62,16 @@ jobs: - sidekiq_6 - sidekiq_7 - solid_queue_0 + - solid_queue_1 exclude: - - ruby-version: 2.7 - appraisal: good_job_4 + - appraisal: solid_queue_1 + ruby-version: 2.7 + - appraisal: solid_queue_1 + ruby-version: 3.0 + - appraisal: solid_queue_1 + ruby-version: 3.1 + - appraisal: good_job_4 + ruby-version: 2.7 steps: - name: Check out repository uses: actions/checkout@v4 diff --git a/Appraisals b/Appraisals index 86c61af..de0a96b 100644 --- a/Appraisals +++ b/Appraisals @@ -87,3 +87,9 @@ appraise "solid_queue_0" do gem "rails", "~> 7" gem "solid_queue", "< 0.2", require: false end + +appraise "solid_queue_1" do + gem "pg" + gem "rails", "~> 8" + gem "solid_queue", "~> 1", require: false +end diff --git a/Rakefile b/Rakefile index da5770e..230054f 100644 --- a/Rakefile +++ b/Rakefile @@ -45,7 +45,7 @@ APPRAISAL_FILES = { APPRAISAL_VERSIONS = { "rack" => %w[2 3], - "solid_queue" => %w[0], + "solid_queue" => %w[0 1], "sidekiq" => %w[6 7], "bunny" => %w[2], "good_job" => %w[2 3 4], diff --git a/gemfiles/solid_queue_1.gemfile b/gemfiles/solid_queue_1.gemfile new file mode 100644 index 0000000..66e8fb9 --- /dev/null +++ b/gemfiles/solid_queue_1.gemfile @@ -0,0 +1,20 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "debug" +gem "rake" +gem "standardrb" +gem "minitest" +gem "webmock" +gem "mocha" +gem "timecop" +gem "yard" +gem "rack" +gem "webrick" +gem "simplecov", require: false +gem "pg" +gem "rails", "~> 8" +gem "solid_queue", "~> 1", require: false + +gemspec path: "../" diff --git a/gemfiles/solid_queue_1.gemfile.lock b/gemfiles/solid_queue_1.gemfile.lock new file mode 100644 index 0000000..50e7eaa --- /dev/null +++ b/gemfiles/solid_queue_1.gemfile.lock @@ -0,0 +1,288 @@ +PATH + remote: .. + specs: + hirefire-resource (1.0.4) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (8.0.0) + actionpack (= 8.0.0) + activesupport (= 8.0.0) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (8.0.0) + actionpack (= 8.0.0) + activejob (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) + mail (>= 2.8.0) + actionmailer (8.0.0) + actionpack (= 8.0.0) + actionview (= 8.0.0) + activejob (= 8.0.0) + activesupport (= 8.0.0) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.0.0) + actionview (= 8.0.0) + activesupport (= 8.0.0) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.0.0) + actionpack (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (8.0.0) + activesupport (= 8.0.0) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (8.0.0) + activesupport (= 8.0.0) + globalid (>= 0.3.6) + activemodel (8.0.0) + activesupport (= 8.0.0) + activerecord (8.0.0) + activemodel (= 8.0.0) + activesupport (= 8.0.0) + timeout (>= 0.4.0) + activestorage (8.0.0) + actionpack (= 8.0.0) + activejob (= 8.0.0) + activerecord (= 8.0.0) + activesupport (= 8.0.0) + marcel (~> 1.0) + activesupport (8.0.0) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + ast (2.4.2) + base64 (0.2.0) + benchmark (0.4.0) + bigdecimal (3.1.8) + builder (3.3.0) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + crack (1.0.0) + bigdecimal + rexml + crass (1.0.6) + date (3.4.0) + debug (1.9.2) + irb (~> 1.10) + reline (>= 0.3.8) + docile (1.4.1) + drb (2.2.1) + erubi (1.13.0) + et-orbi (1.2.11) + tzinfo + fugit (1.11.1) + et-orbi (~> 1, >= 1.2.11) + raabro (~> 1.4) + globalid (1.2.1) + activesupport (>= 6.1) + hashdiff (1.1.1) + i18n (1.14.6) + concurrent-ruby (~> 1.0) + io-console (0.7.2) + irb (1.14.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + json (2.8.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + logger (1.6.1) + loofah (2.23.1) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + mini_mime (1.1.5) + minitest (5.25.1) + mocha (2.5.0) + ruby2_keywords (>= 0.0.5) + net-imap (0.5.1) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.4) + nokogiri (1.16.7-arm64-darwin) + racc (~> 1.4) + parallel (1.26.3) + parser (3.3.6.0) + ast (~> 2.4.1) + racc + pg (1.5.9) + psych (5.2.0) + stringio + public_suffix (6.0.1) + raabro (1.4.0) + racc (1.8.1) + rack (3.1.8) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.2.0) + rack (>= 3) + rails (8.0.0) + actioncable (= 8.0.0) + actionmailbox (= 8.0.0) + actionmailer (= 8.0.0) + actionpack (= 8.0.0) + actiontext (= 8.0.0) + actionview (= 8.0.0) + activejob (= 8.0.0) + activemodel (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) + bundler (>= 1.15.0) + railties (= 8.0.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (8.0.0) + actionpack (= 8.0.0) + activesupport (= 8.0.0) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.2.1) + rdoc (6.7.0) + psych (>= 4.0.0) + regexp_parser (2.9.2) + reline (0.5.11) + io-console (~> 0.5) + rexml (3.3.9) + rubocop (1.66.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.4, < 3.0) + rubocop-ast (>= 1.32.2, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.35.0) + parser (>= 3.3.1.0) + rubocop-performance (1.22.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + securerandom (0.3.2) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.13.1) + simplecov_json_formatter (0.1.4) + solid_queue (1.0.1) + activejob (>= 7.1) + activerecord (>= 7.1) + concurrent-ruby (>= 1.3.1) + fugit (~> 1.11.0) + railties (>= 7.1) + thor (~> 1.3.1) + standard (1.41.1) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.66.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.5) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.5.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.22.0) + standardrb (1.0.1) + standard + stringio (3.1.2) + thor (1.3.2) + timecop (0.9.8) + timeout (0.4.2) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.6.0) + uri (1.0.1) + useragent (0.16.10) + webmock (3.24.0) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + webrick (1.8.1) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + yard (0.9.37) + zeitwerk (2.7.1) + +PLATFORMS + arm64-darwin-24 + +DEPENDENCIES + appraisal (~> 2) + debug + hirefire-resource! + minitest + mocha + pg + rack + rails (~> 8) + rake + simplecov + solid_queue (~> 1) + standardrb + timecop + webmock + webrick + yard + +BUNDLED WITH + 2.4.7 diff --git a/test/env/rails_solid_queue_1/.gitignore b/test/env/rails_solid_queue_1/.gitignore new file mode 100644 index 0000000..cad2309 --- /dev/null +++ b/test/env/rails_solid_queue_1/.gitignore @@ -0,0 +1 @@ +/tmp \ No newline at end of file diff --git a/test/env/rails_solid_queue_1/Rakefile b/test/env/rails_solid_queue_1/Rakefile new file mode 100644 index 0000000..d1baef0 --- /dev/null +++ b/test/env/rails_solid_queue_1/Rakefile @@ -0,0 +1,3 @@ +require_relative "config/application" + +Rails.application.load_tasks diff --git a/test/env/rails_solid_queue_1/app/jobs/basic_job.rb b/test/env/rails_solid_queue_1/app/jobs/basic_job.rb new file mode 100644 index 0000000..d1522f9 --- /dev/null +++ b/test/env/rails_solid_queue_1/app/jobs/basic_job.rb @@ -0,0 +1,4 @@ +class BasicJob < ActiveJob::Base + def perform + end +end diff --git a/test/env/rails_solid_queue_1/app/jobs/blocked_job.rb b/test/env/rails_solid_queue_1/app/jobs/blocked_job.rb new file mode 100644 index 0000000..b228a5a --- /dev/null +++ b/test/env/rails_solid_queue_1/app/jobs/blocked_job.rb @@ -0,0 +1,7 @@ +class BlockedJob < ActiveJob::Base + BLOCK_DURATION = 10.seconds + limits_concurrency to: 1, key: "ratelimit", duration: BLOCK_DURATION + + def perform + end +end diff --git a/test/env/rails_solid_queue_1/bin/rails b/test/env/rails_solid_queue_1/bin/rails new file mode 100755 index 0000000..efc0377 --- /dev/null +++ b/test/env/rails_solid_queue_1/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/test/env/rails_solid_queue_1/config.ru b/test/env/rails_solid_queue_1/config.ru new file mode 100644 index 0000000..cb0bc69 --- /dev/null +++ b/test/env/rails_solid_queue_1/config.ru @@ -0,0 +1,2 @@ +require_relative "config/environment" +run Rails.application diff --git a/test/env/rails_solid_queue_1/config/application.rb b/test/env/rails_solid_queue_1/config/application.rb new file mode 100644 index 0000000..89ce0f6 --- /dev/null +++ b/test/env/rails_solid_queue_1/config/application.rb @@ -0,0 +1,14 @@ +require_relative "boot" + +require "active_support/railtie" +require "active_job/railtie" +require "active_record/railtie" + +require "solid_queue" + +class RailsSolidQueue1Application < Rails::Application + config.load_defaults 8.0 + config.root = File.expand_path("../..", __FILE__) + config.eager_load = false + config.active_job.queue_adapter = :solid_queue +end diff --git a/test/env/rails_solid_queue_1/config/boot.rb b/test/env/rails_solid_queue_1/config/boot.rb new file mode 100644 index 0000000..ca86f6c --- /dev/null +++ b/test/env/rails_solid_queue_1/config/boot.rb @@ -0,0 +1,3 @@ +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../gemfiles/solid_queue_1.gemfile", __dir__) + +require "bundler/setup" diff --git a/test/env/rails_solid_queue_1/config/database.yml b/test/env/rails_solid_queue_1/config/database.yml new file mode 100644 index 0000000..4f73e73 --- /dev/null +++ b/test/env/rails_solid_queue_1/config/database.yml @@ -0,0 +1,6 @@ +test: + adapter: postgresql + host: localhost + database: rails_solid_queue_1_test_database + username: <%= ENV["POSTGRES_USER"] %> + password: <%= ENV["POSTGRES_PASSWORD"] %> diff --git a/test/env/rails_solid_queue_1/config/environment.rb b/test/env/rails_solid_queue_1/config/environment.rb new file mode 100644 index 0000000..40c19d2 --- /dev/null +++ b/test/env/rails_solid_queue_1/config/environment.rb @@ -0,0 +1,2 @@ +require_relative "application" +Rails.application.initialize! diff --git a/test/env/rails_solid_queue_1/db/migrate/20231021073152_create_solid_queue_tables.rb b/test/env/rails_solid_queue_1/db/migrate/20231021073152_create_solid_queue_tables.rb new file mode 100644 index 0000000..7086e5d --- /dev/null +++ b/test/env/rails_solid_queue_1/db/migrate/20231021073152_create_solid_queue_tables.rb @@ -0,0 +1,131 @@ +class CreateSolidQueueTables < ActiveRecord::Migration[8.0] + def change + create_table "solid_queue_blocked_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.string "concurrency_key", null: false + t.datetime "expires_at", null: false + t.datetime "created_at", null: false + t.index ["concurrency_key", "priority", "job_id"], name: "index_solid_queue_blocked_executions_for_release" + t.index ["expires_at", "concurrency_key"], name: "index_solid_queue_blocked_executions_for_maintenance" + t.index ["job_id"], name: "index_solid_queue_blocked_executions_on_job_id", unique: true + end + + create_table "solid_queue_claimed_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.bigint "process_id" + t.datetime "created_at", null: false + t.index ["job_id"], name: "index_solid_queue_claimed_executions_on_job_id", unique: true + t.index ["process_id", "job_id"], name: "index_solid_queue_claimed_executions_on_process_id_and_job_id" + end + + create_table "solid_queue_failed_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.text "error" + t.datetime "created_at", null: false + t.index ["job_id"], name: "index_solid_queue_failed_executions_on_job_id", unique: true + end + + create_table "solid_queue_jobs", force: :cascade do |t| + t.string "queue_name", null: false + t.string "class_name", null: false + t.text "arguments" + t.integer "priority", default: 0, null: false + t.string "active_job_id" + t.datetime "scheduled_at" + t.datetime "finished_at" + t.string "concurrency_key" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["active_job_id"], name: "index_solid_queue_jobs_on_active_job_id" + t.index ["class_name"], name: "index_solid_queue_jobs_on_class_name" + t.index ["finished_at"], name: "index_solid_queue_jobs_on_finished_at" + t.index ["queue_name", "finished_at"], name: "index_solid_queue_jobs_for_filtering" + t.index ["scheduled_at", "finished_at"], name: "index_solid_queue_jobs_for_alerting" + end + + create_table "solid_queue_pauses", force: :cascade do |t| + t.string "queue_name", null: false + t.datetime "created_at", null: false + t.index ["queue_name"], name: "index_solid_queue_pauses_on_queue_name", unique: true + end + + create_table "solid_queue_processes", force: :cascade do |t| + t.string "kind", null: false + t.datetime "last_heartbeat_at", null: false + t.bigint "supervisor_id" + t.integer "pid", null: false + t.string "hostname" + t.text "metadata" + t.datetime "created_at", null: false + t.string "name", null: false + t.index ["last_heartbeat_at"], name: "index_solid_queue_processes_on_last_heartbeat_at" + t.index ["name", "supervisor_id"], name: "index_solid_queue_processes_on_name_and_supervisor_id", unique: true + t.index ["supervisor_id"], name: "index_solid_queue_processes_on_supervisor_id" + end + + create_table "solid_queue_ready_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.datetime "created_at", null: false + t.index ["job_id"], name: "index_solid_queue_ready_executions_on_job_id", unique: true + t.index ["priority", "job_id"], name: "index_solid_queue_poll_all" + t.index ["queue_name", "priority", "job_id"], name: "index_solid_queue_poll_by_queue" + end + + create_table "solid_queue_recurring_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "task_key", null: false + t.datetime "run_at", null: false + t.datetime "created_at", null: false + t.index ["job_id"], name: "index_solid_queue_recurring_executions_on_job_id", unique: true + t.index ["task_key", "run_at"], name: "index_solid_queue_recurring_executions_on_task_key_and_run_at", unique: true + end + + create_table "solid_queue_recurring_tasks", force: :cascade do |t| + t.string "key", null: false + t.string "schedule", null: false + t.string "command", limit: 2048 + t.string "class_name" + t.text "arguments" + t.string "queue_name" + t.integer "priority", default: 0 + t.boolean "static", default: true, null: false + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["key"], name: "index_solid_queue_recurring_tasks_on_key", unique: true + t.index ["static"], name: "index_solid_queue_recurring_tasks_on_static" + end + + create_table "solid_queue_scheduled_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.datetime "scheduled_at", null: false + t.datetime "created_at", null: false + t.index ["job_id"], name: "index_solid_queue_scheduled_executions_on_job_id", unique: true + t.index ["scheduled_at", "priority", "job_id"], name: "index_solid_queue_dispatch_all" + end + + create_table "solid_queue_semaphores", force: :cascade do |t| + t.string "key", null: false + t.integer "value", default: 1, null: false + t.datetime "expires_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["expires_at"], name: "index_solid_queue_semaphores_on_expires_at" + t.index ["key", "value"], name: "index_solid_queue_semaphores_on_key_and_value" + t.index ["key"], name: "index_solid_queue_semaphores_on_key", unique: true + end + + add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + end +end diff --git a/test/hirefire/macro/test_solid_queue.rb b/test/hirefire/macro/test_solid_queue.rb index e724edf..d48413c 100644 --- a/test/hirefire/macro/test_solid_queue.rb +++ b/test/hirefire/macro/test_solid_queue.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true require "test_helper" - -require_relative "../../env/rails_solid_queue_0/config/environment" +require "solid_queue/version" class HireFire::Macro::SolidQueueTest < Minitest::Test + MAJOR_VERSION = Gem::Version.new(::SolidQueue::VERSION).segments[0] + require_relative "../../env/rails_solid_queue_#{MAJOR_VERSION}/config/environment" + LATENCY_DELTA = 2 def setup @@ -138,19 +140,16 @@ def test_job_queue_size_with_claimed_jobs def prepare_database db_config = Rails.configuration.database_configuration[Rails.env] - ActiveRecord::Base.establish_connection(db_config) - begin - ActiveRecord::Base.connection + ActiveRecord::Base.establish_connection(db_config) + ActiveRecord::Migration.verbose = false + ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate rescue ActiveRecord::NoDatabaseError ActiveRecord::Tasks::DatabaseTasks.create(db_config) - ActiveRecord::Base.establish_connection(db_config) + retry end - ActiveRecord::Migration.verbose = false - ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate - - SolidQueue::Job.delete_all # Cascades deletion to all executions. + SolidQueue::Job.delete_all SolidQueue::Pause.delete_all end @@ -179,11 +178,29 @@ def insert_claimed_job(job_class, **options) claimed_count = SolidQueue::ClaimedExecution.count ready_count = SolidQueue::ReadyExecution.count job = job_class.set(**options).perform_later - process = SolidQueue::Process.create!(pid: 1, kind: "Worker", last_heartbeat_at: Time.now) + + process_attributes = if MAJOR_VERSION >= 1 + { + pid: 1, + kind: "Worker", + last_heartbeat_at: Time.now, + name: "test-worker-1" # Required in 1.x + } + else + { + pid: 1, + kind: "Worker", + last_heartbeat_at: Time.now + } + end + + process = SolidQueue::Process.create!(process_attributes) + SolidQueue::Job.transaction do SolidQueue::ReadyExecution.find_by(job_id: job.provider_job_id).destroy! SolidQueue::ClaimedExecution.create!(job_id: job.provider_job_id, process_id: process.id) end + assert_equal (job_count + 1), SolidQueue::Job.count assert_equal (claimed_count + 1), SolidQueue::ClaimedExecution.count assert_equal ready_count, SolidQueue::ReadyExecution.count