Project

General

Profile

Bug #17484

Report factory increments "reported_at" field until new reports go out of sync

Added by Dominic Cleal about 4 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Tests
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

The "report" factory used in our test suite uses a sequence for the "reported_at" field, incrementally making new reports that are further and further back in time:

  0 FactoryGirl.define do
  1   factory :report do
  2     host
  3     sequence(:reported_at) { |n| n.minutes.ago }
[..]

In a full test run, this can eventually start creating reports that are out of sync compared to the current time.

This causes test failures on 1.13-stable when running rake test:

HostTest.test_0038_host #refresh_statuses saves all relevant statuses and refreshes global status
Expected: 0
  Actual: 1 (Minitest::Assertion)
/var/lib/workspace/workspace/test_1_13_stable/database/sqlite3/ruby/2.3/slave/fast/test/unit/host_test.rb:509 

Debugging the above test shows a host was created with a new report at 11:08, but the reported_at time is 08:57, therefore the host is out of sync:

[20] pry(#<HostTest>)> host.host_statuses.first.last_report
=> #<ConfigReport:0x00000018608048
 id: 5,
 host_id: 1,
 reported_at: Fri, 25 Nov 2016 08:57:35 UTC +00:00,
 created_at: Fri, 25 Nov 2016 11:08:35 UTC +00:00,
 updated_at: Fri, 25 Nov 2016 11:08:35 UTC +00:00,
[..]
[21] pry(#<HostTest>)> host.host_statuses.first.out_of_sync?
=> true

This causes the global status error and assertion to fail.

Running the test in isolation works as reported_at is closer to the current time:

[3] pry(#<HostTest>)> host.host_statuses.first.last_report
=> #<ConfigReport:0x0000000f3109e8
 id: 5,
 host_id: 1,
 reported_at: Fri, 25 Nov 2016 11:22:17 UTC +00:00,
 created_at: Fri, 25 Nov 2016 11:27:17 UTC +00:00,
 updated_at: Fri, 25 Nov 2016 11:27:17 UTC +00:00,
[..]
[4] pry(#<HostTest>)> host.host_statuses.first.out_of_sync?
=> false

And the test passes.

Associated revisions

Revision 46edaeb9 (diff)
Added by Dominic Cleal about 4 years ago

fixes #17484 - remove reported_at sequence from report factory

Prevents reports getting ever more out of sync from Time.now.

Revision 6e58973d (diff)
Added by Dominic Cleal almost 4 years ago

fixes #17484 - remove reported_at sequence from report factory

Prevents reports getting ever more out of sync from Time.now.
(cherry picked from commit 46edaeb9ca6cd0ee3a804d665b8783c62f2f0700)

Revision 59372586 (diff)
Added by Dominic Cleal almost 4 years ago

fixes #17484 - remove reported_at sequence from report factory

Prevents reports getting ever more out of sync from Time.now.
(cherry picked from commit 46edaeb9ca6cd0ee3a804d665b8783c62f2f0700)

History

#1 Updated by The Foreman Bot about 4 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4053 added

#2 Updated by Dominic Cleal about 4 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#3 Updated by Dominic Cleal about 4 years ago

  • Legacy Backlogs Release (now unused) set to 189

#4 Updated by Dominic Cleal about 4 years ago

  • Legacy Backlogs Release (now unused) changed from 189 to 207

Also available in: Atom PDF