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

Add integration test #1083

Merged
merged 45 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
64bee06
test: init integration
shhdgit Dec 1, 2021
e354632
test: integration init
shhdgit Dec 1, 2021
59de412
test(integration): slowquery init
shhdgit Dec 2, 2021
886a2fb
test(*): refine tests scripts
shhdgit Dec 5, 2021
4a98ebc
test(slow_query): add db session
shhdgit Dec 5, 2021
ee8a5e9
Merge branch 'master' into test/integration
shhdgit Dec 5, 2021
95833fe
test: refine test scripts
shhdgit Dec 6, 2021
8f52c9d
Merge branch 'test/integration' of github.com:shhdgit/tidb-dashboard …
shhdgit Dec 6, 2021
ba7c7bb
Merge branch 'master' into test/integration
shhdgit Dec 6, 2021
4712414
test: update bin path
shhdgit Dec 6, 2021
074c180
test: echo profile
shhdgit Dec 6, 2021
7fb34c0
test: update source configs
shhdgit Dec 6, 2021
5c15f49
test: update integration log path
shhdgit Dec 6, 2021
9cc9b04
test: echo config path
shhdgit Dec 6, 2021
c51bc38
test: update tiup setup
shhdgit Dec 6, 2021
bd7eca7
test: update tiup usage
shhdgit Dec 7, 2021
f95f499
test: temp disable diagnose integration test
shhdgit Dec 7, 2021
eaa39b4
Merge branch 'master' into test/integration
shhdgit Dec 9, 2021
a1ce514
tweak: tiup teardown precisely
shhdgit Dec 15, 2021
3081b7a
test: slow query test
shhdgit Dec 16, 2021
8b890df
test: coverage
shhdgit Dec 16, 2021
8c5adce
chore: move integration tests
shhdgit Dec 16, 2021
2823bd7
test: compatibility test
shhdgit Dec 16, 2021
cd531f2
Merge branch 'master' into test/integration
shhdgit Dec 16, 2021
751c101
fix: bin not exist
shhdgit Dec 17, 2021
79aa642
ci: integration test matrix
shhdgit Dec 17, 2021
b244861
chore: dump tips
shhdgit Dec 17, 2021
ce0679c
test: split diagnose test
shhdgit Dec 17, 2021
ad1c13b
refine: test cases
shhdgit Dec 19, 2021
e67b261
tweak: compatibility tests
shhdgit Dec 19, 2021
e754113
tweak: compatibility test
shhdgit Dec 20, 2021
25c2bee
tweak: slowquery tests
shhdgit Dec 20, 2021
4c21254
fix: compatibility tests
shhdgit Dec 20, 2021
c7af711
test: add prev stmt search test
shhdgit Dec 20, 2021
38d3dac
tweak: close sys schema cache
shhdgit Dec 20, 2021
c611683
chore: rename TestCompatibilitySuite
shhdgit Dec 20, 2021
67e33ca
tweak: split create table workflow for local tests
shhdgit Dec 20, 2021
dd1d515
tweak: makefile phony definition
shhdgit Dec 20, 2021
7aef798
test: code coverage
shhdgit Dec 20, 2021
5d43c2d
test: code coverage
shhdgit Dec 20, 2021
27d2cfb
test: coverage flags
shhdgit Dec 20, 2021
f1d440a
chore: comments
shhdgit Dec 20, 2021
9404f95
chore: add badge to readme
shhdgit Dec 20, 2021
b57f6c7
Revert "chore: add badge to readme"
shhdgit Dec 20, 2021
8817949
chore: rename coverage flag
shhdgit Dec 20, 2021
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
4 changes: 2 additions & 2 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: pull_request

jobs:
backend:
name: backend
name: Backend
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down Expand Up @@ -34,7 +34,7 @@ jobs:
git diff --exit-code

frontend:
name: frontend
name: Frontend
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down
45 changes: 44 additions & 1 deletion .github/workflows/e2e-test.yaml → .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,51 @@ on:
- release

