Skip to content

Commit

Permalink
pkg: parallelize the pkg tests (tikv#5094)
Browse files Browse the repository at this point in the history
ref tikv#5087

Parallelize the `pkg` tests as much as possible.

Signed-off-by: JmPotato <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
2 people authored and CabinfeverB committed Jul 14, 2022
1 parent 0aa2c18 commit 219fa0e
Show file tree
Hide file tree
Showing 38 changed files with 108 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/apiutil/apiutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

func TestJsonRespondErrorOk(t *testing.T) {
t.Parallel()
re := require.New(t)
rd := render.New(render.Options{
IndentJSON: true,
Expand All @@ -43,6 +44,7 @@ func TestJsonRespondErrorOk(t *testing.T) {
}

func TestJsonRespondErrorBadInput(t *testing.T) {
t.Parallel()
re := require.New(t)
rd := render.New(render.Options{
IndentJSON: true,
Expand Down
1 change: 1 addition & 0 deletions pkg/assertutil/assertutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

func TestNilFail(t *testing.T) {
t.Parallel()
re := require.New(t)
var failErr error
checker := NewChecker(func() {
Expand Down
3 changes: 3 additions & 0 deletions pkg/audit/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
)

func TestLabelMatcher(t *testing.T) {
t.Parallel()
re := require.New(t)
matcher := &LabelMatcher{"testSuccess"}
labels1 := &BackendLabels{Labels: []string{"testFail", "testSuccess"}}
Expand All @@ -41,6 +42,7 @@ func TestLabelMatcher(t *testing.T) {
}

func TestPrometheusHistogramBackend(t *testing.T) {
t.Parallel()
re := require.New(t)
serviceAuditHistogramTest := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Expand Down Expand Up @@ -87,6 +89,7 @@ func TestPrometheusHistogramBackend(t *testing.T) {
}

func TestLocalLogBackendUsingFile(t *testing.T) {
t.Parallel()
re := require.New(t)
backend := NewLocalLogBackend(true)
fname := initLog()
Expand Down
5 changes: 5 additions & 0 deletions pkg/autoscaling/calculation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
)

func TestGetScaledTiKVGroups(t *testing.T) {
t.Parallel()
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -213,6 +214,7 @@ func (q *mockQuerier) Query(options *QueryOptions) (QueryResult, error) {
}

func TestGetTotalCPUUseTime(t *testing.T) {
t.Parallel()
re := require.New(t)
querier := &mockQuerier{}
instances := []instance{
Expand All @@ -235,6 +237,7 @@ func TestGetTotalCPUUseTime(t *testing.T) {
}

func TestGetTotalCPUQuota(t *testing.T) {
t.Parallel()
re := require.New(t)
querier := &mockQuerier{}
instances := []instance{
Expand All @@ -257,6 +260,7 @@ func TestGetTotalCPUQuota(t *testing.T) {
}

func TestScaleOutGroupLabel(t *testing.T) {
t.Parallel()
re := require.New(t)
var jsonStr = []byte(`
{
Expand Down Expand Up @@ -299,6 +303,7 @@ func TestScaleOutGroupLabel(t *testing.T) {
}

func TestStrategyChangeCount(t *testing.T) {
t.Parallel()
re := require.New(t)
var count uint64 = 2
strategy := &Strategy{
Expand Down
6 changes: 6 additions & 0 deletions pkg/autoscaling/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (c *normalClient) Do(_ context.Context, req *http.Request) (response *http.
}

func TestRetrieveCPUMetrics(t *testing.T) {
t.Parallel()
re := require.New(t)
client := &normalClient{
mockData: make(map[string]*response),
Expand Down Expand Up @@ -225,6 +226,7 @@ func (c *emptyResponseClient) Do(_ context.Context, req *http.Request) (r *http.
}

func TestEmptyResponse(t *testing.T) {
t.Parallel()
re := require.New(t)
client := &emptyResponseClient{}
querier := NewPrometheusQuerier(client)
Expand Down Expand Up @@ -252,6 +254,7 @@ func (c *errorHTTPStatusClient) Do(_ context.Context, req *http.Request) (r *htt
}

func TestErrorHTTPStatus(t *testing.T) {
t.Parallel()
re := require.New(t)
client := &errorHTTPStatusClient{}
querier := NewPrometheusQuerier(client)
Expand All @@ -277,6 +280,7 @@ func (c *errorPrometheusStatusClient) Do(_ context.Context, req *http.Request) (
}

func TestErrorPrometheusStatus(t *testing.T) {
t.Parallel()
re := require.New(t)
client := &errorPrometheusStatusClient{}
querier := NewPrometheusQuerier(client)
Expand All @@ -287,6 +291,7 @@ func TestErrorPrometheusStatus(t *testing.T) {
}

func TestGetInstanceNameFromAddress(t *testing.T) {
t.Parallel()
re := require.New(t)
testCases := []struct {
address string
Expand Down Expand Up @@ -324,6 +329,7 @@ func TestGetInstanceNameFromAddress(t *testing.T) {
}

func TestGetDurationExpression(t *testing.T) {
t.Parallel()
re := require.New(t)
testCases := []struct {
duration time.Duration
Expand Down
5 changes: 5 additions & 0 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

func TestExpireRegionCache(t *testing.T) {
t.Parallel()
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -115,6 +116,7 @@ func sortIDs(ids []uint64) []uint64 {
}

func TestLRUCache(t *testing.T) {
t.Parallel()
re := require.New(t)
cache := newLRU(3)

Expand Down Expand Up @@ -192,6 +194,7 @@ func TestLRUCache(t *testing.T) {
}

func TestFifoCache(t *testing.T) {
t.Parallel()
re := require.New(t)
cache := NewFIFO(3)
cache.Put(1, "1")
Expand Down Expand Up @@ -219,6 +222,7 @@ func TestFifoCache(t *testing.T) {
}

func TestTwoQueueCache(t *testing.T) {
t.Parallel()
re := require.New(t)
cache := newTwoQueue(3)
cache.Put(1, "1")
Expand Down Expand Up @@ -303,6 +307,7 @@ func (pq PriorityQueueItemTest) ID() uint64 {
}

func TestPriorityQueue(t *testing.T) {
t.Parallel()
re := require.New(t)
testData := []PriorityQueueItemTest{0, 1, 2, 3, 4, 5}
pq := NewPriorityQueue(0)
Expand Down
2 changes: 2 additions & 0 deletions pkg/codec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
)

func TestDecodeBytes(t *testing.T) {
t.Parallel()
re := require.New(t)
key := "abcdefghijklmnopqrstuvwxyz"
for i := 0; i < len(key); i++ {
Expand All @@ -31,6 +32,7 @@ func TestDecodeBytes(t *testing.T) {
}

func TestTableID(t *testing.T) {
t.Parallel()
re := require.New(t)
key := EncodeBytes([]byte("t\x80\x00\x00\x00\x00\x00\x00\xff"))
re.Equal(int64(0xff), key.TableID())
Expand Down
4 changes: 4 additions & 0 deletions pkg/encryption/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

func TestAdjustDefaultValue(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &Config{}
err := config.Adjust()
Expand All @@ -34,18 +35,21 @@ func TestAdjustDefaultValue(t *testing.T) {
}

func TestAdjustInvalidDataEncryptionMethod(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &Config{DataEncryptionMethod: "unknown"}
re.NotNil(config.Adjust())
}

func TestAdjustNegativeRotationDuration(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &Config{DataKeyRotationPeriod: typeutil.NewDuration(time.Duration(int64(-1)))}
re.NotNil(config.Adjust())
}

func TestAdjustInvalidMasterKeyType(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &Config{MasterKey: MasterKeyConfig{Type: "unknown"}}
re.NotNil(config.Adjust())
Expand Down
5 changes: 5 additions & 0 deletions pkg/encryption/crypter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

func TestEncryptionMethodSupported(t *testing.T) {
t.Parallel()
re := require.New(t)
re.NotNil(CheckEncryptionMethodSupported(encryptionpb.EncryptionMethod_PLAINTEXT))
re.NotNil(CheckEncryptionMethodSupported(encryptionpb.EncryptionMethod_UNKNOWN))
Expand All @@ -33,6 +34,7 @@ func TestEncryptionMethodSupported(t *testing.T) {
}

func TestKeyLength(t *testing.T) {
t.Parallel()
re := require.New(t)
_, err := KeyLength(encryptionpb.EncryptionMethod_PLAINTEXT)
re.NotNil(err)
Expand All @@ -50,6 +52,7 @@ func TestKeyLength(t *testing.T) {
}

func TestNewIv(t *testing.T) {
t.Parallel()
re := require.New(t)
ivCtr, err := NewIvCTR()
re.NoError(err)
Expand All @@ -60,6 +63,7 @@ func TestNewIv(t *testing.T) {
}

func TestNewDataKey(t *testing.T) {
t.Parallel()
re := require.New(t)
for _, method := range []encryptionpb.EncryptionMethod{
encryptionpb.EncryptionMethod_AES128_CTR,
Expand All @@ -78,6 +82,7 @@ func TestNewDataKey(t *testing.T) {
}

func TestAesGcmCrypter(t *testing.T) {
t.Parallel()
re := require.New(t)
key, err := hex.DecodeString("ed568fbd8c8018ed2d042a4e5d38d6341486922d401d2022fb81e47c900d3f07")
re.NoError(err)
Expand Down
8 changes: 8 additions & 0 deletions pkg/encryption/master_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

func TestPlaintextMasterKey(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &encryptionpb.MasterKey{
Backend: &encryptionpb.MasterKey_Plaintext{
Expand All @@ -49,6 +50,7 @@ func TestPlaintextMasterKey(t *testing.T) {
}

func TestEncrypt(t *testing.T) {
t.Parallel()
re := require.New(t)
keyHex := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806"
key, err := hex.DecodeString(keyHex)
Expand All @@ -64,6 +66,7 @@ func TestEncrypt(t *testing.T) {
}

func TestDecrypt(t *testing.T) {
t.Parallel()
re := require.New(t)
keyHex := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806"
key, err := hex.DecodeString(keyHex)
Expand All @@ -80,6 +83,7 @@ func TestDecrypt(t *testing.T) {
}

func TestNewFileMasterKeyMissingPath(t *testing.T) {
t.Parallel()
re := require.New(t)
config := &encryptionpb.MasterKey{
Backend: &encryptionpb.MasterKey_File{
Expand All @@ -93,6 +97,7 @@ func TestNewFileMasterKeyMissingPath(t *testing.T) {
}

func TestNewFileMasterKeyMissingFile(t *testing.T) {
t.Parallel()
re := require.New(t)
dir, err := os.MkdirTemp("", "test_key_files")
re.NoError(err)
Expand All @@ -109,6 +114,7 @@ func TestNewFileMasterKeyMissingFile(t *testing.T) {
}

func TestNewFileMasterKeyNotHexString(t *testing.T) {
t.Parallel()
re := require.New(t)
dir, err := os.MkdirTemp("", "test_key_files")
re.NoError(err)
Expand All @@ -126,6 +132,7 @@ func TestNewFileMasterKeyNotHexString(t *testing.T) {
}

func TestNewFileMasterKeyLengthMismatch(t *testing.T) {
t.Parallel()
re := require.New(t)
dir, err := os.MkdirTemp("", "test_key_files")
re.NoError(err)
Expand All @@ -143,6 +150,7 @@ func TestNewFileMasterKeyLengthMismatch(t *testing.T) {
}

func TestNewFileMasterKey(t *testing.T) {
t.Parallel()
re := require.New(t)
key := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806"
dir, err := os.MkdirTemp("", "test_key_files")
Expand Down
8 changes: 8 additions & 0 deletions pkg/encryption/region_crypter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (m *testKeyManager) GetKey(keyID uint64) (*encryptionpb.DataKey, error) {
}

func TestNilRegion(t *testing.T) {
t.Parallel()
re := require.New(t)
m := newTestKeyManager()
region, err := EncryptRegion(nil, m)
Expand All @@ -80,6 +81,7 @@ func TestNilRegion(t *testing.T) {
}

func TestEncryptRegionWithoutKeyManager(t *testing.T) {
t.Parallel()
re := require.New(t)
region := &metapb.Region{
Id: 10,
Expand All @@ -96,6 +98,7 @@ func TestEncryptRegionWithoutKeyManager(t *testing.T) {
}

func TestEncryptRegionWhileEncryptionDisabled(t *testing.T) {
t.Parallel()
re := require.New(t)
region := &metapb.Region{
Id: 10,
Expand All @@ -114,6 +117,7 @@ func TestEncryptRegionWhileEncryptionDisabled(t *testing.T) {
}

func TestEncryptRegion(t *testing.T) {
t.Parallel()
re := require.New(t)
startKey := []byte("abc")
endKey := []byte("xyz")
Expand Down Expand Up @@ -148,6 +152,7 @@ func TestEncryptRegion(t *testing.T) {
}

func TestDecryptRegionNotEncrypted(t *testing.T) {
t.Parallel()
re := require.New(t)
region := &metapb.Region{
Id: 10,
Expand All @@ -165,6 +170,7 @@ func TestDecryptRegionNotEncrypted(t *testing.T) {
}

func TestDecryptRegionWithoutKeyManager(t *testing.T) {
t.Parallel()
re := require.New(t)
region := &metapb.Region{
Id: 10,
Expand All @@ -180,6 +186,7 @@ func TestDecryptRegionWithoutKeyManager(t *testing.T) {
}

func TestDecryptRegionWhileKeyMissing(t *testing.T) {
t.Parallel()
re := require.New(t)
keyID := uint64(3)
m := newTestKeyManager()
Expand All @@ -200,6 +207,7 @@ func TestDecryptRegionWhileKeyMissing(t *testing.T) {
}

func TestDecryptRegion(t *testing.T) {
t.Parallel()
re := require.New(t)
keyID := uint64(1)
startKey := []byte("abc")
Expand Down
Loading

0 comments on commit 219fa0e

Please sign in to comment.