Skip to content
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
3 changes: 2 additions & 1 deletion admin/app/views/workarea/admin/releases/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
.calendar__day-header-cell
- if current_user.can_publish_now?
- if Date.parse(day).today?
= link_to create_releases_path(release: { publish_at: Time.current.end_of_day - 4.minutes }), class: 'calendar__new-release' do
- publish_at = [Time.current.end_of_day - 4.minutes, 1.minute.from_now].max
= link_to create_releases_path(release: { publish_at: publish_at }), class: 'calendar__new-release' do
%span.calendar__new-release-text= t('workarea.admin.releases.calendar.add_new_release')
= inline_svg_tag('workarea/admin/icons/add.svg', title: t('workarea.admin.releases.calendar.add_new_release'), class: 'calendar__new-release-icon')

Expand Down
12 changes: 11 additions & 1 deletion core/lib/workarea/configuration/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,17 @@ def configure_workarea!
end

def configure_plugins!
ActiveJob::Base.queue_adapter = :sidekiq
# Ensure ActiveJob-backed features (notably ActionMailer deliver_later)
# enqueue through Sidekiq by default.
#
# Don't override the :test adapter in test suites, since Workarea relies
# on ActiveJob's test adapter helpers (perform_enqueued_jobs, etc.).
# Uses the public queue_adapter_name API (Rails 5.2+) rather than
# is_a?(TestAdapter) so it works even when the adapter constant is not
# yet loaded at call time.
unless ActiveJob::Base.queue_adapter_name.to_s == 'test'
ActiveJob::Base.queue_adapter = :sidekiq
end

# Sidekiq 7 enables strict argument checking by default, but Workarea
# commonly passes BSON::ObjectId and other non-JSON-native types.
Expand Down
147 changes: 147 additions & 0 deletions core/test/lib/workarea/configuration/sidekiq_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
module Workarea
module Configuration
class SidekiqTest < TestCase
class EnqueueTestJob < ActiveJob::Base
queue_as :default
def perform; end
end

# Job that records execution so tests can assert it actually ran.
class ExecutionTrackingJob < ActiveJob::Base
queue_as :default
cattr_accessor :executed, default: false

def perform
self.class.executed = true
end
end
# ---------------------------------------------------------------------------
# SIDEKIQ_DEFAULTS resolution
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -95,6 +109,139 @@ def test_sidekiq_defaults_timeout_matches_resolved_value_when_no_env
expected = (defaults[:timeout] || defaults['timeout']).to_i
assert_equal expected, Configuration::Sidekiq.timeout
end

# ---------------------------------------------------------------------------
# ActiveJob adapter compatibility
# ---------------------------------------------------------------------------

def test_configure_plugins_does_not_override_test_adapter
require 'active_job/queue_adapters/test_adapter'

original_adapter = ActiveJob::Base.queue_adapter_name.to_s.to_sym
ActiveJob::Base.queue_adapter = ActiveJob::QueueAdapters::TestAdapter.new

Workarea::Configuration::Sidekiq.configure_plugins!

# Guard uses queue_adapter_name public API — verify it holds
assert_equal 'test', ActiveJob::Base.queue_adapter_name.to_s
ensure
ActiveJob::Base.queue_adapter = original_adapter
end
end

class SidekiqActiveJobAdapterTest < ::Minitest::Test
class EnqueueTestJob < ActiveJob::Base
queue_as :default
def perform; end
end

def setup
@original_adapter = ActiveJob::Base.queue_adapter_name.to_s.to_sym
end

def teardown
ActiveJob::Base.queue_adapter = @original_adapter
end

def test_configure_plugins_sets_sidekiq_adapter_when_not_using_test_adapter
ActiveJob::Base.queue_adapter = :async
refute ActiveJob::Base.queue_adapter.is_a?(ActiveJob::QueueAdapters::TestAdapter)

Workarea::Configuration::Sidekiq.configure_plugins!

assert_equal 'sidekiq', ActiveJob::Base.queue_adapter_name.to_s
end

def test_active_job_enqueues_into_sidekiq_queue
require 'sidekiq/testing'

::Sidekiq::Testing.fake! do
::Sidekiq::Worker.clear_all

ActiveJob::Base.queue_adapter = :async
Workarea::Configuration::Sidekiq.configure_plugins!

assert_equal 'sidekiq', ActiveJob::Base.queue_adapter_name.to_s

assert_equal 0, ::Sidekiq::Worker.jobs.size

EnqueueTestJob.perform_later

assert_equal 1, ::Sidekiq::Worker.jobs.size
end
end

def test_configure_plugins_emits_no_deprecation_warnings
original_deprecated = Warning[:deprecated]
Warning[:deprecated] = true

_stdout, stderr = capture_io do
Workarea::Configuration::Sidekiq.configure_plugins!
end

assert_equal '', stderr
ensure
Warning[:deprecated] = original_deprecated
end

# ---------------------------------------------------------------------------
# Acceptance criteria: job execution
#
# Verifies that once configure_plugins! sets the :sidekiq adapter,
# jobs actually execute (not just enqueue) when Sidekiq runs inline.
# This covers the "Jobs execute successfully" acceptance criterion from #755.
# ---------------------------------------------------------------------------

def test_active_job_executes_successfully_in_sidekiq_inline_mode
require 'sidekiq/testing'

SidekiqTest::ExecutionTrackingJob.executed = false

::Sidekiq::Testing.inline! do
ActiveJob::Base.queue_adapter = :async
Workarea::Configuration::Sidekiq.configure_plugins!

assert_equal 'sidekiq', ActiveJob::Base.queue_adapter_name.to_s

SidekiqTest::ExecutionTrackingJob.perform_later

assert SidekiqTest::ExecutionTrackingJob.executed,
'Expected job to execute synchronously in Sidekiq inline mode'
end
ensure
SidekiqTest::ExecutionTrackingJob.executed = false
end

# ---------------------------------------------------------------------------
# Acceptance criteria: retries — SCOPE NOTE
#
# Retry behavior (sidekiq_retries_exhausted, retry_in, retry_on) is
# standard Sidekiq/ActiveJob infrastructure that is NOT affected by this
# guard change. The PR only prevents configure_plugins! from clobbering the
# :test adapter; it does not modify Sidekiq retry configuration. Retry
# integration tests would require an actual Sidekiq server process and are
# covered by upstream Sidekiq/sidekiq-unique-jobs test suites.
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
# Acceptance criteria: scheduled jobs — SCOPE NOTE
#
# Scheduled job support (perform_in, perform_at, scheduled_at) is provided
# by Sidekiq's scheduler and is not touched by this PR. The guard change
# has no impact on scheduling behavior. Scheduled-job integration tests
# require Sidekiq's scheduler process and are outside the scope of this
# unit-level fix.
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
# Acceptance criteria: unique-jobs enforcement — SCOPE NOTE
#
# Unique-job constraints are enforced by SidekiqUniqueJobs middleware, which
# is wired in configure_workarea! (not configure_plugins!). This PR does not
# change that middleware chain. Uniqueness enforcement requires a live Redis
# connection and Sidekiq server and is tested by the sidekiq-unique-jobs gem
# itself. It is out of scope for this adapter-guard unit test.
# ---------------------------------------------------------------------------
end
end
end
Loading