This commit is contained in:
Yasuhiro Matsumoto 2017-08-02 02:06:40 +09:00
parent 7133e5d7f5
commit 6654e412c3
1 changed files with 35 additions and 34 deletions

View File

@ -1424,19 +1424,20 @@ var db *TestDB
var testTables = []string{"foo", "bar", "t", "bench"} var testTables = []string{"foo", "bar", "t", "bench"}
var tests = []testing.InternalTest{ var tests = []testing.InternalTest{
{Name: "TestBlobs", F: TestBlobs}, {Name: "TestResult", F: testResult},
{Name: "TestManyQueryRow", F: TestManyQueryRow}, {Name: "TestBlobs", F: testBlobs},
{Name: "TestTxQuery", F: TestTxQuery}, {Name: "TestManyQueryRow", F: testManyQueryRow},
{Name: "TestPreparedStmt", F: TestPreparedStmt}, {Name: "TestTxQuery", F: testTxQuery},
{Name: "TestPreparedStmt", F: testPreparedStmt},
} }
var benchmarks = []testing.InternalBenchmark{ var benchmarks = []testing.InternalBenchmark{
{Name: "BenchmarkExec", F: BenchmarkExec}, {Name: "BenchmarkExec", F: benchmarkExec},
{Name: "BenchmarkQuery", F: BenchmarkQuery}, {Name: "BenchmarkQuery", F: benchmarkQuery},
{Name: "BenchmarkParams", F: BenchmarkParams}, {Name: "BenchmarkParams", F: benchmarkParams},
{Name: "BenchmarkStmt", F: BenchmarkStmt}, {Name: "BenchmarkStmt", F: benchmarkStmt},
{Name: "BenchmarkRows", F: BenchmarkRows}, {Name: "BenchmarkRows", F: benchmarkRows},
{Name: "BenchmarkStmtRows", F: BenchmarkStmtRows}, {Name: "BenchmarkStmtRows", F: benchmarkStmtRows},
} }
func (db *TestDB) mustExec(sql string, args ...interface{}) sql.Result { func (db *TestDB) mustExec(sql string, args ...interface{}) sql.Result {
@ -1451,9 +1452,9 @@ func (db *TestDB) tearDown() {
for _, tbl := range testTables { for _, tbl := range testTables {
switch db.dialect { switch db.dialect {
case SQLITE: case SQLITE:
db.Exec("drop table if exists " + tbl) db.mustExec("drop table if exists " + tbl)
case MYSQL, POSTGRESQL: case MYSQL, POSTGRESQL:
db.Exec("drop table if exists " + tbl) db.mustExec("drop table if exists " + tbl)
default: default:
db.Fatal("unknown dialect") db.Fatal("unknown dialect")
} }
@ -1526,8 +1527,8 @@ func makeBench() {
} }
} }
// TestResult is test for result // testResult is test for result
func TestResult(t *testing.T) { func testResult(t *testing.T) {
db.tearDown() db.tearDown()
db.mustExec("create temporary table test (id " + db.serialPK() + ", name varchar(10))") db.mustExec("create temporary table test (id " + db.serialPK() + ", name varchar(10))")
@ -1553,8 +1554,8 @@ func TestResult(t *testing.T) {
} }
} }
// TestBlobs is test for blobs // testBlobs is test for blobs
func TestBlobs(t *testing.T) { func testBlobs(t *testing.T) {
db.tearDown() db.tearDown()
var blob = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} var blob = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
db.mustExec("create table foo (id integer primary key, bar " + db.blobType(16) + ")") db.mustExec("create table foo (id integer primary key, bar " + db.blobType(16) + ")")
@ -1580,8 +1581,8 @@ func TestBlobs(t *testing.T) {
} }
} }
// TestManyQueryRow is test for many query row // testManyQueryRow is test for many query row
func TestManyQueryRow(t *testing.T) { func testManyQueryRow(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Log("skipping in short mode") t.Log("skipping in short mode")
return return
@ -1598,8 +1599,8 @@ func TestManyQueryRow(t *testing.T) {
} }
} }
// TestTxQuery is test for transactional query // testTxQuery is test for transactional query
func TestTxQuery(t *testing.T) { func testTxQuery(t *testing.T) {
db.tearDown() db.tearDown()
tx, err := db.Begin() tx, err := db.Begin()
if err != nil { if err != nil {
@ -1637,8 +1638,8 @@ func TestTxQuery(t *testing.T) {
} }
} }
// TestPreparedStmt is test for prepared statement // testPreparedStmt is test for prepared statement
func TestPreparedStmt(t *testing.T) { func testPreparedStmt(t *testing.T) {
db.tearDown() db.tearDown()
db.mustExec("CREATE TABLE t (count INT)") db.mustExec("CREATE TABLE t (count INT)")
sel, err := db.Prepare("SELECT count FROM t ORDER BY count DESC") sel, err := db.Prepare("SELECT count FROM t ORDER BY count DESC")
@ -1683,8 +1684,8 @@ func TestPreparedStmt(t *testing.T) {
// test -bench but calling Benchmark() from a benchmark test // test -bench but calling Benchmark() from a benchmark test
// currently hangs go. // currently hangs go.
// BenchmarkExec is benchmark for exec // benchmarkExec is benchmark for exec
func BenchmarkExec(b *testing.B) { func benchmarkExec(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
if _, err := db.Exec("select 1"); err != nil { if _, err := db.Exec("select 1"); err != nil {
panic(err) panic(err)
@ -1692,8 +1693,8 @@ func BenchmarkExec(b *testing.B) {
} }
} }
// BenchmarkQuery is benchmark for query // benchmarkQuery is benchmark for query
func BenchmarkQuery(b *testing.B) { func benchmarkQuery(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
var n sql.NullString var n sql.NullString
var i int var i int
@ -1706,8 +1707,8 @@ func BenchmarkQuery(b *testing.B) {
} }
} }
// BenchmarkParams is benchmark for params // benchmarkParams is benchmark for params
func BenchmarkParams(b *testing.B) { func benchmarkParams(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
var n sql.NullString var n sql.NullString
var i int var i int
@ -1720,8 +1721,8 @@ func BenchmarkParams(b *testing.B) {
} }
} }
// BenchmarkStmt is benchmark for statement // benchmarkStmt is benchmark for statement
func BenchmarkStmt(b *testing.B) { func benchmarkStmt(b *testing.B) {
st, err := db.Prepare("select ?, ?, ?, ?") st, err := db.Prepare("select ?, ?, ?, ?")
if err != nil { if err != nil {
panic(err) panic(err)
@ -1740,8 +1741,8 @@ func BenchmarkStmt(b *testing.B) {
} }
} }
// BenchmarkRows is benchmark for rows // benchmarkRows is benchmark for rows
func BenchmarkRows(b *testing.B) { func benchmarkRows(b *testing.B) {
db.once.Do(makeBench) db.once.Do(makeBench)
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
@ -1765,8 +1766,8 @@ func BenchmarkRows(b *testing.B) {
} }
} }
// BenchmarkStmtRows is benchmark for statement rows // benchmarkStmtRows is benchmark for statement rows
func BenchmarkStmtRows(b *testing.B) { func benchmarkStmtRows(b *testing.B) {
db.once.Do(makeBench) db.once.Do(makeBench)
st, err := db.Prepare("select * from bench") st, err := db.Prepare("select * from bench")