From 0bbf8c9428f252401ccdc23131da209a0493dd4c Mon Sep 17 00:00:00 2001 From: Jeremy Stone Date: Thu, 23 Feb 2017 12:01:34 -0800 Subject: [PATCH] Try another approach to see if it passes in CircleCI --- dashboard/test/integration/pardot_test.rb | 14 ++++++++++++++ lib/cdo/contact_rollups.rb | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dashboard/test/integration/pardot_test.rb b/dashboard/test/integration/pardot_test.rb index c4c71860ea871..d3077500ff76b 100644 --- a/dashboard/test/integration/pardot_test.rb +++ b/dashboard/test/integration/pardot_test.rb @@ -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 + def test_empty_contacts # Test the rollup process with an empty database rollups_test_helper 0, [] diff --git a/lib/cdo/contact_rollups.rb b/lib/cdo/contact_rollups.rb index eb66f1f7c4f6f..66b8bd81f6011 100644 --- a/lib/cdo/contact_rollups.rb +++ b/lib/cdo/contact_rollups.rb @@ -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