Skip to content

Commit

Permalink
Merge pull request #318 from cashapp/jayj/fix-tests
Browse files Browse the repository at this point in the history
rename test tables to avoid conflicts
  • Loading branch information
jayjanssen authored Jul 1, 2024
2 parents 6d7131c + 60f33bd commit 2301f6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
32 changes: 16 additions & 16 deletions pkg/checksum/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ import (
)

func TestBasicChecksum(t *testing.T) {
testutils.RunSQL(t, "DROP TABLE IF EXISTS t1, _t1_new, _t1_chkpnt")
testutils.RunSQL(t, "CREATE TABLE t1 (a INT NOT NULL, b INT, c INT, PRIMARY KEY (a))")
testutils.RunSQL(t, "CREATE TABLE _t1_new (a INT NOT NULL, b INT, c INT, PRIMARY KEY (a))")
testutils.RunSQL(t, "CREATE TABLE _t1_chkpnt (a INT)") // for binlog advancement
testutils.RunSQL(t, "INSERT INTO t1 VALUES (1, 2, 3)")
testutils.RunSQL(t, "INSERT INTO _t1_new VALUES (1, 2, 3)")
testutils.RunSQL(t, "DROP TABLE IF EXISTS basic_checksum, _basic_checksum_new, _basic_checksum_chkpnt")
testutils.RunSQL(t, "CREATE TABLE basic_checksum (a INT NOT NULL, b INT, c INT, PRIMARY KEY (a))")
testutils.RunSQL(t, "CREATE TABLE _basic_checksum_new (a INT NOT NULL, b INT, c INT, PRIMARY KEY (a))")
testutils.RunSQL(t, "CREATE TABLE _basic_checksum_chkpnt (a INT)") // for binlog advancement
testutils.RunSQL(t, "INSERT INTO basic_checksum VALUES (1, 2, 3)")
testutils.RunSQL(t, "INSERT INTO _basic_checksum_new VALUES (1, 2, 3)")

db, err := dbconn.New(testutils.DSN(), dbconn.NewDBConfig())
assert.NoError(t, err)

t1 := table.NewTableInfo(db, "test", "t1")
t1 := table.NewTableInfo(db, "test", "basic_checksum")
assert.NoError(t, t1.SetInfo(context.TODO()))
t2 := table.NewTableInfo(db, "test", "_t1_new")
t2 := table.NewTableInfo(db, "test", "_basic_checksum_new")
assert.NoError(t, t2.SetInfo(context.TODO()))
logger := logrus.New()

Expand All @@ -53,19 +53,19 @@ func TestBasicChecksum(t *testing.T) {
}

func TestBasicValidation(t *testing.T) {
testutils.RunSQL(t, "DROP TABLE IF EXISTS t1, t2, _t1_chkpnt")
testutils.RunSQL(t, "CREATE TABLE t1 (a INT NOT NULL, b INT, c INT, PRIMARY KEY (a))")
testutils.RunSQL(t, "CREATE TABLE t2 (a INT NOT NULL, b INT, c INT, PRIMARY KEY (a))")
testutils.RunSQL(t, "CREATE TABLE _t1_chkpnt (a INT)") // for binlog advancement
testutils.RunSQL(t, "INSERT INTO t1 VALUES (1, 2, 3)")
testutils.RunSQL(t, "INSERT INTO t2 VALUES (1, 2, 3)")
testutils.RunSQL(t, "DROP TABLE IF EXISTS basic_validation, basic_validation2, _basic_validation_chkpnt")
testutils.RunSQL(t, "CREATE TABLE basic_validation (a INT NOT NULL, b INT, c INT, PRIMARY KEY (a))")
testutils.RunSQL(t, "CREATE TABLE basic_validation2 (a INT NOT NULL, b INT, c INT, PRIMARY KEY (a))")
testutils.RunSQL(t, "CREATE TABLE _basic_validation_chkpnt (a INT)") // for binlog advancement
testutils.RunSQL(t, "INSERT INTO basic_validation VALUES (1, 2, 3)")
testutils.RunSQL(t, "INSERT INTO basic_validation2 VALUES (1, 2, 3)")

db, err := dbconn.New(testutils.DSN(), dbconn.NewDBConfig())
assert.NoError(t, err)

t1 := table.NewTableInfo(db, "test", "t1")
t1 := table.NewTableInfo(db, "test", "basic_validation")
assert.NoError(t, t1.SetInfo(context.TODO()))
t2 := table.NewTableInfo(db, "test", "t2")
t2 := table.NewTableInfo(db, "test", "basic_validation2")
assert.NoError(t, t2.SetInfo(context.TODO()))
logger := logrus.New()

Expand Down
8 changes: 4 additions & 4 deletions pkg/dbconn/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func TestNewConn(t *testing.T) {
}

func TestNewConnRejectsReadOnlyConnections(t *testing.T) {
testutils.RunSQL(t, "DROP TABLE IF EXISTS t1")
testutils.RunSQL(t, "CREATE TABLE t1 (a INT NOT NULL, b INT, c INT, PRIMARY KEY (a))")
testutils.RunSQL(t, "DROP TABLE IF EXISTS conn_read_only")
testutils.RunSQL(t, "CREATE TABLE conn_read_only (a INT NOT NULL, b INT, c INT, PRIMARY KEY (a))")

config := NewDBConfig()
// Setting the connection pool size = 1 && transaction_read_only = 1 for the session.
Expand All @@ -77,11 +77,11 @@ func TestNewConnRejectsReadOnlyConnections(t *testing.T) {
// This would error, but `database/sql` automatically retries on a
// new connection which is not read-only, and eventually succeed.
// See also: rejectReadOnly test in `go-sql-driver/mysql`: https://github.com/go-sql-driver/mysql/blob/52c1917d99904701db2b0e4f14baffa948009cd7/driver_test.go#L2270-L2301
_, err = db.Exec("insert into t1 values (1, 2, 3)")
_, err = db.Exec("insert into conn_read_only values (1, 2, 3)")
assert.NoError(t, err)

var count int
err = db.QueryRow("select count(*) from t1 where a = 1").Scan(&count)
err = db.QueryRow("select count(*) from conn_read_only where a = 1").Scan(&count)
assert.NoError(t, err)
assert.Equal(t, 1, count)
}

0 comments on commit 2301f6e

Please sign in to comment.