jobs:
backend_ut:
name: Backend Unit Test
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: "1.13.5"
- name: Load go module cache
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run unit test
run: |
make unit_test
backend_integration:
name: Backend Integration Test
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
tidb_version: [latest, v4.0.1]
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: "1.13.5"
- name: Load go module cache
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run integration test
run: |
make integration_test TIDB_VERSION=${{ matrix.tidb_version }}
e2e_test:
name: UI
name: E2E
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
coverage/

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
Expand Down
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: install_tools lint dev yarn_dependencies go_generate ui server run
.PHONY: install_tools lint dev yarn_dependencies go_generate ui server run test unit_test integration_test

DASHBOARD_PKG := github.com/pingcap/tidb-dashboard

Expand All @@ -16,14 +16,29 @@ LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.PDVersion=N/A"
LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.BuildGitHash=$(shell git rev-parse HEAD)"

TIDB_VERSION ?= latest

default: server

clean:
rm -rf ./coverage

install_tools:
scripts/install_go_tools.sh

lint:
scripts/lint.sh

test: clean unit_test integration_test

unit_test:
shhdgit marked this conversation as resolved.
Show resolved Hide resolved
@mkdir -p ./coverage
GO111MODULE=on go test -v -cover -coverprofile=coverage/ut.out ./pkg/... ./util/...

integration_test:
@mkdir -p ./coverage
@TIDB_VERSION=${TIDB_VERSION} tests/run.sh

dev: lint default

