Skip to content

Commit

Permalink
paralellize tests 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
codez committed Sep 11, 2019
1 parent dd50d34 commit 667eb54
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-*
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
- AIRTIME_DB_ADAPTER=postgresql
- AIRTIME_DB_NAME=airtime_test
- AIRTIME_DB_USERNAME=postgres
- PARALLEL_WORKERS=1

sudo: false

Expand Down
9 changes: 8 additions & 1 deletion app/services/file_store/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ class Structure
class << self

def home
Rails.application.secrets.archive_home
home = Rails.application.secrets.archive_home
# rubocop:disable Style/GlobalVars
if Rails.env.test? && $TEST_WORKER
File.join(home, $TEST_WORKER.to_s)
# rubocop:enable Style/GlobalVars
else
home
end
end

end
Expand Down
18 changes: 16 additions & 2 deletions app/services/import/recording/finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ def imported
end

def import_directories
Rails.application.secrets.import_directories ||
raise('IMPORT_DIRECTORIES not set!')
if Rails.env.test? && $TEST_WORKER # rubocop:disable Style/GlobalVars
parallelized_import_directories
else
config_import_directories
end
end

private
Expand All @@ -27,6 +30,17 @@ def glob_recordings(pattern)
end.flatten
end

def config_import_directories
Rails.application.secrets.import_directories ||
raise('IMPORT_DIRECTORIES not set!')
end

def parallelized_import_directories
config_import_directories.map do |dir|
::File.join(dir, $TEST_WORKER.to_s) # rubocop:disable Style/GlobalVars
end
end

end

end
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/status_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class StatusControllerTest < ActionController::TestCase

setup do
FileUtils.mkdir_p(Rails.application.secrets.archive_home)
FileUtils.touch(File.join(Rails.application.secrets.archive_home, 'dummy_content.data'))
FileUtils.mkdir_p(FileStore::Structure.home)
FileUtils.touch(File.join(FileStore::Structure.home, 'dummy_content.data'))
end

test 'GET show returns json' do
Expand Down
4 changes: 2 additions & 2 deletions test/models/status_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class StatusTest < ActiveSupport::TestCase
end

test 'file_system is true if directory has content' do
FileUtils.mkdir_p(Rails.application.secrets.archive_home)
FileUtils.touch(File.join(Rails.application.secrets.archive_home, 'dummy_content.data'))
FileUtils.mkdir_p(FileStore::Structure.home)
FileUtils.touch(File.join(FileStore::Structure.home, 'dummy_content.data'))
assert_equal true, Status.new.file_system
end

Expand Down
10 changes: 10 additions & 0 deletions test/support/airtime_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ module AirtimeHelper

included do
setup :setup_airtime
parallelize_setup { |worker| create_airtime_db(worker) }
end

module ClassMethods
def create_airtime_db(worker)
Airtime::Base.establish_connection(
adapter: :sqlite3,
database: "db/airtime_test_#{worker}.sqlite3"
)
end
end

private
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@

class ActiveSupport::TestCase

parallelize(workers: :number_of_processors)

# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all

# Add more helper methods to be used by all tests here...
include CustomAssertions

parallelize_setup do |worker|
$TEST_WORKER = worker # use global variable for process based parallelization
end

def encode_token(token)
ActionController::HttpAuthentication::Token.encode_credentials(token)
end
Expand Down

0 comments on commit 667eb54

Please sign in to comment.