Skip to content

Commit

Permalink
Added some trivial integration tests
Browse files Browse the repository at this point in the history
Just ported some very basic tests for now, looking to port more tests.
  • Loading branch information
shuhaowu committed Sep 17, 2018
1 parent 663e0c3 commit 558c297
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/integration/cases/trivial_integration_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "ghostferry_integration"

class TrivialIntegrationTests < GhostferryIntegration::TestCase
def ghostferry_main_path
"go/minimal.go"
end


def test_copy_data_without_any_writes_to_source
@dbs.seed_simple_database_with_single_table
@ghostferry.run
assert_test_table_is_identical
end

def test_copy_data_with_writes_to_source
use_datawriter

@dbs.seed_simple_database_with_single_table

@ghostferry.run
assert_test_table_is_identical
end
end
77 changes: 77 additions & 0 deletions test/integration/ruby/ghostferry_integration/test_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
require "minitest"
require "minitest/hooks/test"

module GhostferryIntegration
class TestCase < Minitest::Test
include Minitest::Hooks
include GhostferryIntegration

##############
# Test Hooks #
##############

def before_all
@ghostferry = Ghostferry.new(ghostferry_main_path)
end

def after_all
@ghostferry.remove_binary
end

def before_setup
@dbs = DbManager.new
@dbs.reset_data

@datawriter = DataWriter.new(@dbs.source_db_config)
end

def after_teardown
# Will be a no op if already stopped or not started
@datawriter.stop
@datawriter.join
end

######################
# Test Setup Helpers #
######################

def use_datawriter
@ghostferry.on_status(Ghostferry::Status::READY) do
@datawriter.start
end

@ghostferry.on_status(Ghostferry::Status::ROW_COPY_COMPLETED) do
# At the start of the cutover phase, we have to set the database to
# read-only. This is done by stopping the datawriter.
@datawriter.stop
@datawriter.join
end
end

#####################
# Assertion Helpers #
#####################

def assert_test_table_is_identical
source, target = @dbs.source_and_target_table_metrics

assert source[DbManager::DEFAULT_FULL_TABLE_NAME][:row_count] > 0
assert target[DbManager::DEFAULT_FULL_TABLE_NAME][:row_count] > 0

assert_equal(
source[DbManager::DEFAULT_FULL_TABLE_NAME][:checksum],
target[DbManager::DEFAULT_FULL_TABLE_NAME][:checksum],
)

assert_equal(
source[DbManager::DEFAULT_FULL_TABLE_NAME][:sample_row],
target[DbManager::DEFAULT_FULL_TABLE_NAME][:sample_row],
)
end

protected
def ghostferry_main_path
raise NotImplementedError
end
end
end
6 changes: 6 additions & 0 deletions test/integration/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "minitest/autorun"

ruby_path = File.join(File.absolute_path(File.dirname(__FILE__)), "ruby")
$LOAD_PATH.unshift(ruby_path) unless $LOAD_PATH.include?(ruby_path)

require_relative "cases/trivial_integration_tests"

0 comments on commit 558c297

Please sign in to comment.