Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
  • Loading branch information
Leavrth committed Sep 12, 2024
1 parent c82be88 commit fedd8e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pkg/executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,22 +858,22 @@ func TestInfoSchemaDDLJobs(t *testing.T) {
tk2 := testkit.NewTestKit(t, store)
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE table_name = "t1";`).Check(testkit.RowsWithSep("|",
"125|add index /* txn-merge */|public|118|123|t1|synced",
"124|create table|public|118|123|t1|synced",
"111|add index /* txn-merge */|public|104|109|t1|synced",
"110|create table|public|104|109|t1|synced",
"127|add index /* txn-merge */|public|120|125|t1|synced",
"126|create table|public|120|125|t1|synced",
"113|add index /* txn-merge */|public|106|111|t1|synced",
"112|create table|public|106|111|t1|synced",
))
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE db_name = "d1" and JOB_TYPE LIKE "add index%%";`).Check(testkit.RowsWithSep("|",
"131|add index /* txn-merge */|public|118|129|t3|synced",
"128|add index /* txn-merge */|public|118|126|t2|synced",
"125|add index /* txn-merge */|public|118|123|t1|synced",
"122|add index /* txn-merge */|public|118|120|t0|synced",
"133|add index /* txn-merge */|public|120|131|t3|synced",
"130|add index /* txn-merge */|public|120|128|t2|synced",
"127|add index /* txn-merge */|public|120|125|t1|synced",
"124|add index /* txn-merge */|public|120|122|t0|synced",
))
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE db_name = "d0" and table_name = "t3";`).Check(testkit.RowsWithSep("|",
"117|add index /* txn-merge */|public|104|115|t3|synced",
"116|create table|public|104|115|t3|synced",
"119|add index /* txn-merge */|public|106|117|t3|synced",
"118|create table|public|106|117|t3|synced",
))
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE state = "running";`).Check(testkit.Rows())
Expand All @@ -884,15 +884,15 @@ func TestInfoSchemaDDLJobs(t *testing.T) {
if job.SchemaState == model.StateWriteOnly && loaded.CompareAndSwap(false, true) {
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE table_name = "t0" and state = "running";`).Check(testkit.RowsWithSep("|",
"132|add index /* txn-merge */|write only|104|106|t0|running",
"134|add index /* txn-merge */|write only|106|108|t0|running",
))
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE db_name = "d0" and state = "running";`).Check(testkit.RowsWithSep("|",
"132|add index /* txn-merge */|write only|104|106|t0|running",
"134|add index /* txn-merge */|write only|106|108|t0|running",
))
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE state = "running";`).Check(testkit.RowsWithSep("|",
"132|add index /* txn-merge */|write only|104|106|t0|running",
"134|add index /* txn-merge */|write only|106|108|t0|running",
))
}
})
Expand All @@ -908,8 +908,8 @@ func TestInfoSchemaDDLJobs(t *testing.T) {
tk.MustExec("create table test2.t1(id int)")
tk.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE db_name = "test2" and table_name = "t1"`).Check(testkit.RowsWithSep("|",
"141|create table|public|138|140|t1|synced",
"136|create table|public|133|135|t1|synced",
"143|create table|public|140|142|t1|synced",
"138|create table|public|135|137|t1|synced",
))

// Test explain output, since the output may change in future.
Expand Down
10 changes: 10 additions & 0 deletions pkg/statistics/handle/storage/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
package storage_test

import (
"cmp"
"context"
"encoding/json"
"errors"
"fmt"
"math"
"runtime"
"slices"
"strings"
"testing"

Expand Down Expand Up @@ -600,6 +602,10 @@ func TestJSONTableToBlocks(t *testing.T) {

dumpJSONTable, err := h.DumpStatsToJSON("test", tableInfo.Meta(), nil, true)
require.NoError(t, err)
// the slice is generated from a map loop, which is randomly
slices.SortFunc(dumpJSONTable.PredicateColumns, func(a, b *handleutil.JSONPredicateColumn) int {
return cmp.Compare(a.ID, b.ID)
})
jsOrigin, _ := json.Marshal(dumpJSONTable)

blockSize := 30
Expand All @@ -608,6 +614,10 @@ func TestJSONTableToBlocks(t *testing.T) {
dumpJSONBlocks, err := storage.JSONTableToBlocks(js, blockSize)
require.NoError(t, err)
jsConverted, err := storage.BlocksToJSONTable(dumpJSONBlocks)
// the slice is generated from a map loop, which is randomly
slices.SortFunc(jsConverted.PredicateColumns, func(a, b *handleutil.JSONPredicateColumn) int {
return cmp.Compare(a.ID, b.ID)
})
require.NoError(t, err)
jsonStr, err := json.Marshal(jsConverted)
require.NoError(t, err)
Expand Down

0 comments on commit fedd8e4

Please sign in to comment.