Skip to content

Commit

Permalink
use more suitable method
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepymole committed Nov 23, 2021
1 parent 79d0062 commit db816c7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
1 change: 1 addition & 0 deletions br/pkg/utils/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestParseKey(t *testing.T) {

for _, tt := range testNotSupportKey {
_, err := ParseKey("notSupport", tt.any)
require.Error(t, err)
require.Regexp(t, "unknown format.*", err.Error())
}
}
Expand Down
14 changes: 7 additions & 7 deletions br/pkg/utils/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func TestProgress(t *testing.T) {
progress2.Inc()
time.Sleep(2 * time.Second)
p = <-pCh2
require.Regexp(t, `.*"P":"50\.00%".*`, p)
require.Contains(t, p, `"P":"50.00%"`)
progress2.Inc()
time.Sleep(2 * time.Second)
p = <-pCh2
require.Regexp(t, `.*"P":"100\.00%".*`, p)
require.Contains(t, p, `"P":"100.00%"`)
progress2.Inc()
time.Sleep(2 * time.Second)
p = <-pCh2
require.Regexp(t, `.*"P":"100\.00%".*`, p)
require.Contains(t, p, `"P":"100.00%"`)
progress2.Close()

pCh4 := make(chan string, 4)
Expand All @@ -52,12 +52,12 @@ func TestProgress(t *testing.T) {
progress4.Inc()
time.Sleep(2 * time.Second)
p = <-pCh4
require.Regexp(t, `.*"P":"25\.00%".*`, p)
require.Contains(t, p, `"P":"25.00%"`)
progress4.Inc()
progress4.Close()
time.Sleep(2 * time.Second)
p = <-pCh4
require.Regexp(t, `.*"P":"100\.00%".*`, p)
require.Contains(t, p, `"P":"100.00%"`)

pCh8 := make(chan string, 8)
progress8 := NewProgressPrinter("test", 8, false)
Expand All @@ -68,11 +68,11 @@ func TestProgress(t *testing.T) {
progress8.Inc()
time.Sleep(2 * time.Second)
p = <-pCh8
require.Regexp(t, `.*"P":"25\.00%".*`, p)
require.Contains(t, p, `"P":"25.00%"`)

// Cancel should stop progress at the current position.
cancel()
p = <-pCh8
require.Regexp(t, `.*"P":"25\.00%".*`, p)
require.Contains(t, p, `"P":"25.00%"`)
progress8.Close()
}
9 changes: 5 additions & 4 deletions br/pkg/utils/safe_point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ func TestCheckGCSafepoint(t *testing.T) {
}
{
err := utils.CheckGCSafePoint(ctx, pdClient, 2333)
require.NotNil(t, err)
require.Error(t, err)
}
{
err := utils.CheckGCSafePoint(ctx, pdClient, 2333-1)
require.NotNil(t, err)
require.Error(t, err)
}
{
err := utils.CheckGCSafePoint(ctx, pdClient, 0)
require.Regexp(t, ".*GC safepoint 2333 exceed TS 0.*", err)
require.Error(t, err)
require.Regexp(t, ".*GC safepoint 2333 exceed TS 0.*", err.Error())
}
}

Expand Down Expand Up @@ -125,7 +126,7 @@ func TestStartServiceSafePointKeeper(t *testing.T) {
if cs.ok {
require.NoErrorf(t, err, "case #%d, %v", i, cs)
} else {
require.NotNilf(t, err, "case #%d, %v", i, cs)
require.Errorf(t, err, "case #%d, %v", i, cs)
}
cancel()
}
Expand Down
16 changes: 8 additions & 8 deletions br/pkg/utils/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestLoadBackupMeta(t *testing.T) {
)
tbl := dbs[dbName.String()].GetTable(tblName.String())
require.NoError(t, err)
require.Equal(t, 1, len(tbl.Files))
require.Len(t, tbl.Files, 1)
require.Equal(t, "1.sst", tbl.Files[0].Name)
}

Expand Down Expand Up @@ -210,7 +210,7 @@ func TestLoadBackupMetaPartionTable(t *testing.T) {
)
tbl := dbs[dbName.String()].GetTable(tblName.String())
require.NoError(t, err)
require.Equal(t, 3, len(tbl.Files))
require.Len(t, tbl.Files, 3)
contains := func(name string) bool {
for i := range tbl.Files {
if tbl.Files[i].Name == name {
Expand Down Expand Up @@ -294,9 +294,9 @@ func BenchmarkLoadBackupMeta64(b *testing.B) {
),
)
require.NoError(b, err)
require.Equal(b, 1, len(dbs))
require.Len(b, dbs, 1)
require.Contains(b, dbs, "bench")
require.Equal(b, 64, len(dbs["bench"].Tables))
require.Len(b, dbs["bench"].Tables, 64)
}
}

Expand Down Expand Up @@ -325,9 +325,9 @@ func BenchmarkLoadBackupMeta1024(b *testing.B) {
),
)
require.NoError(b, err)
require.Equal(b, 1, len(dbs))
require.Len(b, dbs, 1)
require.Contains(b, dbs, "bench")
require.Equal(b, 1024, len(dbs["bench"].Tables))
require.Len(b, dbs["bench"].Tables, 1024)
}
}

Expand Down Expand Up @@ -356,8 +356,8 @@ func BenchmarkLoadBackupMeta10240(b *testing.B) {
),
)
require.NoError(b, err)
require.Equal(b, 1, len(dbs))
require.Len(b, dbs, 1)
require.Contains(b, dbs, "bench")
require.Equal(b, 10240, len(dbs["bench"].Tables))
require.Len(b, dbs["bench"].Tables, 10240)
}
}

0 comments on commit db816c7

Please sign in to comment.