Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhaowu committed Nov 3, 2022
1 parent bf386e2 commit 0db9b4f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
11 changes: 9 additions & 2 deletions copydb/test/copydb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"fmt"
"os"
"testing"

"github.com/Shopify/ghostferry"
Expand Down Expand Up @@ -138,8 +139,14 @@ func (t *CopydbTestSuite) TestCreateDatabaseCopiesTheRightCollation() {
row := t.ferry.TargetDB.QueryRow(query)
err = row.Scan(&characterSet, &collation)
t.Require().Nil(err)
t.Require().Equal(characterSet, "utf8")
t.Require().Equal(collation, "utf8_general_ci")

if os.Getenv("MYSQL_VERSION") == "8.0" {
t.Require().Equal(characterSet, "utf8mb3")
t.Require().Equal(collation, "utf8mb3_general_ci")
} else {
t.Require().Equal(characterSet, "utf8")
t.Require().Equal(collation, "utf8_general_ci")
}

query = "SELECT table_collation FROM information_schema.tables WHERE table_schema = \"%s\" AND table_name = \"%s\""
query = fmt.Sprintf(query, renamedSchemaName, renamedTableName)
Expand Down
5 changes: 4 additions & 1 deletion sharding/test/primary_key_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package test
import (
"fmt"
"net/http"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -90,7 +91,9 @@ func (t *PrimaryKeyTableTestSuite) TestPrimaryKeyTableVerificationFailure() {
t.Ferry.Run()

t.Require().NotNil(errHandler.LastError)
t.Require().Equal("row fingerprints for paginationKeys [2] on gftest1.tenants_table do not match", errHandler.LastError.Error())

t.Require().True(strings.HasPrefix(errHandler.LastError.Error(), "row fingerprints for paginationKeys [{2"))
t.Require().True(strings.HasSuffix(errHandler.LastError.Error(), "on gftest1.tenants_table do not match"))
}

func TestPrimaryKeyTableTestSuite(t *testing.T) {
Expand Down
18 changes: 9 additions & 9 deletions test/integration/inline_verifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_corrupted_insert_is_detected_inline_with_batch_writer

assert verification_ran
assert_equal ["#{DEFAULT_DB}.#{DEFAULT_TABLE}"], incorrect_tables
assert_equal "cutover verification failed for: gftest.test_table_1 [paginationKeys: #{corrupting_id} ] ", ghostferry.error_lines.last["msg"]
assert ghostferry.error_lines.last["msg"].start_with?("cutover verification failed for: gftest.test_table_1 [paginationKeys: #{corrupting_id}")
end

def test_different_compressed_data_is_detected_inline_with_batch_writer
Expand Down Expand Up @@ -68,7 +68,7 @@ def test_different_compressed_data_is_detected_inline_with_batch_writer

assert verification_ran
assert_equal ["#{DEFAULT_DB}.#{DEFAULT_TABLE}"], incorrect_tables
assert_equal "cutover verification failed for: gftest.test_table_1 [paginationKeys: 1 ] ", ghostferry.error_lines.last["msg"]
assert ghostferry.error_lines.last["msg"].start_with?("cutover verification failed for: gftest.test_table_1 [paginationKeys: 1")
end

def test_same_decompressed_data_different_compressed_test_passes_inline_verification
Expand Down Expand Up @@ -163,7 +163,7 @@ def test_catches_binlog_streamer_corruption

ghostferry.run
assert verification_ran
assert_equal "cutover verification failed for: gftest.test_table_1 [paginationKeys: #{corrupting_id} ] ", ghostferry.error_lines.last["msg"]
assert ghostferry.error_lines.last["msg"].start_with?("cutover verification failed for: gftest.test_table_1 [paginationKeys: #{corrupting_id}")
end

def test_target_corruption_is_ignored_if_skip_target_verification
Expand Down Expand Up @@ -399,7 +399,7 @@ def test_catches_binlog_streamer_corruption_with_composite_pk
ghostferry.run
assert verification_ran
assert incorrect_tables_found, "verification did not catch corrupted table"
assert_equal "cutover verification failed for: #{DEFAULT_DB}.#{DEFAULT_TABLE} [paginationKeys: #{corrupting_id} ] ", ghostferry.error_lines.last["msg"]
assert ghostferry.error_lines.last["msg"].start_with?("cutover verification failed for: #{DEFAULT_DB}.#{DEFAULT_TABLE} [paginationKeys: #{corrupting_id}")
end

def test_positive_negative_zero
Expand Down Expand Up @@ -430,7 +430,7 @@ def test_positive_negative_zero

assert verification_ran
assert_equal ["#{DEFAULT_DB}.#{DEFAULT_TABLE}"], incorrect_tables
assert_equal "cutover verification failed for: #{DEFAULT_DB}.#{DEFAULT_TABLE} [paginationKeys: 1 ] ", ghostferry.error_lines.last["msg"]
assert ghostferry.error_lines.last["msg"].start_with?("cutover verification failed for: #{DEFAULT_DB}.#{DEFAULT_TABLE} [paginationKeys: 1")

# Now we run the real test case.
target_db.query("UPDATE #{DEFAULT_FULL_TABLE_NAME} SET data = -0.0 WHERE id = 1")
Expand Down Expand Up @@ -484,7 +484,7 @@ def test_null_vs_empty_string

assert verification_ran
assert_equal ["#{DEFAULT_DB}.#{DEFAULT_TABLE}"], incorrect_tables
assert_equal "cutover verification failed for: gftest.test_table_1 [paginationKeys: 1 ] ", ghostferry.error_lines.last["msg"]
assert ghostferry.error_lines.last["msg"].start_with?("cutover verification failed for: gftest.test_table_1 [paginationKeys: 1")
end

def test_null_vs_null_string
Expand All @@ -507,7 +507,7 @@ def test_null_vs_null_string

assert verification_ran
assert_equal ["#{DEFAULT_DB}.#{DEFAULT_TABLE}"], incorrect_tables
assert_equal "cutover verification failed for: gftest.test_table_1 [paginationKeys: 1 ] ", ghostferry.error_lines.last["msg"]
assert ghostferry.error_lines.last["msg"].start_with?("cutover verification failed for: gftest.test_table_1 [paginationKeys: 1")
end

def test_null_in_different_order
Expand All @@ -533,7 +533,7 @@ def test_null_in_different_order

assert verification_ran
assert_equal ["#{DEFAULT_DB}.#{DEFAULT_TABLE}"], incorrect_tables
assert_equal "cutover verification failed for: gftest.test_table_1 [paginationKeys: 1 ] ", ghostferry.error_lines.last["msg"]
assert ghostferry.error_lines.last["msg"].start_with?("cutover verification failed for: gftest.test_table_1 [paginationKeys: 1")
end

###################
Expand Down Expand Up @@ -605,7 +605,7 @@ def run_collation_test(data, source_charset, target_charset, identical:)

assert verify_during_cutover_ran
assert_equal ["#{DEFAULT_DB}.#{DEFAULT_TABLE}"], incorrect_tables
assert_equal "cutover verification failed for: gftest.test_table_1 [paginationKeys: 1 ] ", ghostferry.error_lines.last["msg"]
assert ghostferry.error_lines.last["msg"].start_with?("cutover verification failed for: gftest.test_table_1 [paginationKeys: 1")
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/integration/interrupt_resume_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def test_interrupt_resume_inline_verifier_will_verify_entries_in_reverify_store
assert_equal "gftest.test_table_1", incorrect_tables.first

error_line = ghostferry.error_lines.last
assert_equal "cutover verification failed for: gftest.test_table_1 [paginationKeys: #{chosen_id} ] ", error_line["msg"]
assert error_line["msg"].start_with?("cutover verification failed for: gftest.test_table_1 [paginationKeys: #{chosen_id}")
end

def test_interrupt_resume_inline_verifier_will_verify_additional_rows_changed_on_source_during_interrupt
Expand Down Expand Up @@ -306,7 +306,7 @@ def test_interrupt_resume_inline_verifier_will_verify_additional_rows_changed_on
assert_equal "gftest.test_table_1", incorrect_tables.first

error_line = ghostferry.error_lines.last
assert_equal "cutover verification failed for: gftest.test_table_1 [paginationKeys: #{chosen_id} ] ", error_line["msg"]
assert error_line["msg"].start_with?("cutover verification failed for: gftest.test_table_1 [paginationKeys: #{chosen_id}")
end

# originally taken from @kolbitsch-lastline in https://github.com/Shopify/ghostferry/pull/160
Expand Down Expand Up @@ -671,6 +671,6 @@ def test_issue_149_corrupted

assert verification_ran
assert_equal ["#{DEFAULT_DB}.#{DEFAULT_TABLE}"], incorrect_tables
assert_equal "cutover verification failed for: gftest.test_table_1 [paginationKeys: #{id_to_change} ] ", ghostferry.error_lines.last["msg"]
assert ghostferry.error_lines.last["msg"].start_with?("cutover verification failed for: gftest.test_table_1 [paginationKeys: #{id_to_change}")
end
end

0 comments on commit 0db9b4f

Please sign in to comment.