yarn_dependencies: install_tools
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/gtank/cryptopasta v0.0.0-20170601214702-1f550f6f2f69
github.com/henrylee2cn/ameda v1.4.10
github.com/jarcoal/httpmock v1.0.8
github.com/joho/godotenv v1.3.0
github.com/joho/godotenv v1.4.0
github.com/joomcode/errorx v1.0.1
github.com/minio/sio v0.3.0
github.com/oleiade/reflections v1.0.1
Expand All @@ -33,8 +33,9 @@ require (
github.com/pingcap/kvproto v0.0.0-20200411081810-b85805c9476c
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354
github.com/rs/cors v1.7.0
github.com/shhdgit/testfixtures/v3 v3.6.2-0.20211219171712-c4f264d673d3
Copy link
Member Author

@shhdgit shhdgit Dec 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to adapt tidb checksum logic, I'll create a pr to upstream later

github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0
github.com/spf13/pflag v1.0.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba
github.com/swaggo/swag v1.6.6-0.20200529100950-7c765ddd0476
Expand Down
104 changes: 96 additions & 8 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (s *Service) Start(ctx context.Context) error {
tidb.NewTiDBClient,
tikv.NewTiKVClient,
tiflash.NewTiFlashClient,
utils.NewSysSchema,
utils.ProvideSysSchema,
info.NewService,
clusterinfo.NewService,
logsearch.NewService,
Expand Down
140 changes: 0 additions & 140 deletions pkg/apiserver/diagnose/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
package diagnose

import (
"fmt"
"strings"
"testing"

. "github.com/pingcap/check"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)

func TestT(t *testing.T) {
Expand All @@ -21,98 +17,6 @@ var _ = Suite(&testReportSuite{})

type testReportSuite struct{}

//func (t *testReportSuite) TestReport(c *C) {
// cli, err := gorm.Open("mysql", "root:@tcp(172.16.5.40:4009)/test?charset=utf8&parseTime=True&loc=Local")
// c.Assert(err, IsNil)
// defer cli.Close()
//
// startTime := "2020-03-03 17:18:00"
// endTime := "2020-03-03 17:21:00"
//
// tables := GetReportTablesForDisplay(startTime, endTime, cli)
// for _, tbl := range tables {
// printRows(tbl)
// }
//}

func (t *testReportSuite) TestGetTable(c *C) {
cli, err := gorm.Open(mysql.Open("root:@tcp(172.16.5.40:4009)/test?charset=utf8&parseTime=True&loc=Local"))
c.Assert(err, IsNil)

startTime := "2020-03-25 23:00:00"
endTime := "2020-03-25 23:05:00"

var table TableDef
table, err = GetLoadTable(startTime, endTime, cli)
c.Assert(err, IsNil)
printRows(&table)
}

func (t *testReportSuite) TestGetCompareTable(c *C) {
cli, err := gorm.Open(mysql.Open("root:@tcp(172.16.5.40:4009)/test?charset=utf8&parseTime=True&loc=Local"))
c.Assert(err, IsNil)

//startTime1 := "2020-03-12 20:17:00"
//endTime1 := "2020-03-12 20:39:00"
//
//startTime2 := "2020-03-12 20:17:00"
//endTime2 := "2020-03-12 20:39:00"

startTime1 := "2020-04-02 12:13:00"
endTime1 := "2020-04-02 12:15:00"

startTime2 := "2020-04-02 12:15:00"
endTime2 := "2020-04-02 12:17:00"

tables := GetCompareReportTablesForDisplay(startTime1, endTime1, startTime2, endTime2, cli, nil, "ID")
for _, tbl := range tables {
printRows(tbl)
}
}

func (t *testReportSuite) TestInspection(c *C) {
cli, err := gorm.Open(mysql.Open("root:@tcp(172.16.5.40:4009)/test?charset=utf8&parseTime=True&loc=Local"))
c.Assert(err, IsNil)

// affect by big query join
startTime1 := "2020-03-08 01:36:00"
endTime1 := "2020-03-08 01:41:00"

startTime2 := "2020-03-08 01:46:30"
endTime2 := "2020-03-08 01:51:30"

// affect by big write with conflict
//startTime1 := "2020-03-10 12:35:00"
//endTime1 := "2020-03-10 12:39:00"
//
//startTime2 := "2020-03-10 12:41:00"
//endTime2 := "2020-03-10 12:45:00"

// affect by big write without conflict
//startTime1 := " 2020-03-10 13:20:00"
//endTime1 := " 2020-03-10 13:23:00"
//
//startTime2 := "2020-03-10 13:24:00"
//endTime2 := "2020-03-10 13:27:00"

// diagnose for server down
// startTime1 := "2020-03-09 20:35:00"
// endTime1 := "2020-03-09 21:20:00"
// startTime2 := "2020-03-08 20:35:00"
// endTime2 := "2020-03-09 21:20:00"

// diagnose for disk slow , need more disk metric.
//startTime1 := "2020-03-10 12:48:00"
//endTime1 := "2020-03-10 12:50:00"
//
//startTime2 := "2020-03-10 12:54:30"
//endTime2 := "2020-03-10 12:56:30"

table, errRow := CompareDiagnose(startTime1, endTime1, startTime2, endTime2, cli)
c.Assert(errRow, IsNil)
printRows(&table)
}

func (t *testReportSuite) TestCompareTable(c *C) {
table1 := TableDef{
Category: []string{"header"},
Expand Down Expand Up @@ -222,47 +126,3 @@ func (t *testReportSuite) TestRoundFloatString(c *C) {
c.Assert(result, Equals, cas.out)
}
}

func printRows(t *TableDef) {
if t == nil {
fmt.Println("table is nil")
return
}

fmt.Println(strings.Join(t.Category, " - "))
fmt.Println(t.Title)
fmt.Println(t.Comment)
if len(t.Rows) == 0 {
fmt.Println("table rows is 0")
return
}

fieldLen := t.ColumnWidth()
// fmt.Println(fieldLen)
printLine := func(values []string, comment string) {
line := ""
for i, s := range values {
for k := len(s); k < fieldLen[i]; k++ {
s += " "
}
if i > 0 {
line += " | "
}
line += s
}
if len(comment) != 0 {
line = line + " | " + comment
}
fmt.Println(line)
}

printLine(t.Column, "")

for _, row := range t.Rows {
printLine(row.Values, row.Comment)
for i := range row.SubValues {
printLine(row.SubValues[i], "")
}
}
fmt.Println("")
}
38 changes: 25 additions & 13 deletions pkg/apiserver/slowquery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ package slowquery
import (
"strings"

"github.com/thoas/go-funk"
"gorm.io/gorm"

"github.com/pingcap/tidb-dashboard/pkg/utils"
)

const (
slowQueryTable = "INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY"
SlowQueryTable = "INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY"
)

type GetListRequest struct {
Expand All @@ -35,26 +38,29 @@ type GetDetailRequest struct {
ConnectID string `json:"connect_id" form:"connect_id"`
}

func (s *Service) querySlowLogList(db *gorm.DB, req *GetListRequest) ([]Model, error) {
tableColumns, err := s.params.SysSchema.GetTableColumnNames(db, slowQueryTable)
func QuerySlowLogList(req *GetListRequest, sysSchema *utils.SysSchema, db *gorm.DB) ([]Model, error) {
slowQueryColumns, err := sysSchema.GetTableColumnNames(db, SlowQueryTable)
if err != nil {
return nil, err
}

reqFields := strings.Split(req.Fields, ",")
selectStmt, err := s.genSelectStmt(tableColumns, reqFields)
selectStmt, err := genSelectStmt(slowQueryColumns, reqFields)
if err != nil {
return nil, err
}

tx := db.
Table(slowQueryTable).
Select(selectStmt).
Where("Time BETWEEN FROM_UNIXTIME(?) AND FROM_UNIXTIME(?)", req.BeginTime, req.EndTime)
Select(selectStmt)

if req.BeginTime != 0 && req.EndTime != 0 {
tx = tx.Where("Time BETWEEN FROM_UNIXTIME(?) AND FROM_UNIXTIME(?)", req.BeginTime, req.EndTime)
}

if req.Limit > 0 {
tx = tx.Limit(req.Limit)
if req.Limit <= 0 {
req.Limit = 100
}
tx = tx.Limit(req.Limit)

if req.Text != "" {
lowerStr := strings.ToLower(req.Text)
Expand All @@ -78,8 +84,7 @@ func (s *Service) querySlowLogList(db *gorm.DB, req *GetListRequest) ([]Model, e
if req.OrderBy == "" {
req.OrderBy = "timestamp"
}

orderStmt, err := s.genOrderStmt(tableColumns, req.OrderBy, req.IsDesc)
orderStmt, err := genOrderStmt(slowQueryColumns, req.OrderBy, req.IsDesc)
if err != nil {
return nil, err
}
Expand All @@ -102,10 +107,9 @@ func (s *Service) querySlowLogList(db *gorm.DB, req *GetListRequest) ([]Model, e
return results, nil
}

func (s *Service) querySlowLogDetail(db *gorm.DB, req *GetDetailRequest) (*Model, error) {
func QuerySlowLogDetail(req *GetDetailRequest, db *gorm.DB) (*Model, error) {
var result Model
err := db.
Table(slowQueryTable).
Select("*, (UNIX_TIMESTAMP(Time) + 0E0) AS timestamp").
Where("Digest = ?", req.Digest).
Where("Time = FROM_UNIXTIME(?)", req.Timestamp).
Expand All @@ -116,3 +120,11 @@ func (s *Service) querySlowLogDetail(db *gorm.DB, req *GetDetailRequest) (*Model
}
return &result, nil
}

func QueryTableColumns(sysSchema *utils.SysSchema, db *gorm.DB) ([]string, error) {
cs, err := sysSchema.GetTableColumnNames(db, SlowQueryTable)
if err != nil {
return nil, err
}
return funk.UniqString(append(cs, getVirtualFields()...)), nil
}
Loading