From c10145cc937f273248fed499be6a4a624ed6eab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Hendricksen?= Date: Tue, 12 Jul 2016 17:38:55 -0400 Subject: [PATCH 1/3] builds occasionally fail when the timestamps are a second off, this should fix that --- spec/unit/serialize/v2/http/jobs_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/unit/serialize/v2/http/jobs_spec.rb b/spec/unit/serialize/v2/http/jobs_spec.rb index 7b78c9f8..58363f19 100644 --- a/spec/unit/serialize/v2/http/jobs_spec.rb +++ b/spec/unit/serialize/v2/http/jobs_spec.rb @@ -2,6 +2,7 @@ describe Travis::Api::Serialize::V2::Http::Jobs do include Travis::Testing::Stubs, Support::Formats let(:data) { described_class.new([test]).data } + let!(:time) { Time.now.utc } it 'jobs' do data['jobs'].first.should == { @@ -13,8 +14,8 @@ describe Travis::Api::Serialize::V2::Http::Jobs do 'log_id' => 1, 'number' => '2.1', 'state' => 'passed', - 'started_at' => json_format_time(Time.now.utc - 1.minute), - 'finished_at' => json_format_time(Time.now.utc), + 'started_at' => json_format_time(time - 1.minute), + 'finished_at' => json_format_time(time), 'config' => { 'rvm' => '1.8.7', 'gemfile' => 'test/Gemfile.rails-2.3.x' }, 'queue' => 'builds.linux', 'allow_failure' => false, @@ -28,7 +29,7 @@ describe Travis::Api::Serialize::V2::Http::Jobs do 'sha' => '62aae5f70ceee39123ef', 'branch' => 'master', 'message' => 'the commit message', - 'committed_at' => json_format_time(Time.now.utc - 1.hour), + 'committed_at' => json_format_time(time - 1.hour), 'committer_name' => 'Sven Fuchs', 'committer_email' => 'svenfuchs@artweb-design.de', 'author_name' => 'Sven Fuchs', @@ -50,4 +51,3 @@ describe Travis::Api::Serialize::V2::Http::Jobs, 'using Travis::Services::Jobs:: lambda { data }.should issue_queries(4) end end - From 16968f445f890d627c14c30dac558c8a5dab2d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Hendricksen?= Date: Tue, 12 Jul 2016 19:23:24 -0400 Subject: [PATCH 2/3] freeze time for the whole suite so all the Time.now calls sprinkled through the old tests won't error if there is a delay on Travis CI --- spec/spec_helper.rb | 9 +++++++++ spec/v3/models/cron_spec.rb | 2 ++ 2 files changed, 11 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 748561f5..b16ac2c8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -62,3 +62,12 @@ RSpec.configure do |c| end end end + +require 'timecop' +Timecop.freeze(Time.now.utc) + +describe Time do + let(:time) { Time.now.utc } + example { expect(Time.now.utc).to eq(time) } + example { expect(Time.now.utc + 5.minutes ).to eq(time + 5.minutes) } +end diff --git a/spec/v3/models/cron_spec.rb b/spec/v3/models/cron_spec.rb index cbbac817..f5028f89 100644 --- a/spec/v3/models/cron_spec.rb +++ b/spec/v3/models/cron_spec.rb @@ -7,11 +7,13 @@ describe Travis::API::V3::Models::Cron do describe "next build time is calculated correctly on year changes" do before do + Timecop.return Timecop.travel(DateTime.new(2015, 12, 31, 16)) end after do Timecop.return + Timecop.freeze(Time.now.utc) end it "for daily builds" do From 42b1661107fbec56845a70f3acea6d1b61130c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Hendricksen?= Date: Tue, 12 Jul 2016 19:27:04 -0400 Subject: [PATCH 3/3] already required in the spec helper now --- spec/v3/models/cron_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/v3/models/cron_spec.rb b/spec/v3/models/cron_spec.rb index f5028f89..9e323e66 100644 --- a/spec/v3/models/cron_spec.rb +++ b/spec/v3/models/cron_spec.rb @@ -1,5 +1,3 @@ -require 'timecop' - describe Travis::API::V3::Models::Cron do let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first } let(:branch) { Travis::API::V3::Models::Branch.create(repository: repo, name: 'cron test') }