Skip to content

Commit

Permalink
.*: complete test to improve test coverage radondb#713
Browse files Browse the repository at this point in the history
[summary]
add more test to improve the codecov of queryz.go and delete_plan.go

[test case]
src/backend/queryz_test.go
src/planner/delete_plan_test.go

[patch codecov]
src/backend/queryz.go 96.3%
src/planner/delete_plan.go 95.9%
  • Loading branch information
hustjieke committed Jan 21, 2021
1 parent 5e194ad commit ce54316
Show file tree
Hide file tree
Showing 8 changed files with 773 additions and 770 deletions.
2 changes: 1 addition & 1 deletion src/backend/queryz.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (a byStartTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a byStartTime) Less(i, j int) bool { return a[i].Start.Before(a[j].Start) }

// GetQueryzRows returns a list of QueryDetailzRow sorted by start time
func (qz *Queryz) GetQueryzRows() []QueryDetailzRow {
func (qz *Queryz) GetQueryzRows() byStartTime {
qz.mu.RLock()
rows := []QueryDetailzRow{}
for _, qd := range qz.queryDetails {
Expand Down
4 changes: 4 additions & 0 deletions src/backend/queryz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,9 @@ func TestQueryz(t *testing.T) {
rows := qz.GetQueryzRows()
assert.Equal(t, querys[0], rows[0].Query)
assert.Equal(t, querys[1], rows[1].Query)
// Test byStartTime.Swap() funciton to improve test coverage.
rows.Swap(0, 1)
assert.Equal(t, querys[0], rows[1].Query)
assert.Equal(t, querys[1], rows[0].Query)
}
}
26 changes: 22 additions & 4 deletions src/planner/delete_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ func TestDeleteUnsupportedPlan(t *testing.T) {
}

func TestDeleteErrorPlan(t *testing.T) {
query := "delete from A where id=1"
query1 := "delete from A where id=1"
query2 := "delete from B"

log := xlog.NewStdLog(xlog.Level(xlog.PANIC))
database := "sbtest"
Expand All @@ -274,12 +275,29 @@ func TestDeleteErrorPlan(t *testing.T) {
err = route.AddForTest(database, router.MockTableMConfig())
assert.Nil(t, err)
databaseNull := ""
node, err := sqlparser.Parse(query)
assert.Nil(t, err)
plan := NewDeletePlan(log, databaseNull, query, node.(*sqlparser.Delete), route)

// plan build
{
// test delete with no database.
node, err := sqlparser.Parse(query1)
assert.Nil(t, err)
plan := NewDeletePlan(log, databaseNull, query1, node.(*sqlparser.Delete), route)
planTree := NewPlanTree()
{
err := planTree.Add(plan)
assert.Nil(t, err)
}

{
err := planTree.Build()
assert.NotNil(t, err)
}
}
{
// test route table "B" not exist
node, err := sqlparser.Parse(query2)
assert.Nil(t, err)
plan := NewDeletePlan(log, database, query2, node.(*sqlparser.Delete), route)
planTree := NewPlanTree()
{
err := planTree.Add(plan)
Expand Down
4 changes: 2 additions & 2 deletions src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ce54316

Please sign in to comment.