Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: fix some unit test funcion that can't run independently #31086

Merged
merged 6 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"math/rand"
"strings"
"sync/atomic"
"testing"
"time"

. "github.com/pingcap/check"
Expand All @@ -44,6 +45,7 @@ import (
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
ntestkit "github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/admin"
"github.com/pingcap/tidb/util/collate"
Expand Down Expand Up @@ -3523,3 +3525,30 @@ func (s *testSerialDBSuite1) TestAddPartitionReplicaBiggerThanTiFlashStores(c *C
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:-1]DDL job rollback, error msg: [ddl] add partition wait for tiflash replica to complete")
}

func TestDropAndTruncatePartition(t *testing.T) {
// Useless, but is required to initialize the global infoSync
// Otherwise this test throw a "infoSyncer is not initialized" error
_, clean := ntestkit.CreateMockStore(t)
defer clean()

ddl.ExportTestDropAndTruncatePartition(t)
}

func TestTable(t *testing.T) {
// Useless, but is required to initialize the global infoSync
// Otherwise this test throw a "infoSyncer is not initialized" error
_, clean := ntestkit.CreateMockStore(t)
defer clean()

ddl.ExportTestTable(t)
}

func TestRenameTables(t *testing.T) {
// Useless, but is required to initialize the global infoSync
// Otherwise this test throw a "infoSyncer is not initialized" error
_, clean := ntestkit.CreateMockStore(t)
defer clean()

ddl.ExportTestRenameTables(t)
}
2 changes: 1 addition & 1 deletion ddl/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestDropAndTruncatePartition(t *testing.T) {
func ExportTestDropAndTruncatePartition(t *testing.T) {
store := testCreateStoreT(t, "test_store")
d, err := testNewDDLAndStart(
context.Background(),
Expand Down
4 changes: 2 additions & 2 deletions ddl/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func testGetTableWithError(d *ddl, schemaID, tableID int64) (table.Table, error)
return tbl, nil
}

func TestTable(t *testing.T) {
func ExportTestTable(t *testing.T) {
store, err := mockstore.NewMockStore()
require.NoError(t, err)
ddl, err := testNewDDLAndStart(
Expand Down Expand Up @@ -346,7 +346,7 @@ func testAlterNoCacheTable(t *testing.T, ctx sessionctx.Context, d *ddl, newSche
return job
}

func TestRenameTables(t *testing.T) {
func ExportTestRenameTables(t *testing.T) {
store, err := mockstore.NewMockStore()
require.NoError(t, err)
ddl, err := testNewDDLAndStart(
Expand Down
27 changes: 19 additions & 8 deletions tools/check/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"io"
"bytes"
"fmt"
"math/rand"
Expand Down Expand Up @@ -344,13 +345,20 @@ func (n *numa) worker(wg *sync.WaitGroup, ch chan task) {
defer wg.Done()
for t := range ch {
start := time.Now()
if err := n.runTestCase(t.pkg, t.test, t.old); err != nil {
fmt.Println("run test case error", t.pkg, t.test, t.old, time.Since(start), err)
res := n.runTestCase(t.pkg, t.test, t.old)
if res.err != nil {
fmt.Println("[FAIL] ", t.pkg, t.test, t.old, time.Since(start), res.err)
io.Copy(os.Stderr, &res.output)
}
}
}

func (n *numa) runTestCase(pkg string, fn string, old bool) error {
type testResult struct {
err error
output bytes.Buffer
}

func (n *numa) runTestCase(pkg string, fn string, old bool) (res testResult) {
exe := "./" + testFileName(pkg)
var cmd *exec.Cmd
if n.numactl {
Expand All @@ -359,12 +367,13 @@ func (n *numa) runTestCase(pkg string, fn string, old bool) error {
cmd = n.testCommand(exe, fn, old)
}
cmd.Dir = path.Join(workDir, pkg)
_, err := cmd.CombinedOutput()
if err != nil {
// fmt.Println("run test case error", pkg, fn, string(output))
return err
// Combine the test case output, so the run result for failed cases can be displayed.
cmd.Stdout = &res.output
bb7133 marked this conversation as resolved.
Show resolved Hide resolved
cmd.Stderr = &res.output
if err := cmd.Run(); err != nil {
res.err = withTrace(err)
}
return nil
return res
}

func (n *numa) testCommandWithNumaCtl(exe string, fn string, old bool) *exec.Cmd {
Expand Down Expand Up @@ -415,6 +424,8 @@ func buildTestBinary(pkg string) error {
// go test -c
cmd := exec.Command("go", "test", "-c", "-vet", "off", "-o", testFileName(pkg))
cmd.Dir = path.Join(workDir, pkg)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
return withTrace(err)
}
Expand Down