Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing: Shared test task handles db dependencies better #19537

Merged
merged 1 commit into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ def rack_env?(*env)
e.include? rack_env
end

def with_rack_env(temporary_env)
previous_env = CDO.rack_env
CDO.rack_env = temporary_env
yield
CDO.rack_env = previous_env
end

def deploy_dir(*dirs)
CDO.dir(*dirs)
end
Expand Down
13 changes: 12 additions & 1 deletion shared/rake/test.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
require 'rake/testtask'
task :test do
require 'cdo/rake_utils'

task :prepare_dbs do
with_rack_env(:test) do
Dir.chdir(pegasus_dir) do
puts 'Migrating pegasus test database...'
RakeUtils.rake 'db:ensure_created', 'db:migrate', 'seed:migrate'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if invoking these Rake tasks from within the existing process (using Rake::Task['db:ensure_created'].invoke rather than RakeUtils.rake) would make this preparation run any quicker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replacement you suggested here doesn't work out of the box, because it can't find the db:ensure_created task. I think that's because we're in shared/rake/test.rake but we're trying to run tasks in pegasus/rake/db.rake (hence the directory change). Do you know if there's a clean way to make those pegasus tasks available without exposing them all as part of this rakefile?

end
end
end

task test: [:prepare_dbs] do
ENV['RACK_ENV'] = 'test' if rack_env?(:development)
ENV['HONEYBADGER_LOGGING_LEVEL'] = 'error'
Rake::TestTask.new.tap do |t|
Expand Down