Skip to content

Commit

Permalink
Merge pull request #15686 from opf/time-matcher-flaky-fix
Browse files Browse the repository at this point in the history
Time matcher flaky fix
  • Loading branch information
dombesz authored May 28, 2024
2 parents 1a14641 + 41a1ec0 commit 9b10bd6
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 32 deletions.
30 changes: 18 additions & 12 deletions modules/bim/spec/requests/api/bcf/v2_1/comments_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,13 @@
let(:expected_status) { 201 }
let(:expected_body) do
comment = Bim::Bcf::Comment.last.reload
creation_date = comment&.journal&.created_at&.iso8601

{
guid: comment&.uuid,
date: creation_date,
date: comment&.journal&.created_at&.iso8601,
author: edit_user.mail,
comment: "this is a new bcf comment",
modified_date: creation_date,
modified_date: comment&.journal&.updated_at&.iso8601,
modified_author: edit_user.mail,
topic_guid: bcf_issue.uuid,
reply_to_comment_guid: nil,
Expand Down Expand Up @@ -223,14 +222,13 @@
let(:expected_status) { 201 }
let(:expected_body) do
comment = Bim::Bcf::Comment.last.reload
creation_date = comment&.journal&.created_at&.iso8601

{
guid: comment&.uuid,
date: creation_date,
date: comment&.journal&.created_at,
author: edit_user.mail,
comment: "this is a comment to a specific viewpoint",
modified_date: creation_date,
modified_date: comment&.journal&.updated_at,
modified_author: edit_user.mail,
topic_guid: bcf_issue.uuid,
reply_to_comment_guid: nil,
Expand Down Expand Up @@ -270,14 +268,13 @@
let(:expected_status) { 201 }
let(:expected_body) do
comment = Bim::Bcf::Comment.last.reload
creation_date = comment&.journal&.created_at&.iso8601

{
guid: comment&.uuid,
date: creation_date,
date: comment&.journal&.created_at,
author: edit_user.mail,
comment: "this is a reply comment to another comment",
modified_date: creation_date,
modified_date: comment&.journal&.updated_at,
modified_author: edit_user.mail,
topic_guid: bcf_issue.uuid,
reply_to_comment_guid: bcf_comment.uuid,
Expand Down Expand Up @@ -318,14 +315,13 @@
let(:expected_status) { 201 }
let(:expected_body) do
comment = Bim::Bcf::Comment.last.reload
creation_date = comment&.journal&.created_at&.iso8601

{
guid: comment&.uuid,
date: creation_date,
date: comment&.journal&.created_at,
author: edit_user.mail,
comment: "this is a reply comment to another comment with a specific reference to a viewpoint",
modified_date: creation_date,
modified_date: comment&.journal&.updated_at,
modified_author: edit_user.mail,
topic_guid: bcf_issue.uuid,
reply_to_comment_guid: bcf_comment.uuid,
Expand Down Expand Up @@ -409,6 +405,8 @@

it_behaves_like "bcf api successful response" do
let(:expected_body) do
bcf_comment.reload

{
guid: bcf_comment.uuid,
date: bcf_comment.journal.created_at,
Expand All @@ -429,6 +427,8 @@

it_behaves_like "bcf api successful response" do
let(:expected_body) do
bcf_comment.reload

{
guid: bcf_comment.uuid,
date: bcf_comment.journal.created_at,
Expand Down Expand Up @@ -476,6 +476,8 @@

it_behaves_like "bcf api successful response" do
let(:expected_body) do
updated_comment.reload

{
guid: updated_comment.uuid,
date: updated_comment.journal.created_at,
Expand Down Expand Up @@ -513,6 +515,8 @@

it_behaves_like "bcf api successful response" do
let(:expected_body) do
updated_comment.reload

{
guid: updated_comment.uuid,
date: updated_comment.journal.created_at,
Expand Down Expand Up @@ -573,6 +577,8 @@

it_behaves_like "bcf api successful response" do
let(:expected_body) do
updated_comment.reload

{
guid: updated_comment.uuid,
date: updated_comment.journal.created_at,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
require_module_spec_helper

RSpec.describe Storages::Admin::Sidebar::HealthStatusComponent, type: :component do
include ActiveSupport::Testing::TimeHelpers
frozen_date_time = Time.zone.local(2023, 11, 28, 1, 2, 3)

subject(:health_status_component) { described_class.new(storage:) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/concerns/auth_source_sso_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@

expect(service).to have_received(:call!).with(other_user)
expect(response).to redirect_to my_account_path
expect(user.reload.last_login_on).to be_within(10.seconds).of(Time.current)
expect(user.reload.last_login_on).to equal_time_without_usec(Time.current)
expect(session[:user_id]).to eq user.id
expect(session[:updated_at]).to be > session_update_time
end
Expand Down
2 changes: 0 additions & 2 deletions spec/features/activities/activity_page_navigation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
require "spec_helper"

RSpec.describe "Activity page navigation", :js, :with_cuprite do
include ActiveSupport::Testing::TimeHelpers

shared_let(:project) { create(:project, enabled_module_names: Setting.default_projects_modules + ["activity"]) }
shared_let(:subproject) do
create(:project, parent: project, enabled_module_names: Setting.default_projects_modules + ["activity"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# rubocop:disable RSpec/ScatteredLet
RSpec.describe "Notification center date alerts", :js, :with_cuprite,
with_settings: { journal_aggregation_time_minutes: 0 } do
include ActiveSupport::Testing::TimeHelpers

# Find an assignable time zone with the same UTC offset as the local time zone
def find_compatible_local_time_zone
local_offset = Time.now.gmt_offset # rubocop:disable Rails/TimeZone
Expand Down
2 changes: 0 additions & 2 deletions spec/features/projects/projects_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,6 @@ def expect_projects_in_order(*projects)
end

describe "other filter types", with_ee: %i[custom_fields_in_projects_list] do
include ActiveSupport::Testing::TimeHelpers

shared_let(:list_custom_field) { create(:list_project_custom_field) }
shared_let(:date_custom_field) { create(:date_project_custom_field) }
shared_let(:datetime_of_this_week) do
Expand Down
19 changes: 17 additions & 2 deletions spec/support/time_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,25 @@
#
# See COPYRIGHT and LICENSE files for more details.
#++

RSpec.configure do |config|
config.include ActiveSupport::Testing::TimeHelpers
end

RSpec::Matchers.define :equal_time_without_usec do |expected|
failure_message { "expected: #{expected.iso8601}, actual: #{actual.iso8601}, difference: #{actual - expected}s" }
expected_without_usec = expected.change(usec: 0)

failure_message do
actual_without_usec = actual.change(usec: 0)
[
"expected: #{expected_without_usec.iso8601}",
"actual: #{actual_without_usec.iso8601}",
"difference: #{actual_without_usec - expected_without_usec}s"
].join(" - ")
end

match do |actual|
actual.change(usec: 0) == expected.change(usec: 0)
actual_without_usec = actual.change(usec: 0)
expected_without_usec == actual_without_usec
end
end
2 changes: 0 additions & 2 deletions spec/support_spec/schedule_helpers/chart_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
require "spec_helper"

RSpec.describe ScheduleHelpers::ChartBuilder do
include ActiveSupport::Testing::TimeHelpers

let(:fake_today) { Date.new(2022, 6, 16) } # Thursday 16 June 2022
let(:monday) { Date.new(2022, 6, 20) } # Monday 20 June
let(:tuesday) { Date.new(2022, 6, 21) }
Expand Down
2 changes: 0 additions & 2 deletions spec/support_spec/schedule_helpers/chart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
require "spec_helper"

RSpec.describe ScheduleHelpers::Chart do
include ActiveSupport::Testing::TimeHelpers

let(:fake_today) { Date.new(2022, 6, 16) } # Thursday 16 June 2022
let(:monday) { Date.new(2022, 6, 20) } # Monday 20 June
let(:tuesday) { Date.new(2022, 6, 21) }
Expand Down
2 changes: 0 additions & 2 deletions spec/support_spec/schedule_helpers/example_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@
end

describe "change_schedule" do
include ActiveSupport::Testing::TimeHelpers

let(:fake_today) { Date.new(2022, 6, 16) } # Thursday 16 June 2022
let(:monday) { Date.new(2022, 6, 20) } # Monday 20 June
let(:tuesday) { Date.new(2022, 6, 21) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
require "spec_helper"

RSpec.describe Notifications::CreateDateAlertsNotificationsJob, type: :job, with_ee: %i[date_alerts] do
include ActiveSupport::Testing::TimeHelpers

shared_let(:project) { create(:project, name: "main") }

shared_let(:status_open) { create(:status, name: "open", is_closed: false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
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") }
# Paris and Berlin are both UTC+01:00 (CET) or UTC+02:00 (CEST)
shared_let(:timezone_paris) { ActiveSupport::TimeZone["Europe/Paris"] }
Expand Down

0 comments on commit 9b10bd6

Please sign in to comment.