From e0be2d0f5892d994862af2e52ebb72b32c9c052e Mon Sep 17 00:00:00 2001 From: kevindiu Date: Fri, 25 Nov 2022 10:23:03 +0900 Subject: [PATCH 1/3] fix deepsource Signed-off-by: kevindiu --- internal/info/info.go | 2 +- internal/info/info_test.go | 1 + internal/net/grpc/pool/pool.go | 1 + internal/net/grpc/pool/pool_test.go | 1 + internal/test/data/vector/gen.go | 16 ++++++++-------- internal/test/data/vector/gen_test.go | 8 ++++---- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/internal/info/info.go b/internal/info/info.go index 246b284aa6..85fe31d5ec 100644 --- a/internal/info/info.go +++ b/internal/info/info.go @@ -265,7 +265,7 @@ func (i *info) Get() Detail { return i.get() } -// skipcq: VET-V0008 +// skipcq: VET-V0008, RVV-B0001 func (i info) get() Detail { i.detail.StackTrace = make([]StackTrace, 0, 10) for j := 2; ; j++ { diff --git a/internal/info/info_test.go b/internal/info/info_test.go index 3ddb25f78c..b84dd2d238 100644 --- a/internal/info/info_test.go +++ b/internal/info/info_test.go @@ -1567,6 +1567,7 @@ func TestStackTrace_String(t *testing.T) { } } +// skipcq: RVV-B0001 func Test_info_get(t *testing.T) { type fields struct { baseURL string diff --git a/internal/net/grpc/pool/pool.go b/internal/net/grpc/pool/pool.go index eaa15a5d02..ffe60600ce 100644 --- a/internal/net/grpc/pool/pool.go +++ b/internal/net/grpc/pool/pool.go @@ -360,6 +360,7 @@ func (p *pool) Get() (*ClientConn, bool) { return p.get(p.Len()) } +// skipcq: RVV-B0001 func (p *pool) get(retry uint64) (*ClientConn, bool) { if retry <= 0 || retry > math.MaxUint64-p.Len() || p.Len() <= 0 { log.Warnf("failed to find grpc pool connection for %s", p.addr) diff --git a/internal/net/grpc/pool/pool_test.go b/internal/net/grpc/pool/pool_test.go index 97287c1dbc..38ac768911 100644 --- a/internal/net/grpc/pool/pool_test.go +++ b/internal/net/grpc/pool/pool_test.go @@ -1284,6 +1284,7 @@ func Test_pool_Get(t *testing.T) { } } +// skipcq: RVV-B0001 func Test_pool_get(t *testing.T) { t.Parallel() type args struct { diff --git a/internal/test/data/vector/gen.go b/internal/test/data/vector/gen.go index 63dde69a31..1aaa7f89e1 100644 --- a/internal/test/data/vector/gen.go +++ b/internal/test/data/vector/gen.go @@ -63,8 +63,8 @@ func Uint8VectorGenerator(d Distribution) (Uint8VectorGeneratorFunc, error) { } } -// genFloat32Vec return n float32 vectors with dim dimension. -func genFloat32Vec(n, dim int, gen func() float32) (ret [][]float32) { +// doGenFloat32Vec return n float32 vectors with dim dimension. +func doGenFloat32Vec(n, dim int, gen func() float32) (ret [][]float32) { ret = make([][]float32, 0, n) for i := 0; i < n; i++ { @@ -79,18 +79,18 @@ func genFloat32Vec(n, dim int, gen func() float32) (ret [][]float32) { // UniformDistributedFloat32VectorGenerator returns n float32 vectors with dim dimension and their values under Uniform distribution func UniformDistributedFloat32VectorGenerator(n, dim int) [][]float32 { - return genFloat32Vec(n, dim, rand.Float32) + return doGenFloat32Vec(n, dim, rand.Float32) } // GaussianDistributedFloat32VectorGenerator returns n float32 vectors with dim dimension and their values under Gaussian distribution func GaussianDistributedFloat32VectorGenerator(n, dim int) [][]float32 { - return genFloat32Vec(n, dim, func() float32 { + return doGenFloat32Vec(n, dim, func() float32 { return float32(rand.NormFloat64()) }) } -// genUint8Vec return n uint8 vectors with dim dimension -func genUint8Vec(n, dim int, gen func() uint8) (ret [][]uint8) { +// doGenUint8Vec return n uint8 vectors with dim dimension +func doGenUint8Vec(n, dim int, gen func() uint8) (ret [][]uint8) { ret = make([][]uint8, 0, n) for i := 0; i < n; i++ { @@ -105,7 +105,7 @@ func genUint8Vec(n, dim int, gen func() uint8) (ret [][]uint8) { // UniformDistributedUint8VectorGenerator returns n uint8 vectors with dim dimension and their values under Uniform distribution func UniformDistributedUint8VectorGenerator(n, dim int) [][]uint8 { - return genUint8Vec(n, dim, func() uint8 { + return doGenUint8Vec(n, dim, func() uint8 { return uint8(irand.LimitedUint32(math.MaxUint8)) }) } @@ -113,7 +113,7 @@ func UniformDistributedUint8VectorGenerator(n, dim int) [][]uint8 { // GaussianDistributedUint8VectorGenerator returns n uint8 vectors with dim dimension and their values under Gaussian distribution func GaussianDistributedUint8VectorGenerator(n, dim int) [][]uint8 { // NOTE: The boundary test is the main purpose for refactoring. Now, passing this function is dependent on the seed of the random generator. We should fix the randomness of the passing test. - return genUint8Vec(n, dim, func() uint8 { + return doGenUint8Vec(n, dim, func() uint8 { val := rand.NormFloat64()*gaussianSigma + gaussianMean if val < 0 { return 0 diff --git a/internal/test/data/vector/gen_test.go b/internal/test/data/vector/gen_test.go index ce072b80b0..9f7a372bdc 100644 --- a/internal/test/data/vector/gen_test.go +++ b/internal/test/data/vector/gen_test.go @@ -208,7 +208,7 @@ func TestUint8VectorGenerator(t *testing.T) { } } -func Test_genFloat32Vec(t *testing.T) { +func Test_doGenFloat32Vec(t *testing.T) { type args struct { n int dim int @@ -279,7 +279,7 @@ func Test_genFloat32Vec(t *testing.T) { checkFunc = defaultCheckFunc } - gotRet := genFloat32Vec(test.args.n, test.args.dim, test.args.gen) + gotRet := doGenFloat32Vec(test.args.n, test.args.dim, test.args.gen) if err := checkFunc(test.want, gotRet); err != nil { tt.Errorf("error = %v", err) } @@ -439,7 +439,7 @@ func TestGaussianDistributedFloat32VectorGenerator(t *testing.T) { } } -func Test_genUint8Vec(t *testing.T) { +func Test_doGenUint8Vec(t *testing.T) { type args struct { n int dim int @@ -510,7 +510,7 @@ func Test_genUint8Vec(t *testing.T) { checkFunc = defaultCheckFunc } - gotRet := genUint8Vec(test.args.n, test.args.dim, test.args.gen) + gotRet := doGenUint8Vec(test.args.n, test.args.dim, test.args.gen) if err := checkFunc(test.want, gotRet); err != nil { tt.Errorf("error = %v", err) } From 92ebe7f7008391ac2892485edb25f932293f2216 Mon Sep 17 00:00:00 2001 From: kevindiu Date: Fri, 25 Nov 2022 10:28:46 +0900 Subject: [PATCH 2/3] rename info/get to info/getDetail Signed-off-by: kevindiu --- internal/info/info.go | 7 ++++--- internal/info/info_test.go | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/info/info.go b/internal/info/info.go index 85fe31d5ec..8d2fa6cfdd 100644 --- a/internal/info/info.go +++ b/internal/info/info.go @@ -1,4 +1,5 @@ // +// // Copyright (C) 2019-2022 vdaas.org vald team // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -262,11 +263,11 @@ func (d Detail) String() string { // Get returns parased Detail object. func (i *info) Get() Detail { i.prepare() - return i.get() + return i.getDetail() } -// skipcq: VET-V0008, RVV-B0001 -func (i info) get() Detail { +// skipcq: VET-V0008 +func (i info) getDetail() Detail { i.detail.StackTrace = make([]StackTrace, 0, 10) for j := 2; ; j++ { pc, file, line, ok := i.rtCaller(j) diff --git a/internal/info/info_test.go b/internal/info/info_test.go index b84dd2d238..24611be798 100644 --- a/internal/info/info_test.go +++ b/internal/info/info_test.go @@ -1567,8 +1567,7 @@ func TestStackTrace_String(t *testing.T) { } } -// skipcq: RVV-B0001 -func Test_info_get(t *testing.T) { +func Test_info_getDetail(t *testing.T) { type fields struct { baseURL string detail Detail @@ -1650,7 +1649,7 @@ func Test_info_get(t *testing.T) { rtFuncForPC: test.fields.rtFuncForPC, } - got := i.get() + got := i.getDetail() if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } From a4435e1923b27a1ae23aad0f41718c9ddd136a0e Mon Sep 17 00:00:00 2001 From: kevindiu Date: Fri, 25 Nov 2022 12:28:08 +0900 Subject: [PATCH 3/3] rename pool/get to pool/doGet Signed-off-by: kevindiu --- internal/net/grpc/pool/pool.go | 7 +++---- internal/net/grpc/pool/pool_test.go | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/net/grpc/pool/pool.go b/internal/net/grpc/pool/pool.go index ffe60600ce..679a0ac588 100644 --- a/internal/net/grpc/pool/pool.go +++ b/internal/net/grpc/pool/pool.go @@ -357,11 +357,10 @@ func (p *pool) Do(f func(conn *ClientConn) error) error { } func (p *pool) Get() (*ClientConn, bool) { - return p.get(p.Len()) + return p.doGet(p.Len()) } -// skipcq: RVV-B0001 -func (p *pool) get(retry uint64) (*ClientConn, bool) { +func (p *pool) doGet(retry uint64) (*ClientConn, bool) { if retry <= 0 || retry > math.MaxUint64-p.Len() || p.Len() <= 0 { log.Warnf("failed to find grpc pool connection for %s", p.addr) if p.isIP { @@ -379,7 +378,7 @@ func (p *pool) get(retry uint64) (*ClientConn, bool) { } } retry-- - return p.get(retry) + return p.doGet(retry) } func (p *pool) Len() uint64 { diff --git a/internal/net/grpc/pool/pool_test.go b/internal/net/grpc/pool/pool_test.go index 38ac768911..fa91ab7408 100644 --- a/internal/net/grpc/pool/pool_test.go +++ b/internal/net/grpc/pool/pool_test.go @@ -1284,8 +1284,7 @@ func Test_pool_Get(t *testing.T) { } } -// skipcq: RVV-B0001 -func Test_pool_get(t *testing.T) { +func Test_pool_doGet(t *testing.T) { t.Parallel() type args struct { retry uint64 @@ -1427,7 +1426,7 @@ func Test_pool_get(t *testing.T) { reconnectHash: test.fields.reconnectHash, } - got, got1 := p.get(test.args.retry) + got, got1 := p.doGet(test.args.retry) if err := checkFunc(test.want, got, got1); err != nil { tt.Errorf("error = %v", err) }