From c6e3c29a579f3e268cbf25340ccc37e4ec10feff Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 25 Jan 2013 23:47:21 +0100 Subject: [PATCH 01/12] Load the data for integration tests upfront We can do it, because we use :transaction strategy with DatabaseCleaner, which starts transaction before each test and rollbacks after it. That way data before each test is consistent. The big advantage of such approach is that tests are fast now - we need to only load Scenario data once. One of the drawbacks, on the other hand, is that we need to always load this data, even if no integration tests need running. We can try to be smart about it and check if any integration tests are loaded. --- spec/integration/v1/branches_spec.rb | 2 -- spec/integration/v1/builds_spec.rb | 2 -- spec/integration/v1/hooks_spec.rb | 1 - spec/integration/v1/repositories_spec.rb | 2 -- spec/integration/v2/branches_spec.rb | 2 -- spec/integration/v2/builds_spec.rb | 2 -- spec/integration/v2/hooks_spec.rb | 1 - spec/integration/v2/repositories_spec.rb | 2 -- spec/integration/v2/users_spec.rb | 2 +- spec/spec_helper.rb | 3 ++- spec/unit/endpoint/accounts_spec.rb | 2 +- 11 files changed, 4 insertions(+), 17 deletions(-) diff --git a/spec/integration/v1/branches_spec.rb b/spec/integration/v1/branches_spec.rb index 07beef62..6e5c8735 100644 --- a/spec/integration/v1/branches_spec.rb +++ b/spec/integration/v1/branches_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'Branches' do - before { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } diff --git a/spec/integration/v1/builds_spec.rb b/spec/integration/v1/builds_spec.rb index 3c1bca96..73d2fe85 100644 --- a/spec/integration/v1/builds_spec.rb +++ b/spec/integration/v1/builds_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'Builds' do - before { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:build) { repo.builds.first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } diff --git a/spec/integration/v1/hooks_spec.rb b/spec/integration/v1/hooks_spec.rb index 35160330..ccf76a00 100644 --- a/spec/integration/v1/hooks_spec.rb +++ b/spec/integration/v1/hooks_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' describe 'Hooks' do before(:each) do - Scenario.default user.permissions.create repository: repo, admin: true end diff --git a/spec/integration/v1/repositories_spec.rb b/spec/integration/v1/repositories_spec.rb index 9d4da90b..aea3fd4c 100644 --- a/spec/integration/v1/repositories_spec.rb +++ b/spec/integration/v1/repositories_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'v1 repos' do - before(:each) { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } diff --git a/spec/integration/v2/branches_spec.rb b/spec/integration/v2/branches_spec.rb index 6f52bbf7..3e54ecc8 100644 --- a/spec/integration/v2/branches_spec.rb +++ b/spec/integration/v2/branches_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'Branches' do - before { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } diff --git a/spec/integration/v2/builds_spec.rb b/spec/integration/v2/builds_spec.rb index 1f948fb8..4366a558 100644 --- a/spec/integration/v2/builds_spec.rb +++ b/spec/integration/v2/builds_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'Builds' do - before { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:build) { repo.builds.first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } diff --git a/spec/integration/v2/hooks_spec.rb b/spec/integration/v2/hooks_spec.rb index 37f1a931..c0a685de 100644 --- a/spec/integration/v2/hooks_spec.rb +++ b/spec/integration/v2/hooks_spec.rb @@ -3,7 +3,6 @@ require 'travis/testing/payloads' describe 'Hooks' do before(:each) do - Scenario.default user.permissions.create repository: repo, admin: true end diff --git a/spec/integration/v2/repositories_spec.rb b/spec/integration/v2/repositories_spec.rb index fba8035d..9de7ad63 100644 --- a/spec/integration/v2/repositories_spec.rb +++ b/spec/integration/v2/repositories_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe 'Repos' do - before(:each) { Scenario.default } - let(:repo) { Repository.by_slug('svenfuchs/minimal').first } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } diff --git a/spec/integration/v2/users_spec.rb b/spec/integration/v2/users_spec.rb index 945afa57..739ebc43 100644 --- a/spec/integration/v2/users_spec.rb +++ b/spec/integration/v2/users_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'Users' do - let(:user) { Factory(:user, locale: 'en') } + let(:user) { User.first } let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json', 'HTTP_AUTHORIZATION' => "token #{token}" } } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index af4563da..33a828a1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,7 +41,8 @@ RSpec.configure do |c| c.before :suite do DatabaseCleaner.strategy = :transaction - DatabaseCleaner.clean_with :transaction + DatabaseCleaner.clean_with :truncation + Scenario.default end c.before :each do diff --git a/spec/unit/endpoint/accounts_spec.rb b/spec/unit/endpoint/accounts_spec.rb index 2277ea8d..ecae3c03 100644 --- a/spec/unit/endpoint/accounts_spec.rb +++ b/spec/unit/endpoint/accounts_spec.rb @@ -18,7 +18,7 @@ describe Travis::Api::App::Endpoint::Accounts do 'login' => user.login, 'name' => user.name, 'type' => 'user', - 'repos_count' => nil + 'repos_count' => 1 }] end end From 46eefaf26dc0aa98f035218f14bb001d57cecf84 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 26 Jan 2013 00:02:15 +0100 Subject: [PATCH 02/12] Fix syntax error --- lib/travis/api/app/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index 90c73b42..92031836 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -20,7 +20,7 @@ class Travis::Api::App # hotfix?? def route_missing - @app ? forward : halt 404 + @app ? forward : halt(404) end def call(env) From f2d768080f0228eaeb4390b094ff7ca099101b1d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 26 Jan 2013 01:12:42 +0100 Subject: [PATCH 03/12] Return last builds on each branch for /builds?branches=true This is a hack to fix travis-ci/travis-web#123 easier. A proper solution would be to refactor how /branches work. --- lib/travis/api/app/endpoint/builds.rb | 3 ++- spec/integration/v2/builds_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index fe7b21c4..3ef22141 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -4,7 +4,8 @@ class Travis::Api::App class Endpoint class Builds < Endpoint get '/' do - respond_with service(:find_builds, params) + name = params[:branches] ? :find_branches : :find_builds + respond_with service(name, params) end get '/:id' do diff --git a/spec/integration/v2/builds_spec.rb b/spec/integration/v2/builds_spec.rb index 4366a558..51eb82fb 100644 --- a/spec/integration/v2/builds_spec.rb +++ b/spec/integration/v2/builds_spec.rb @@ -29,4 +29,9 @@ describe 'Builds' do response = get "/repos/svenfuchs/minimal/builds/#{build.id}", {}, headers response.should deliver_json_for(build, version: 'v2') end + + it 'GET /builds/1?repository_id=1&branches=true' do + response = get "/builds?repository_id=#{repo.id}&branches=true", {}, headers + response.should deliver_json_for(repo.last_finished_builds_by_branches, version: 'v2') + end end From d441336573ea8344e0213bf72a76945ece8b566b Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Thu, 24 Jan 2013 00:06:42 +0100 Subject: [PATCH 04/12] expose logs on /job/:id/log.txt --- Gemfile | 2 +- Gemfile.lock | 2 +- lib/travis/api/app.rb | 21 ++++++++++++--------- lib/travis/api/app/endpoint/jobs.rb | 4 ++++ spec/integration/v1/workers_spec.rb | 15 +++------------ spec/integration/v2/jobs_spec.rb | 8 +++++++- spec/integration/v2/workers_spec.rb | 15 +++------------ spec/support/matchers.rb | 20 ++++++++++++++++++++ 8 files changed, 51 insertions(+), 36 deletions(-) diff --git a/Gemfile b/Gemfile index 85cf5d16..add18133 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,8 @@ ruby '1.9.3' rescue nil source :rubygems gemspec +gem 'travis-core', github: 'travis-ci/travis-core', branch: 'sf-archive-logs' gem 'travis-support', github: 'travis-ci/travis-support' -gem 'travis-core', github: 'travis-ci/travis-core' gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741' gem 'sinatra' #github: 'sinatra/sinatra' gem 'sinatra-contrib', require: nil #github: 'sinatra/sinatra-contrib', require: nil diff --git a/Gemfile.lock b/Gemfile.lock index 63849b5c..b1b903d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: ba4e4a83b473393539728a3aeb8e3499ab1ef1bc + revision: 4637ea48abe8fb0976d8e0bbf997ea2578a3ca62 specs: travis-core (0.0.1) actionmailer (~> 3.2.11) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 277520fe..e57abdab 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -111,16 +111,19 @@ module Travis::Api Travis::Amqp.config = Travis.config.amqp Travis::Database.connect Travis::Features.start - Sidekiq.configure_client do |config| - config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace) + + unless Travis.env == 'test' + Sidekiq.configure_client do |config| + config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace) + end + + Raven.configure do |config| + config.dsn = Travis.config.sentry.dsn + end if Travis.config.sentry + + Travis::LogSubscriber::ActiveRecordMetrics.attach + Travis::Notification.setup end - - Raven.configure do |config| - config.dsn = Travis.config.sentry.dsn - end if Travis.config.sentry - - Travis::LogSubscriber::ActiveRecordMetrics.attach - Travis::Notification.setup end def self.load_endpoints diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index de02c291..963e2c59 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -10,6 +10,10 @@ class Travis::Api::App get '/:id' do respond_with service(:find_job, params) end + + get '/:job_id/log' do + respond_with service(:find_artifact, params) + end end end end diff --git a/spec/integration/v1/workers_spec.rb b/spec/integration/v1/workers_spec.rb index 34edd9e3..22bb8683 100644 --- a/spec/integration/v1/workers_spec.rb +++ b/spec/integration/v1/workers_spec.rb @@ -1,22 +1,13 @@ require 'spec_helper' describe 'Workers' do - before(:each) do - Time.stubs(:now).returns(Time.utc(2011, 11, 11, 11, 11, 11)) - @workers = [ - Worker.new('1', full_name: 'ruby1:ruby1.travis-ci.org'), - Worker.new('2', full_name: 'ruby2:ruby1.travis-ci.org') - ] - end - - let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } - - attr_reader :workers + let!(:workers) { [Worker.create(full_name: 'one'), Worker.create(full_name: 'two')] } + let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } it 'GET /workers' do Worker.stubs(all: @workers) response = get '/workers', {}, headers - response.should deliver_json_for(@workers, version: 'v1', type: 'workers') + response.should deliver_json_for(Worker.all, version: 'v1', type: 'workers') end end diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index 4da7acae..58e370ef 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -13,8 +13,14 @@ describe 'Jobs' do response.should deliver_json_for(Job.queued('builds.common'), version: 'v2') end - it '/jobs/:job_id' do + it '/jobs/:id' do response = get "/jobs/#{job.id}", {}, headers response.should deliver_json_for(job, version: 'v2') end + + it '/jobs/:id' do + job.log.update_attributes!(content: 'the log') + response = get "/jobs/#{job.id}/log.txt", {}, headers + response.should deliver_as_txt('the log', version: 'v2') + end end diff --git a/spec/integration/v2/workers_spec.rb b/spec/integration/v2/workers_spec.rb index 35f03e36..047dff94 100644 --- a/spec/integration/v2/workers_spec.rb +++ b/spec/integration/v2/workers_spec.rb @@ -1,22 +1,13 @@ require 'spec_helper' describe 'Workers' do - before(:each) do - Time.stubs(:now).returns(Time.utc(2011, 11, 11, 11, 11, 11)) - @workers = [ - Worker.new('1', full_name: 'ruby1:ruby1.travis-ci.org'), - Worker.new('2', full_name: 'ruby2:ruby1.travis-ci.org') - ] - end - - let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } - - attr_reader :workers + let!(:workers) { [Worker.create(full_name: 'one'), Worker.create(full_name: 'two')] } + let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } it 'GET /workers' do Worker.stubs(all: @workers) response = get '/workers', {}, headers - response.should deliver_json_for(@workers, version: 'v2', type: 'workers') + response.should deliver_json_for(Worker.all, version: 'v2', type: 'workers') end end diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 53cc97aa..3152322a 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -24,6 +24,26 @@ RSpec::Matchers.define :deliver_json_for do |resource, options = {}| end end +RSpec::Matchers.define :deliver_as_txt do |expected, options = {}| + match do |response| + if response.status == 200 + failure_message_for_should do + "expected\n\n#{actual}\n\nto equal\n\n#{expected}" + end + response.body.to_s == expected + else + failure_message_for_should do + "expected the request to be successful (200) but was #{response.status}" + end + false + end + end + + def parse(body) + MultiJson.decode(body) + end +end + RSpec::Matchers.define :deliver_result_image_for do |name| match do |response| header = response.headers['content-disposition'] From 598a586ed422cf5698eafe2bca937c5521b45a84 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Thu, 24 Jan 2013 00:48:26 +0100 Subject: [PATCH 05/12] don't start metrics logger etc unless in production --- lib/travis/api/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index e57abdab..0bd99d02 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -112,7 +112,7 @@ module Travis::Api Travis::Database.connect Travis::Features.start - unless Travis.env == 'test' + if Travis.env == 'production' Sidekiq.configure_client do |config| config.redis = Travis.config.redis.merge(size: 1, namespace: Travis.config.sidekiq.namespace) end From 4ea95494de673befe8e4bb7c50616b7c5efdaf79 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Thu, 24 Jan 2013 23:56:48 +0100 Subject: [PATCH 06/12] allow put to /artifacts/:id --- Gemfile | 2 +- Gemfile.lock | 11 ++++++----- lib/travis/api/app/endpoint/artifacts.rb | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index add18133..83b45662 100644 --- a/Gemfile +++ b/Gemfile @@ -38,5 +38,5 @@ end group :development, :test do gem 'rake', '~> 0.9.2' - gem 'micro_migrations', git: 'http://gist.github.com/4269321.git' + gem 'micro_migrations', git: 'https://gist.github.com/4269321.git' end diff --git a/Gemfile.lock b/Gemfile.lock index b1b903d3..abc22ad6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,8 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 4637ea48abe8fb0976d8e0bbf997ea2578a3ca62 + revision: c5f4fb9c33d78cd984e041ba6b280191c8b5349c + branch: sf-archive-logs specs: travis-core (0.0.1) actionmailer (~> 3.2.11) @@ -59,7 +60,7 @@ GIT postmark-rails (~> 0.4.1) pusher (~> 0.11.0) railties (~> 3.2.11) - rake (~> 0.9.2.2) + rake redis (~> 3.0) rollout (~> 1.1.0) simple_states (~> 0.1.1) @@ -80,7 +81,7 @@ GIT travis-support (0.0.1) GIT - remote: http://gist.github.com/4269321.git + remote: https://gist.github.com/4269321.git revision: 8e2d21b924a69dd48191df6a18e51769f5a88614 specs: micro_migrations (0.0.1) @@ -185,7 +186,7 @@ GEM multipart-post (1.1.5) net-http-persistent (2.8) net-http-pipeline (1.0.1) - newrelic_rpm (3.5.5.38) + newrelic_rpm (3.5.6.46) pg (0.13.2) polyglot (0.3.3) postmark (0.9.18) @@ -220,7 +221,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (0.9.2.2) + rake (0.9.6) rdoc (3.12) json (~> 1.4) redcarpet (2.2.2) diff --git a/lib/travis/api/app/endpoint/artifacts.rb b/lib/travis/api/app/endpoint/artifacts.rb index 43fb9040..94601d53 100644 --- a/lib/travis/api/app/endpoint/artifacts.rb +++ b/lib/travis/api/app/endpoint/artifacts.rb @@ -9,6 +9,10 @@ class Travis::Api::App get '/:id' do |id| respond_with service(:find_artifact, params) end + + put '/:id' do |id| + respond_with service(:update_artifact, params) + end end end end From b81644acba2e8542d64887e66b8a9fdddaaed9c1 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sat, 26 Jan 2013 20:41:18 +0100 Subject: [PATCH 07/12] comment out put to /artifacts/:id for now --- lib/travis/api/app/endpoint/artifacts.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/travis/api/app/endpoint/artifacts.rb b/lib/travis/api/app/endpoint/artifacts.rb index 94601d53..1db1bb99 100644 --- a/lib/travis/api/app/endpoint/artifacts.rb +++ b/lib/travis/api/app/endpoint/artifacts.rb @@ -10,9 +10,11 @@ class Travis::Api::App respond_with service(:find_artifact, params) end - put '/:id' do |id| - respond_with service(:update_artifact, params) - end + # TODO needs auth, required for live log archiving on log:aggregted in travis-tasks + # + # put '/:id' do |id| + # respond_with service(:update_artifact, params) + # end end end end From 7b4712c32cbe22bb669db639c14d954e2bb01ebc Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sat, 26 Jan 2013 20:54:58 +0100 Subject: [PATCH 08/12] fix after rebase --- Gemfile.lock | 10 +++++----- spec/integration/v1/workers_spec.rb | 1 - spec/integration/v2/workers_spec.rb | 1 - 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index abc22ad6..d447a621 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: c5f4fb9c33d78cd984e041ba6b280191c8b5349c + revision: 801d0dee5bd85811afa000f705f34e29ff2c65e9 branch: sf-archive-logs specs: travis-core (0.0.1) @@ -60,7 +60,7 @@ GIT postmark-rails (~> 0.4.1) pusher (~> 0.11.0) railties (~> 3.2.11) - rake + rake (~> 0.9.2.2) redis (~> 3.0) rollout (~> 1.1.0) simple_states (~> 0.1.1) @@ -76,7 +76,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: a288008629ae7eab18c529008880d364daca82ce + revision: ff712aca1083a588974f835a84c574e6976aeb29 specs: travis-support (0.0.1) @@ -144,7 +144,7 @@ GEM coderay (1.0.8) connection_pool (0.9.3) daemons (1.1.9) - dalli (2.6.0) + dalli (2.6.2) data_migrations (0.0.1) activerecord rake @@ -221,7 +221,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (0.9.6) + rake (0.9.2.2) rdoc (3.12) json (~> 1.4) redcarpet (2.2.2) diff --git a/spec/integration/v1/workers_spec.rb b/spec/integration/v1/workers_spec.rb index 22bb8683..1c897384 100644 --- a/spec/integration/v1/workers_spec.rb +++ b/spec/integration/v1/workers_spec.rb @@ -5,7 +5,6 @@ describe 'Workers' do let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.1+json' } } it 'GET /workers' do - Worker.stubs(all: @workers) response = get '/workers', {}, headers response.should deliver_json_for(Worker.all, version: 'v1', type: 'workers') end diff --git a/spec/integration/v2/workers_spec.rb b/spec/integration/v2/workers_spec.rb index 047dff94..120934a4 100644 --- a/spec/integration/v2/workers_spec.rb +++ b/spec/integration/v2/workers_spec.rb @@ -5,7 +5,6 @@ describe 'Workers' do let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } it 'GET /workers' do - Worker.stubs(all: @workers) response = get '/workers', {}, headers response.should deliver_json_for(Worker.all, version: 'v2', type: 'workers') end From 616b8df27cd9b82b313909def4008d960bb4f827 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 27 Jan 2013 21:42:00 +0100 Subject: [PATCH 09/12] Use travis-core from master --- Gemfile | 2 +- Gemfile.lock | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 83b45662..d75971de 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ ruby '1.9.3' rescue nil source :rubygems gemspec -gem 'travis-core', github: 'travis-ci/travis-core', branch: 'sf-archive-logs' +gem 'travis-core', github: 'travis-ci/travis-core' gem 'travis-support', github: 'travis-ci/travis-support' gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741' gem 'sinatra' #github: 'sinatra/sinatra' diff --git a/Gemfile.lock b/Gemfile.lock index d447a621..daf0b41c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,8 +45,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 801d0dee5bd85811afa000f705f34e29ff2c65e9 - branch: sf-archive-logs + revision: 987188a5f96f5d7e4f6a6e314ab402f3fbad0963 specs: travis-core (0.0.1) actionmailer (~> 3.2.11) @@ -60,7 +59,7 @@ GIT postmark-rails (~> 0.4.1) pusher (~> 0.11.0) railties (~> 3.2.11) - rake (~> 0.9.2.2) + rake redis (~> 3.0) rollout (~> 1.1.0) simple_states (~> 0.1.1) @@ -221,7 +220,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (0.9.2.2) + rake (0.9.6) rdoc (3.12) json (~> 1.4) redcarpet (2.2.2) From edc9749bcef8baa2f3ee9c5ae151d6417e8f6082 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 28 Jan 2013 00:54:32 +0100 Subject: [PATCH 10/12] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index daf0b41c..98ba2bd9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 987188a5f96f5d7e4f6a6e314ab402f3fbad0963 + revision: be085ccf0aa58fba8d383d6ed72d22e47dae5836 specs: travis-core (0.0.1) actionmailer (~> 3.2.11) From 31371686c95878ff06eb53728de011d5dc281c3c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 28 Jan 2013 03:04:36 +0100 Subject: [PATCH 11/12] Redirect to archive logs --- Gemfile.lock | 2 +- lib/travis/api/app/endpoint/jobs.rb | 15 ++++++++++++++- spec/integration/v2/jobs_spec.rb | 26 ++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 98ba2bd9..b82358b1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,7 +45,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: be085ccf0aa58fba8d383d6ed72d22e47dae5836 + revision: 2d766c54c2fea70dfc4d937c22413eee937f002b specs: travis-core (0.0.1) actionmailer (~> 3.2.11) diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 963e2c59..288c6bb9 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -12,7 +12,20 @@ class Travis::Api::App end get '/:job_id/log' do - respond_with service(:find_artifact, params) + resource = service(:find_artifact, params).run + if !resource || resource.archived? + redirect archive_url("/jobs/#{params[:job_id]}/log.txt") + else + respond_with resource + end + end + + def archive_url(path) + "https://#{hostname('archive')}#{path}" + end + + def hostname(name) + "#{name}#{'-staging' if Travis.env == 'staging'}.#{Travis.config.host.split('.')[-2, 2].join('.')}" end end end diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index 58e370ef..847e56f5 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -18,9 +18,27 @@ describe 'Jobs' do response.should deliver_json_for(job, version: 'v2') end - it '/jobs/:id' do - job.log.update_attributes!(content: 'the log') - response = get "/jobs/#{job.id}/log.txt", {}, headers - response.should deliver_as_txt('the log', version: 'v2') + context 'GET /jobs/:job_id/log.txt' do + it 'returns log for a job' do + job.log.update_attributes!(content: 'the log') + response = get "/jobs/#{job.id}/log.txt", {}, headers + response.should deliver_as_txt('the log', version: 'v2') + end + + context 'when log is archived' do + it 'redirects to archive' do + job.log.update_attributes!(content: 'the log', archived_at: Time.now, archive_verified: true) + response = get "/jobs/#{job.id}/log.txt", {}, headers + response.should redirect_to("https://archive.travis-ci.org/jobs/#{job.id}/log.txt") + end + end + + context 'when log is missing' do + it 'redirects to archive' do + job.log.destroy + response = get "/jobs/#{job.id}/log.txt", {}, headers + response.should redirect_to("https://archive.travis-ci.org/jobs/#{job.id}/log.txt") + end + end end end From a565522f41348ebde62590d211d7028f1ce6b474 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 28 Jan 2013 03:43:24 +0100 Subject: [PATCH 12/12] Redirect to full amazon url Amazon can't work properly with SSL and CNAME for subdomains. For now we can use full amazon url. --- lib/travis/api/app/endpoint/jobs.rb | 2 +- spec/integration/v2/jobs_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 288c6bb9..b5a6d410 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -21,7 +21,7 @@ class Travis::Api::App end def archive_url(path) - "https://#{hostname('archive')}#{path}" + "https://s3.amazonaws.com/#{hostname('archive')}#{path}" end def hostname(name) diff --git a/spec/integration/v2/jobs_spec.rb b/spec/integration/v2/jobs_spec.rb index 847e56f5..fa617d15 100644 --- a/spec/integration/v2/jobs_spec.rb +++ b/spec/integration/v2/jobs_spec.rb @@ -29,7 +29,7 @@ describe 'Jobs' do it 'redirects to archive' do job.log.update_attributes!(content: 'the log', archived_at: Time.now, archive_verified: true) response = get "/jobs/#{job.id}/log.txt", {}, headers - response.should redirect_to("https://archive.travis-ci.org/jobs/#{job.id}/log.txt") + response.should redirect_to("https://s3.amazonaws.com/archive.travis-ci.org/jobs/#{job.id}/log.txt") end end @@ -37,7 +37,7 @@ describe 'Jobs' do it 'redirects to archive' do job.log.destroy response = get "/jobs/#{job.id}/log.txt", {}, headers - response.should redirect_to("https://archive.travis-ci.org/jobs/#{job.id}/log.txt") + response.should redirect_to("https://s3.amazonaws.com/archive.travis-ci.org/jobs/#{job.id}/log.txt") end end end