Skip to content

Commit

Permalink
test: correct TestAllHistory (pingcap#37656)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta authored Sep 7, 2022
1 parent 47f44ca commit c48a5ec
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion server/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ func (ts *basicHTTPHandlerTestSuite) prepareData(t *testing.T) {
err = txn1.Commit()
require.NoError(t, err)
dbt.MustExec("alter table tidb.test add index idx1 (a, b);")
dbt.MustExec("alter table tidb.test drop index idx1;")
dbt.MustExec("alter table tidb.test add index idx1 (a, b);")
dbt.MustExec("alter table tidb.test add unique index idx2 (a, b);")

dbt.MustExec(`create table tidb.pt (a int primary key, b varchar(20), key idx(a, b))
Expand Down Expand Up @@ -976,7 +978,14 @@ func TestAllHistory(t *testing.T) {

require.NoError(t, err)
require.NoError(t, resp.Body.Close())
require.Equal(t, data, jobs)
require.Equal(t, len(data), len(jobs))
for i := range data {
// For the jobs that have arguments(job.Args) for GC delete range,
// the RawArgs should be the same after filtering the spaces.
data[i].RawArgs = filterSpaces(data[i].RawArgs)
jobs[i].RawArgs = filterSpaces(jobs[i].RawArgs)
require.Equal(t, data[i], jobs[i], i)
}

// Cover the start_job_id parameter.
resp, err = ts.fetchStatus("/ddl/history?start_job_id=41")
Expand All @@ -998,6 +1007,22 @@ func TestAllHistory(t *testing.T) {
require.NoError(t, resp.Body.Close())
}

func filterSpaces(bs []byte) []byte {
if len(bs) == 0 {
return nil
}
tmp := bs[:0]
for _, b := range bs {
// 0xa is the line feed character.
// 0xd is the carriage return character.
// 0x20 is the space character.
if b != 0xa && b != 0xd && b != 0x20 {
tmp = append(tmp, b)
}
}
return tmp
}

func dummyRecord() *deadlockhistory.DeadlockRecord {
return &deadlockhistory.DeadlockRecord{}
}
Expand Down

0 comments on commit c48a5ec

Please sign in to comment.