From 93eabb891ff961c21414a1d0a78d9416a26c1576 Mon Sep 17 00:00:00 2001 From: Eric Guo Date: Wed, 20 Mar 2024 23:59:33 +0800 Subject: [PATCH] Revert "Merge pull request #15040 from opf/flaky-schedule_date_alerts_notifications_job_spec" This reverts commit 2acc3ad4d68cf93b5d024216d084accff00710b7, reversing changes made to 691c2d61b9c25ffe21a3b2159652e414cf1bbfa4. --- ...dule_date_alerts_notifications_job_spec.rb | 149 +++++++++--------- 1 file changed, 78 insertions(+), 71 deletions(-) diff --git a/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb b/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb index 5e9fcc86917d..eb434f549376 100644 --- a/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb +++ b/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb @@ -26,24 +26,24 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require "spec_helper" +require 'spec_helper' RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, with_ee: %i[date_alerts] do include ActiveSupport::Testing::TimeHelpers - shared_let(:project) { create(:project, name: "main") } + shared_let(:project) { create(:project, name: 'main') } # Paris and Berlin are both UTC+01:00 (CET) or UTC+02:00 (CEST) - shared_let(:timezone_paris) { ActiveSupport::TimeZone["Europe/Paris"] } + shared_let(:timezone_paris) { ActiveSupport::TimeZone['Europe/Paris'] } # Kathmandu is UTC+05:45 (no DST) - shared_let(:timezone_kathmandu) { ActiveSupport::TimeZone["Asia/Kathmandu"] } + shared_let(:timezone_kathmandu) { ActiveSupport::TimeZone['Asia/Kathmandu'] } shared_let(:user_paris) do create(:user, - firstname: "Paris", + firstname: 'Paris', preferences: { time_zone: timezone_paris.name }) end shared_let(:user_kathmandu) do create(:user, - firstname: "Kathmandu", + firstname: 'Kathmandu', preferences: { time_zone: timezone_kathmandu.name }) end @@ -60,14 +60,14 @@ def set_scheduled_time(scheduled_at) # Converts "hh:mm" into { hour: h, min: m } def time_hash(time) - %i[hour min].zip(time.split(":", 2).map(&:to_i)).to_h + %i[hour min].zip(time.split(':', 2).map(&:to_i)).to_h end def timezone_time(time, timezone) timezone.now.change(time_hash(time)) end - def run_job(scheduled_at:, local_time:, timezone:) + def run_job(scheduled_at: '1:00', local_time: '1:04', timezone: timezone_paris) set_scheduled_time(timezone_time(scheduled_at, timezone)) travel_to(timezone_time(local_time, timezone)) do GoodJob.perform_inline @@ -86,97 +86,104 @@ def deserialize_job(job) def expect_job(job, *arguments) job_data = deserialize_job(job) - expect(job_data["job_class"]).to eql(job.job_class) - expect(job_data["arguments"]).to match_array arguments - expect(job_data["executions"]).to eq 0 + expect(job_data['job_class']).to eql(job.job_class) + expect(job_data['arguments']).to match_array arguments + expect(job_data['executions']).to eq 0 end - shared_examples_for "job execution creates date alerts creation job" do - let(:job_class) { Notifications::CreateDateAlertsNotificationsJob.name } + shared_examples_for 'job execution creates date alerts creation job' do + let(:timezone) { timezone_paris } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:04' } + let(:user) { user_paris } - it "creates the job for the user" do + it 'creates the job for the user' do expect do run_job(timezone:, scheduled_at:, local_time:) do - j = GoodJob::Job.where(job_class:) + j = GoodJob::Job.where(job_class: "Notifications::CreateDateAlertsNotificationsJob") .order(created_at: :desc) .last expect_job(j, user) end - end.to change { GoodJob::Job.where(job_class:).count }.by 1 + end.to change(GoodJob::Job, :count).by 1 end end - shared_examples_for "job execution creates no date alerts creation job" do - it "creates no job" do + shared_examples_for 'job execution creates no date alerts creation job' do + let(:timezone) { timezone_paris } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:04' } + + it 'creates no job' do expect do run_job(timezone:, scheduled_at:, local_time:) end.not_to change(GoodJob::Job, :count) end end - describe "#perform" do - context "for users whose local time is 1:00 am (UTC+1) when the job is executed" do - it_behaves_like "job execution creates date alerts creation job" do + describe '#perform' do + context 'for users whose local time is 1:00 am (UTC+1) when the job is executed' do + it_behaves_like 'job execution creates date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:04" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:04' } let(:user) { user_paris } end end - context "for users whose local time is 1:00 am (UTC+05:45) when the job is executed" do - it_behaves_like "job execution creates date alerts creation job" do + context 'for users whose local time is 1:00 am (UTC+05:45) when the job is executed' do + it_behaves_like 'job execution creates date alerts creation job' do let(:timezone) { timezone_kathmandu } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:04" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:04' } let(:user) { user_kathmandu } end end - context "without enterprise token", with_ee: false do - it_behaves_like "job execution creates no date alerts creation job" do + context 'without enterprise token', with_ee: false do + it_behaves_like 'job execution creates no date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:04" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:04' } end end - context "when scheduled and executed at 01:00 am local time" do - it_behaves_like "job execution creates date alerts creation job" do + context 'when scheduled and executed at 01:00 am local time' do + it_behaves_like 'job execution creates date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:00" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:00' } let(:user) { user_paris } end end - context "when scheduled and executed at 01:14 am local time" do - it_behaves_like "job execution creates date alerts creation job" do + context 'when scheduled and executed at 01:14 am local time' do + it_behaves_like 'job execution creates date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:14" } - let(:local_time) { "1:14" } + let(:scheduled_at) { '1:14' } + let(:local_time) { '1:14' } let(:user) { user_paris } end end - context "when scheduled and executed at 01:15 am local time" do - it_behaves_like "job execution creates no date alerts creation job" do + context 'when scheduled and executed at 01:15 am local time' do + it_behaves_like 'job execution creates no date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:15" } - let(:local_time) { "1:15" } + let(:scheduled_at) { '1:15' } + let(:local_time) { '1:15' } end end - context "when scheduled at 01:00 am local time and executed at 01:37 am local time" do - it_behaves_like "job execution creates date alerts creation job" do + context 'when scheduled at 01:00 am local time and executed at 01:37 am local time' do + it_behaves_like 'job execution creates date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:37" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:37' } let(:user) { user_paris } end end - context "with a user having only due_date active in notification settings" do + context 'with a user having only due_date active in notification settings' do before do NotificationSetting .where(user: user_paris) @@ -185,15 +192,15 @@ def expect_job(job, *arguments) overdue: nil) end - it_behaves_like "job execution creates date alerts creation job" do + it_behaves_like 'job execution creates date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:00" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:00' } let(:user) { user_paris } end end - context "with a user having only start_date active in notification settings" do + context 'with a user having only start_date active in notification settings' do before do NotificationSetting .where(user: user_paris) @@ -202,15 +209,15 @@ def expect_job(job, *arguments) overdue: nil) end - it_behaves_like "job execution creates date alerts creation job" do + it_behaves_like 'job execution creates date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:00" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:00' } let(:user) { user_paris } end end - context "with a user having only overdue active in notification settings" do + context 'with a user having only overdue active in notification settings' do before do NotificationSetting .where(user: user_paris) @@ -219,15 +226,15 @@ def expect_job(job, *arguments) overdue: 1) end - it_behaves_like "job execution creates date alerts creation job" do + it_behaves_like 'job execution creates date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:00" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:00' } let(:user) { user_paris } end end - context "without a user having notification settings" do + context 'without a user having notification settings' do before do NotificationSetting .where(user: user_paris) @@ -236,14 +243,14 @@ def expect_job(job, *arguments) overdue: nil) end - it_behaves_like "job execution creates no date alerts creation job" do + it_behaves_like 'job execution creates no date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:00" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:00' } end end - context "with a user having only a project active notification settings" do + context 'with a user having only a project active notification settings' do before do NotificationSetting .where(user: user_paris) @@ -259,23 +266,23 @@ def expect_job(job, *arguments) overdue: nil) end - it_behaves_like "job execution creates date alerts creation job" do + it_behaves_like 'job execution creates date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:00" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:00' } let(:user) { user_paris } end end - context "with a locked user" do + context 'with a locked user' do before do user_paris.locked! end - it_behaves_like "job execution creates no date alerts creation job" do + it_behaves_like 'job execution creates no date alerts creation job' do let(:timezone) { timezone_paris } - let(:scheduled_at) { "1:00" } - let(:local_time) { "1:00" } + let(:scheduled_at) { '1:00' } + let(:local_time) { '1:00' } end end end