From 853732c46fd07c840c7308bcfc7b6123e5673f92 Mon Sep 17 00:00:00 2001 From: Javier Torres Date: Tue, 28 Feb 2017 11:15:28 +0100 Subject: [PATCH] Recommit everything after merge disaster --- Gemfile | 1 + Gemfile.lock | 6 +++- spec/helpers/spec_helper_helpers.rb | 19 +++++++---- zeus.json | 30 ++++++++++++++++ zeus_plan.rb | 53 +++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 zeus.json create mode 100644 zeus_plan.rb diff --git a/Gemfile b/Gemfile index 2b7c0dd29b..c00b380992 100644 --- a/Gemfile +++ b/Gemfile @@ -116,6 +116,7 @@ group :development, :test do gem 'rb-readline' gem 'byebug' gem 'rack' + gem 'zeus' # Server gem 'thin', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 777a7dea1d..ece4e44d21 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -174,6 +174,7 @@ GEM treetop (~> 1.4.8) memory_profiler (0.9.6) metaclass (0.0.4) + method_source (0.8.2) mime-types (1.25.1) mini_portile (0.6.2) mocha (1.1.0) @@ -349,6 +350,8 @@ GEM websocket (1.2.2) xpath (0.1.4) nokogiri (~> 1.3) + zeus (0.15.13) + method_source (>= 0.6.7) PLATFORMS ruby @@ -429,6 +432,7 @@ DEPENDENCIES virtus (= 1.0.5) vizzuality-sequel-rails (= 0.3.7)! webrick (= 1.3.1) + zeus BUNDLED WITH - 1.11.2 + 1.14.2 diff --git a/spec/helpers/spec_helper_helpers.rb b/spec/helpers/spec_helper_helpers.rb index 4dbb1c2813..11bcb52fb4 100644 --- a/spec/helpers/spec_helper_helpers.rb +++ b/spec/helpers/spec_helper_helpers.rb @@ -6,13 +6,18 @@ module SpecHelperHelpers end def clean_metadata_database - protected_tables = [:schema_migrations, :spatial_ref_sys] - Rails::Sequel.connection.tables.each do |t| - if !protected_tables.include?(t) - begin - Rails::Sequel.connection.run("TRUNCATE TABLE \"#{t}\" CASCADE") - rescue Sequel::DatabaseError => e - raise e unless e.message =~ /PG::Error: ERROR: relation ".*" does not exist/ + if ENV['STELLAR'].present? + Rails::Sequel.connection.disconnect + system "#{ENV['STELLAR']} restore" + else + protected_tables = [:schema_migrations, :spatial_ref_sys] + Rails::Sequel.connection.tables.each do |t| + if !protected_tables.include?(t) + begin + Rails::Sequel.connection.run("TRUNCATE TABLE \"#{t}\" CASCADE") + rescue Sequel::DatabaseError => e + raise e unless e.message =~ /PG::Error: ERROR: relation ".*" does not exist/ + end end end end diff --git a/zeus.json b/zeus.json new file mode 100644 index 0000000000..c56c5d0a39 --- /dev/null +++ b/zeus.json @@ -0,0 +1,30 @@ +{ + "command": "ruby -rbundler/setup -r./zeus_plan -eZeus.go", + + "plan": { + "boot": { + "default_bundle": { + "development_environment": { + "prerake": { + "rake": [], + "carto_resque": ["resque"] + }, + "runner": ["r"], + "console": ["c"], + "server": ["s"], + "generate": ["g"], + "destroy": ["d"], + "dbconsole": ["dbm"], + "carto_user_dbconsole": ["dbd"] + }, + "test_environment": { + "carto_test": { + "test_helper": { + "test": ["rspec", "testrb"] + } + } + } + } + } + } +} diff --git a/zeus_plan.rb b/zeus_plan.rb new file mode 100644 index 0000000000..3a6b8b4415 --- /dev/null +++ b/zeus_plan.rb @@ -0,0 +1,53 @@ +require 'zeus/rails' + +require_relative 'spec/support/redis' +require_relative 'spec/helpers/spec_helper_helpers' + +class CustomPlan < Zeus::Rails + include SpecHelperHelpers + + def carto_test + # Disable before suite hooks + ENV['PARALLEL'] = 'true' + + # Clean up at least sometimes + drop_leaked_test_user_databases + + # Start redis server + CartoDB::RedisTest.up + + if ENV['TURBO'] + clean_redis_databases + clean_metadata_database + else + RSpec.configure do |config| + config.before(:all) do + # Clean redis + clean_redis_databases + clean_metadata_database + end + end + end + end + + def test + ENV['CHECK_SPEC'] = Process.pid.to_s if ENV['TURBO'] + Rails::Sequel.connection.disconnect + + super + end + + def carto_user_dbconsole + u = Carto::User.find_by_username(ARGV[0]) + exec "psql -U postgres #{u.database_name}" + end + + def carto_resque + ENV['VVERBOSE'] = 'true' + ENV['QUEUE'] = 'imports,exports,users,user_dbs,geocodings,synchronizations,tracker,user_migrations' + ARGV.replace(['resque:work']) + Rake.application.run + end +end + +Zeus.plan = CustomPlan.new