Skip to content

Commit

Permalink
Try another approach to see if it passes in CircleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Stone committed Feb 23, 2017
1 parent 1d27875 commit 0bbf8c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions dashboard/test/integration/pardot_test.rb
Expand Up @@ -5,6 +5,20 @@
COLUMN_NAME_TO_INDEX_MAP = { "roles": 0, "ages_taught": 1 }.freeze

class PardotTest < ActiveSupport::TestCase
def setup
# Create the contact_rollups_daily table, which in production exists only on the replica server. Do it here outside
# the main ActiveRecord connection. The test framework runs the test inside a transaction on the ActiveRecord connection
# in order to be able to roll back the transaction and discard test changes at the end of the test. CREATE TABLE on
# that connection would cause an implicit commit of the transaction and break tests. The simplest way to get a different
# ActiveRecord connection is to run the command in a different thread. The structure below ensures the connection
# is returned to the connection pool at the end of the block.
Thread.new do
ActiveRecord::Base.connection_pool.with_connection do |connection|
connection.execute "CREATE TABLE IF NOT EXISTS pegasus_test.contact_rollups_daily LIKE pegasus_test.contact_rollups"
end
end.join
end

This comment has been minimized.

Copy link
@aoby

aoby Feb 23, 2017

Contributor

Note setup runs before every test case, so I don't think you gain anything by doing it in a new thread and connection.

def test_empty_contacts
# Test the rollup process with an empty database
rollups_test_helper 0, []
Expand Down
6 changes: 4 additions & 2 deletions lib/cdo/contact_rollups.rb
Expand Up @@ -185,8 +185,10 @@ def self.create_destination_table
# runs the test inside a transaction on the ActiveRecord connection in order to be able to roll back the transaction
# and discard test changes at the end of the test. CREATE TABLE on that connection would cause an implicit commit
# of the transaction and break tests. So we use a different connection to run schema modification commands.
PEGASUS_REPORTING_DB.run "DROP TABLE IF EXISTS #{DEST_TABLE_NAME}"
PEGASUS_REPORTING_DB.run "CREATE TABLE #{DEST_TABLE_NAME} LIKE #{TEMPLATE_TABLE_NAME}"
unless Rails.env.test?
PEGASUS_REPORTING_DB.run "DROP TABLE IF EXISTS #{DEST_TABLE_NAME}"
PEGASUS_REPORTING_DB.run "CREATE TABLE #{DEST_TABLE_NAME} LIKE #{TEMPLATE_TABLE_NAME}"
end

log_completion(start)
end
Expand Down

0 comments on commit 0bbf8c9

Please sign in to comment.