diff --git a/pkg/discoverer/k8s/service/discover_test.go b/pkg/discoverer/k8s/service/discover_test.go index 27681ede49..6e3cfb8ad5 100644 --- a/pkg/discoverer/k8s/service/discover_test.go +++ b/pkg/discoverer/k8s/service/discover_test.go @@ -34,7 +34,6 @@ import ( ) func TestNew(t *testing.T) { - t.Parallel() type args struct { selector *config.Selectors opts []Option @@ -48,8 +47,8 @@ func TestNew(t *testing.T) { args args want want checkFunc func(want, Discoverer, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotDsc Discoverer, err error) error { if !errors.Is(err, w.err) { @@ -66,10 +65,17 @@ func TestNew(t *testing.T) { { name: "test_case_1", args: args { + selector: nil, opts: nil, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -79,10 +85,17 @@ func TestNew(t *testing.T) { return test { name: "test_case_2", args: args { + selector: nil, opts: nil, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -94,10 +107,10 @@ func TestNew(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -113,16 +126,31 @@ func TestNew(t *testing.T) { } func Test_discoverer_Start(t *testing.T) { - t.Parallel() type args struct { ctx context.Context } type fields struct { - maxPods int - nodes nodeMap - nodeMetrics nodeMetricsMap - pods podsMap - podMetrics podMetricsMap + maxPods int + nodes struct { + read atomic.Value + dirty map[string]*entryNodeMap + misses int + } + nodeMetrics struct { + read atomic.Value + dirty map[string]*entryNodeMetricsMap + misses int + } + pods struct { + read atomic.Value + dirty map[string]*entryPodsMap + misses int + } + podMetrics struct { + read atomic.Value + dirty map[string]*entryPodMetricsMap + misses int + } podsByNode atomic.Value podsByNamespace atomic.Value podsByName atomic.Value @@ -144,8 +172,8 @@ func Test_discoverer_Start(t *testing.T) { fields fields want want checkFunc func(want, <-chan error, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got <-chan error, err error) error { if !errors.Is(err, w.err) { @@ -166,10 +194,10 @@ func Test_discoverer_Start(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -183,6 +211,12 @@ func Test_discoverer_Start(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -196,10 +230,10 @@ func Test_discoverer_Start(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -213,6 +247,12 @@ func Test_discoverer_Start(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -224,21 +264,37 @@ func Test_discoverer_Start(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } d := &discoverer{ - maxPods: test.fields.maxPods, - nodes: test.fields.nodes, - nodeMetrics: test.fields.nodeMetrics, - pods: test.fields.pods, - podMetrics: test.fields.podMetrics, + maxPods: test.fields.maxPods, + nodes: nodeMap{ + read: test.fields.nodes.read, + dirty: test.fields.nodes.dirty, + misses: test.fields.nodes.misses, + }, + nodeMetrics: nodeMetricsMap{ + read: test.fields.nodeMetrics.read, + dirty: test.fields.nodeMetrics.dirty, + misses: test.fields.nodeMetrics.misses, + }, + pods: podsMap{ + read: test.fields.pods.read, + dirty: test.fields.pods.dirty, + misses: test.fields.pods.misses, + }, + podMetrics: podMetricsMap{ + read: test.fields.podMetrics.read, + dirty: test.fields.podMetrics.dirty, + misses: test.fields.podMetrics.misses, + }, podsByNode: test.fields.podsByNode, podsByNamespace: test.fields.podsByNamespace, podsByName: test.fields.podsByName, @@ -260,16 +316,31 @@ func Test_discoverer_Start(t *testing.T) { } func Test_discoverer_GetPods(t *testing.T) { - t.Parallel() type args struct { req *payload.Discoverer_Request } type fields struct { - maxPods int - nodes nodeMap - nodeMetrics nodeMetricsMap - pods podsMap - podMetrics podMetricsMap + maxPods int + nodes struct { + read atomic.Value + dirty map[string]*entryNodeMap + misses int + } + nodeMetrics struct { + read atomic.Value + dirty map[string]*entryNodeMetricsMap + misses int + } + pods struct { + read atomic.Value + dirty map[string]*entryPodsMap + misses int + } + podMetrics struct { + read atomic.Value + dirty map[string]*entryPodMetricsMap + misses int + } podsByNode atomic.Value podsByNamespace atomic.Value podsByName atomic.Value @@ -291,8 +362,8 @@ func Test_discoverer_GetPods(t *testing.T) { fields fields want want checkFunc func(want, *payload.Info_Pods, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotPods *payload.Info_Pods, err error) error { if !errors.Is(err, w.err) { @@ -313,10 +384,10 @@ func Test_discoverer_GetPods(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -330,6 +401,12 @@ func Test_discoverer_GetPods(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -343,10 +420,10 @@ func Test_discoverer_GetPods(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -360,6 +437,12 @@ func Test_discoverer_GetPods(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -371,21 +454,37 @@ func Test_discoverer_GetPods(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } d := &discoverer{ - maxPods: test.fields.maxPods, - nodes: test.fields.nodes, - nodeMetrics: test.fields.nodeMetrics, - pods: test.fields.pods, - podMetrics: test.fields.podMetrics, + maxPods: test.fields.maxPods, + nodes: nodeMap{ + read: test.fields.nodes.read, + dirty: test.fields.nodes.dirty, + misses: test.fields.nodes.misses, + }, + nodeMetrics: nodeMetricsMap{ + read: test.fields.nodeMetrics.read, + dirty: test.fields.nodeMetrics.dirty, + misses: test.fields.nodeMetrics.misses, + }, + pods: podsMap{ + read: test.fields.pods.read, + dirty: test.fields.pods.dirty, + misses: test.fields.pods.misses, + }, + podMetrics: podMetricsMap{ + read: test.fields.podMetrics.read, + dirty: test.fields.podMetrics.dirty, + misses: test.fields.podMetrics.misses, + }, podsByNode: test.fields.podsByNode, podsByNamespace: test.fields.podsByNamespace, podsByName: test.fields.podsByName, @@ -407,16 +506,31 @@ func Test_discoverer_GetPods(t *testing.T) { } func Test_discoverer_GetNodes(t *testing.T) { - t.Parallel() type args struct { req *payload.Discoverer_Request } type fields struct { - maxPods int - nodes nodeMap - nodeMetrics nodeMetricsMap - pods podsMap - podMetrics podMetricsMap + maxPods int + nodes struct { + read atomic.Value + dirty map[string]*entryNodeMap + misses int + } + nodeMetrics struct { + read atomic.Value + dirty map[string]*entryNodeMetricsMap + misses int + } + pods struct { + read atomic.Value + dirty map[string]*entryPodsMap + misses int + } + podMetrics struct { + read atomic.Value + dirty map[string]*entryPodMetricsMap + misses int + } podsByNode atomic.Value podsByNamespace atomic.Value podsByName atomic.Value @@ -438,8 +552,8 @@ func Test_discoverer_GetNodes(t *testing.T) { fields fields want want checkFunc func(want, *payload.Info_Nodes, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotNodes *payload.Info_Nodes, err error) error { if !errors.Is(err, w.err) { @@ -460,10 +574,10 @@ func Test_discoverer_GetNodes(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -477,6 +591,12 @@ func Test_discoverer_GetNodes(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -490,10 +610,10 @@ func Test_discoverer_GetNodes(t *testing.T) { }, fields: fields { maxPods: 0, - nodes: nodeMap{}, - nodeMetrics: nodeMetricsMap{}, - pods: podsMap{}, - podMetrics: podMetricsMap{}, + nodes: struct{}, + nodeMetrics: struct{}, + pods: struct{}, + podMetrics: struct{}, podsByNode: nil, podsByNamespace: nil, podsByName: nil, @@ -507,6 +627,12 @@ func Test_discoverer_GetNodes(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -518,21 +644,37 @@ func Test_discoverer_GetNodes(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } d := &discoverer{ - maxPods: test.fields.maxPods, - nodes: test.fields.nodes, - nodeMetrics: test.fields.nodeMetrics, - pods: test.fields.pods, - podMetrics: test.fields.podMetrics, + maxPods: test.fields.maxPods, + nodes: nodeMap{ + read: test.fields.nodes.read, + dirty: test.fields.nodes.dirty, + misses: test.fields.nodes.misses, + }, + nodeMetrics: nodeMetricsMap{ + read: test.fields.nodeMetrics.read, + dirty: test.fields.nodeMetrics.dirty, + misses: test.fields.nodeMetrics.misses, + }, + pods: podsMap{ + read: test.fields.pods.read, + dirty: test.fields.pods.dirty, + misses: test.fields.pods.misses, + }, + podMetrics: podMetricsMap{ + read: test.fields.podMetrics.read, + dirty: test.fields.podMetrics.dirty, + misses: test.fields.podMetrics.misses, + }, podsByNode: test.fields.podsByNode, podsByNamespace: test.fields.podsByNamespace, podsByName: test.fields.podsByName, diff --git a/pkg/discoverer/k8s/service/nodemap_test.go b/pkg/discoverer/k8s/service/nodemap_test.go index 5f77c38212..73065093f3 100644 --- a/pkg/discoverer/k8s/service/nodemap_test.go +++ b/pkg/discoverer/k8s/service/nodemap_test.go @@ -18,7 +18,6 @@ package service import ( "reflect" - "sync" "sync/atomic" "testing" "unsafe" @@ -29,7 +28,6 @@ import ( ) func Test_newEntryNodeMap(t *testing.T) { - t.Parallel() type args struct { i *node.Node } @@ -41,8 +39,8 @@ func Test_newEntryNodeMap(t *testing.T) { args args want want checkFunc func(want, *entryNodeMap) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got *entryNodeMap) error { if !reflect.DeepEqual(got, w.want) { @@ -60,6 +58,12 @@ func Test_newEntryNodeMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -73,6 +77,12 @@ func Test_newEntryNodeMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -84,10 +94,10 @@ func Test_newEntryNodeMap(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -103,12 +113,10 @@ func Test_newEntryNodeMap(t *testing.T) { } func Test_nodeMap_Load(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -123,8 +131,8 @@ func Test_nodeMap_Load(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotValue *node.Node, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -144,13 +152,18 @@ func Test_nodeMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -163,13 +176,18 @@ func Test_nodeMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -181,17 +199,16 @@ func Test_nodeMap_Load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -206,7 +223,6 @@ func Test_nodeMap_Load(t *testing.T) { } func Test_entryNodeMap_load(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -219,8 +235,8 @@ func Test_entryNodeMap_load(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotValue *node.Node, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -241,6 +257,12 @@ func Test_entryNodeMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -254,6 +276,12 @@ func Test_entryNodeMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -265,10 +293,10 @@ func Test_entryNodeMap_load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -287,13 +315,11 @@ func Test_entryNodeMap_load(t *testing.T) { } func Test_nodeMap_Store(t *testing.T) { - t.Parallel() type args struct { key string value *node.Node } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -305,8 +331,8 @@ func Test_nodeMap_Store(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -321,13 +347,18 @@ func Test_nodeMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -341,13 +372,18 @@ func Test_nodeMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -359,17 +395,16 @@ func Test_nodeMap_Store(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -384,7 +419,6 @@ func Test_nodeMap_Store(t *testing.T) { } func Test_entryNodeMap_tryStore(t *testing.T) { - t.Parallel() type args struct { i **node.Node } @@ -400,8 +434,8 @@ func Test_entryNodeMap_tryStore(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -422,6 +456,12 @@ func Test_entryNodeMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -438,6 +478,12 @@ func Test_entryNodeMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -449,10 +495,10 @@ func Test_entryNodeMap_tryStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -471,7 +517,6 @@ func Test_entryNodeMap_tryStore(t *testing.T) { } func Test_entryNodeMap_unexpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -483,8 +528,8 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotWasExpunged bool) error { if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { @@ -502,6 +547,12 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -515,6 +566,12 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -526,10 +583,10 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -548,7 +605,6 @@ func Test_entryNodeMap_unexpungeLocked(t *testing.T) { } func Test_entryNodeMap_storeLocked(t *testing.T) { - t.Parallel() type args struct { i **node.Node } @@ -562,8 +618,8 @@ func Test_entryNodeMap_storeLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -581,6 +637,12 @@ func Test_entryNodeMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -597,6 +659,12 @@ func Test_entryNodeMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -608,10 +676,10 @@ func Test_entryNodeMap_storeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -630,13 +698,11 @@ func Test_entryNodeMap_storeLocked(t *testing.T) { } func Test_nodeMap_LoadOrStore(t *testing.T) { - t.Parallel() type args struct { key string value *node.Node } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -651,8 +717,8 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual *node.Node, gotLoaded bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -673,13 +739,18 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -693,13 +764,18 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -711,17 +787,16 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -736,7 +811,6 @@ func Test_nodeMap_LoadOrStore(t *testing.T) { } func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { - t.Parallel() type args struct { i *node.Node } @@ -754,8 +828,8 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual *node.Node, gotLoaded bool, gotOk bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -782,6 +856,12 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -798,6 +878,12 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -809,10 +895,10 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -831,12 +917,10 @@ func Test_entryNodeMap_tryLoadOrStore(t *testing.T) { } func Test_nodeMap_LoadAndDelete(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -851,8 +935,8 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotValue *node.Node, gotLoaded bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -872,13 +956,18 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -891,13 +980,18 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -909,17 +1003,16 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -934,12 +1027,10 @@ func Test_nodeMap_LoadAndDelete(t *testing.T) { } func Test_nodeMap_Delete(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -951,8 +1042,8 @@ func Test_nodeMap_Delete(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -966,13 +1057,18 @@ func Test_nodeMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -985,13 +1081,18 @@ func Test_nodeMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1003,17 +1104,16 @@ func Test_nodeMap_Delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1028,7 +1128,6 @@ func Test_nodeMap_Delete(t *testing.T) { } func Test_entryNodeMap_delete(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -1041,8 +1140,8 @@ func Test_entryNodeMap_delete(t *testing.T) { fields fields want want checkFunc func(want, *node.Node, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotValue *node.Node, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -1063,6 +1162,12 @@ func Test_entryNodeMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1076,6 +1181,12 @@ func Test_entryNodeMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1087,10 +1198,10 @@ func Test_entryNodeMap_delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1109,12 +1220,10 @@ func Test_entryNodeMap_delete(t *testing.T) { } func Test_nodeMap_Range(t *testing.T) { - t.Parallel() type args struct { f func(key string, value *node.Node) bool } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -1126,8 +1235,8 @@ func Test_nodeMap_Range(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -1141,13 +1250,18 @@ func Test_nodeMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1160,13 +1274,18 @@ func Test_nodeMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1178,17 +1297,16 @@ func Test_nodeMap_Range(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1203,9 +1321,7 @@ func Test_nodeMap_Range(t *testing.T) { } func Test_nodeMap_missLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -1216,8 +1332,8 @@ func Test_nodeMap_missLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1228,13 +1344,18 @@ func Test_nodeMap_missLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1244,13 +1365,18 @@ func Test_nodeMap_missLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1262,17 +1388,16 @@ func Test_nodeMap_missLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1287,9 +1412,7 @@ func Test_nodeMap_missLocked(t *testing.T) { } func Test_nodeMap_dirtyLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMap misses int @@ -1300,8 +1423,8 @@ func Test_nodeMap_dirtyLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1312,13 +1435,18 @@ func Test_nodeMap_dirtyLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1328,13 +1456,18 @@ func Test_nodeMap_dirtyLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1346,17 +1479,16 @@ func Test_nodeMap_dirtyLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1371,7 +1503,6 @@ func Test_nodeMap_dirtyLocked(t *testing.T) { } func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -1383,8 +1514,8 @@ func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotIsExpunged bool) error { if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { @@ -1402,6 +1533,12 @@ func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1415,6 +1552,12 @@ func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1426,10 +1569,10 @@ func Test_entryNodeMap_tryExpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { diff --git a/pkg/discoverer/k8s/service/nodemetricsmap_test.go b/pkg/discoverer/k8s/service/nodemetricsmap_test.go index 846b41cd94..23e4427b9d 100644 --- a/pkg/discoverer/k8s/service/nodemetricsmap_test.go +++ b/pkg/discoverer/k8s/service/nodemetricsmap_test.go @@ -18,7 +18,6 @@ package service import ( "reflect" - "sync" "sync/atomic" "testing" "unsafe" @@ -29,7 +28,6 @@ import ( ) func Test_newEntryNodeMetricsMap(t *testing.T) { - t.Parallel() type args struct { i mnode.Node } @@ -41,8 +39,8 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { args args want want checkFunc func(want, *entryNodeMetricsMap) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got *entryNodeMetricsMap) error { if !reflect.DeepEqual(got, w.want) { @@ -60,6 +58,12 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -73,6 +77,12 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -84,10 +94,10 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -103,12 +113,10 @@ func Test_newEntryNodeMetricsMap(t *testing.T) { } func Test_nodeMetricsMap_Load(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int @@ -123,8 +131,8 @@ func Test_nodeMetricsMap_Load(t *testing.T) { fields fields want want checkFunc func(want, mnode.Node, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotValue mnode.Node, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -144,13 +152,18 @@ func Test_nodeMetricsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -163,13 +176,18 @@ func Test_nodeMetricsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -181,17 +199,16 @@ func Test_nodeMetricsMap_Load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -206,7 +223,6 @@ func Test_nodeMetricsMap_Load(t *testing.T) { } func Test_entryNodeMetricsMap_load(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -219,8 +235,8 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { fields fields want want checkFunc func(want, mnode.Node, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotValue mnode.Node, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -241,6 +257,12 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -254,6 +276,12 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -265,10 +293,10 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -287,13 +315,11 @@ func Test_entryNodeMetricsMap_load(t *testing.T) { } func Test_nodeMetricsMap_Store(t *testing.T) { - t.Parallel() type args struct { key string value mnode.Node } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int @@ -305,8 +331,8 @@ func Test_nodeMetricsMap_Store(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -321,13 +347,18 @@ func Test_nodeMetricsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -341,13 +372,18 @@ func Test_nodeMetricsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -359,17 +395,16 @@ func Test_nodeMetricsMap_Store(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -384,7 +419,6 @@ func Test_nodeMetricsMap_Store(t *testing.T) { } func Test_entryNodeMetricsMap_tryStore(t *testing.T) { - t.Parallel() type args struct { i *mnode.Node } @@ -400,8 +434,8 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -422,6 +456,12 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -438,6 +478,12 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -449,10 +495,10 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -471,7 +517,6 @@ func Test_entryNodeMetricsMap_tryStore(t *testing.T) { } func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -483,8 +528,8 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotWasExpunged bool) error { if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { @@ -502,6 +547,12 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -515,6 +566,12 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -526,10 +583,10 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -548,7 +605,6 @@ func Test_entryNodeMetricsMap_unexpungeLocked(t *testing.T) { } func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { - t.Parallel() type args struct { i *mnode.Node } @@ -562,8 +618,8 @@ func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -581,6 +637,12 @@ func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -597,6 +659,12 @@ func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -608,10 +676,10 @@ func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -630,13 +698,11 @@ func Test_entryNodeMetricsMap_storeLocked(t *testing.T) { } func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { - t.Parallel() type args struct { key string value mnode.Node } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int @@ -651,8 +717,8 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, mnode.Node, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual mnode.Node, gotLoaded bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -673,13 +739,18 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -693,13 +764,18 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -711,17 +787,16 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -736,7 +811,6 @@ func Test_nodeMetricsMap_LoadOrStore(t *testing.T) { } func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { - t.Parallel() type args struct { i mnode.Node } @@ -754,8 +828,8 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, mnode.Node, bool, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual mnode.Node, gotLoaded bool, gotOk bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -782,6 +856,12 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -798,6 +878,12 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -809,10 +895,10 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -831,12 +917,10 @@ func Test_entryNodeMetricsMap_tryLoadOrStore(t *testing.T) { } func Test_nodeMetricsMap_Delete(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int @@ -848,8 +932,8 @@ func Test_nodeMetricsMap_Delete(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -863,13 +947,18 @@ func Test_nodeMetricsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -882,13 +971,18 @@ func Test_nodeMetricsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -900,17 +994,16 @@ func Test_nodeMetricsMap_Delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -925,7 +1018,6 @@ func Test_nodeMetricsMap_Delete(t *testing.T) { } func Test_entryNodeMetricsMap_delete(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -937,8 +1029,8 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotHadValue bool) error { if !reflect.DeepEqual(gotHadValue, w.wantHadValue) { @@ -956,6 +1048,12 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -969,6 +1067,12 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -980,10 +1084,10 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1002,12 +1106,10 @@ func Test_entryNodeMetricsMap_delete(t *testing.T) { } func Test_nodeMetricsMap_Range(t *testing.T) { - t.Parallel() type args struct { f func(key string, value mnode.Node) bool } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int @@ -1019,8 +1121,8 @@ func Test_nodeMetricsMap_Range(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -1034,13 +1136,18 @@ func Test_nodeMetricsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1053,13 +1160,18 @@ func Test_nodeMetricsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1071,17 +1183,16 @@ func Test_nodeMetricsMap_Range(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1096,9 +1207,7 @@ func Test_nodeMetricsMap_Range(t *testing.T) { } func Test_nodeMetricsMap_missLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int @@ -1109,8 +1218,8 @@ func Test_nodeMetricsMap_missLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1121,13 +1230,18 @@ func Test_nodeMetricsMap_missLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1137,13 +1251,18 @@ func Test_nodeMetricsMap_missLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1155,17 +1274,16 @@ func Test_nodeMetricsMap_missLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1180,9 +1298,7 @@ func Test_nodeMetricsMap_missLocked(t *testing.T) { } func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryNodeMetricsMap misses int @@ -1193,8 +1309,8 @@ func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1205,13 +1321,18 @@ func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1221,13 +1342,18 @@ func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1239,17 +1365,16 @@ func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &nodeMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1264,7 +1389,6 @@ func Test_nodeMetricsMap_dirtyLocked(t *testing.T) { } func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -1276,8 +1400,8 @@ func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotIsExpunged bool) error { if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { @@ -1295,6 +1419,12 @@ func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1308,6 +1438,12 @@ func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1319,10 +1455,10 @@ func Test_entryNodeMetricsMap_tryExpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { diff --git a/pkg/discoverer/k8s/service/podmetricsmap_test.go b/pkg/discoverer/k8s/service/podmetricsmap_test.go index 7c6ca96d43..3b3c95859d 100644 --- a/pkg/discoverer/k8s/service/podmetricsmap_test.go +++ b/pkg/discoverer/k8s/service/podmetricsmap_test.go @@ -18,7 +18,6 @@ package service import ( "reflect" - "sync" "sync/atomic" "testing" "unsafe" @@ -29,7 +28,6 @@ import ( ) func Test_newEntryPodMetricsMap(t *testing.T) { - t.Parallel() type args struct { i mpod.Pod } @@ -41,8 +39,8 @@ func Test_newEntryPodMetricsMap(t *testing.T) { args args want want checkFunc func(want, *entryPodMetricsMap) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got *entryPodMetricsMap) error { if !reflect.DeepEqual(got, w.want) { @@ -60,6 +58,12 @@ func Test_newEntryPodMetricsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -73,6 +77,12 @@ func Test_newEntryPodMetricsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -84,10 +94,10 @@ func Test_newEntryPodMetricsMap(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -103,12 +113,10 @@ func Test_newEntryPodMetricsMap(t *testing.T) { } func Test_podMetricsMap_Load(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int @@ -123,8 +131,8 @@ func Test_podMetricsMap_Load(t *testing.T) { fields fields want want checkFunc func(want, mpod.Pod, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotValue mpod.Pod, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -144,13 +152,18 @@ func Test_podMetricsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -163,13 +176,18 @@ func Test_podMetricsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -181,17 +199,16 @@ func Test_podMetricsMap_Load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -206,7 +223,6 @@ func Test_podMetricsMap_Load(t *testing.T) { } func Test_entryPodMetricsMap_load(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -219,8 +235,8 @@ func Test_entryPodMetricsMap_load(t *testing.T) { fields fields want want checkFunc func(want, mpod.Pod, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotValue mpod.Pod, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -241,6 +257,12 @@ func Test_entryPodMetricsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -254,6 +276,12 @@ func Test_entryPodMetricsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -265,10 +293,10 @@ func Test_entryPodMetricsMap_load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -287,13 +315,11 @@ func Test_entryPodMetricsMap_load(t *testing.T) { } func Test_podMetricsMap_Store(t *testing.T) { - t.Parallel() type args struct { key string value mpod.Pod } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int @@ -305,8 +331,8 @@ func Test_podMetricsMap_Store(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -321,13 +347,18 @@ func Test_podMetricsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -341,13 +372,18 @@ func Test_podMetricsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -359,17 +395,16 @@ func Test_podMetricsMap_Store(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -384,7 +419,6 @@ func Test_podMetricsMap_Store(t *testing.T) { } func Test_entryPodMetricsMap_tryStore(t *testing.T) { - t.Parallel() type args struct { i *mpod.Pod } @@ -400,8 +434,8 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -422,6 +456,12 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -438,6 +478,12 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -449,10 +495,10 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -471,7 +517,6 @@ func Test_entryPodMetricsMap_tryStore(t *testing.T) { } func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -483,8 +528,8 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotWasExpunged bool) error { if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { @@ -502,6 +547,12 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -515,6 +566,12 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -526,10 +583,10 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -548,7 +605,6 @@ func Test_entryPodMetricsMap_unexpungeLocked(t *testing.T) { } func Test_entryPodMetricsMap_storeLocked(t *testing.T) { - t.Parallel() type args struct { i *mpod.Pod } @@ -562,8 +618,8 @@ func Test_entryPodMetricsMap_storeLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -581,6 +637,12 @@ func Test_entryPodMetricsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -597,6 +659,12 @@ func Test_entryPodMetricsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -608,10 +676,10 @@ func Test_entryPodMetricsMap_storeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -630,13 +698,11 @@ func Test_entryPodMetricsMap_storeLocked(t *testing.T) { } func Test_podMetricsMap_LoadOrStore(t *testing.T) { - t.Parallel() type args struct { key string value mpod.Pod } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int @@ -651,8 +717,8 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, mpod.Pod, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual mpod.Pod, gotLoaded bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -673,13 +739,18 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -693,13 +764,18 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -711,17 +787,16 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -736,7 +811,6 @@ func Test_podMetricsMap_LoadOrStore(t *testing.T) { } func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { - t.Parallel() type args struct { i mpod.Pod } @@ -754,8 +828,8 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, mpod.Pod, bool, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual mpod.Pod, gotLoaded bool, gotOk bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -782,6 +856,12 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -798,6 +878,12 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -809,10 +895,10 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -831,12 +917,10 @@ func Test_entryPodMetricsMap_tryLoadOrStore(t *testing.T) { } func Test_podMetricsMap_Delete(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int @@ -848,8 +932,8 @@ func Test_podMetricsMap_Delete(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -863,13 +947,18 @@ func Test_podMetricsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -882,13 +971,18 @@ func Test_podMetricsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -900,17 +994,16 @@ func Test_podMetricsMap_Delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -925,7 +1018,6 @@ func Test_podMetricsMap_Delete(t *testing.T) { } func Test_entryPodMetricsMap_delete(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -937,8 +1029,8 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotHadValue bool) error { if !reflect.DeepEqual(gotHadValue, w.wantHadValue) { @@ -956,6 +1048,12 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -969,6 +1067,12 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -980,10 +1084,10 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1002,12 +1106,10 @@ func Test_entryPodMetricsMap_delete(t *testing.T) { } func Test_podMetricsMap_Range(t *testing.T) { - t.Parallel() type args struct { f func(key string, value mpod.Pod) bool } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int @@ -1019,8 +1121,8 @@ func Test_podMetricsMap_Range(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -1034,13 +1136,18 @@ func Test_podMetricsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1053,13 +1160,18 @@ func Test_podMetricsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1071,17 +1183,16 @@ func Test_podMetricsMap_Range(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1096,9 +1207,7 @@ func Test_podMetricsMap_Range(t *testing.T) { } func Test_podMetricsMap_missLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int @@ -1109,8 +1218,8 @@ func Test_podMetricsMap_missLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1121,13 +1230,18 @@ func Test_podMetricsMap_missLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1137,13 +1251,18 @@ func Test_podMetricsMap_missLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1155,17 +1274,16 @@ func Test_podMetricsMap_missLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1180,9 +1298,7 @@ func Test_podMetricsMap_missLocked(t *testing.T) { } func Test_podMetricsMap_dirtyLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodMetricsMap misses int @@ -1193,8 +1309,8 @@ func Test_podMetricsMap_dirtyLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1205,13 +1321,18 @@ func Test_podMetricsMap_dirtyLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1221,13 +1342,18 @@ func Test_podMetricsMap_dirtyLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1239,17 +1365,16 @@ func Test_podMetricsMap_dirtyLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podMetricsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1264,7 +1389,6 @@ func Test_podMetricsMap_dirtyLocked(t *testing.T) { } func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -1276,8 +1400,8 @@ func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotIsExpunged bool) error { if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { @@ -1295,6 +1419,12 @@ func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1308,6 +1438,12 @@ func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1319,10 +1455,10 @@ func Test_entryPodMetricsMap_tryExpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { diff --git a/pkg/discoverer/k8s/service/podsmap_test.go b/pkg/discoverer/k8s/service/podsmap_test.go index b2bbd29359..c04a24155d 100644 --- a/pkg/discoverer/k8s/service/podsmap_test.go +++ b/pkg/discoverer/k8s/service/podsmap_test.go @@ -18,7 +18,6 @@ package service import ( "reflect" - "sync" "sync/atomic" "testing" "unsafe" @@ -29,7 +28,6 @@ import ( ) func Test_newEntryPodsMap(t *testing.T) { - t.Parallel() type args struct { i []pod.Pod } @@ -41,8 +39,8 @@ func Test_newEntryPodsMap(t *testing.T) { args args want want checkFunc func(want, *entryPodsMap) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got *entryPodsMap) error { if !reflect.DeepEqual(got, w.want) { @@ -60,6 +58,12 @@ func Test_newEntryPodsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -73,6 +77,12 @@ func Test_newEntryPodsMap(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -84,10 +94,10 @@ func Test_newEntryPodsMap(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -103,12 +113,10 @@ func Test_newEntryPodsMap(t *testing.T) { } func Test_podsMap_Load(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int @@ -123,8 +131,8 @@ func Test_podsMap_Load(t *testing.T) { fields fields want want checkFunc func(want, []pod.Pod, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotValue []pod.Pod, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -144,13 +152,18 @@ func Test_podsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -163,13 +176,18 @@ func Test_podsMap_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -181,17 +199,16 @@ func Test_podsMap_Load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -206,7 +223,6 @@ func Test_podsMap_Load(t *testing.T) { } func Test_entryPodsMap_load(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -219,8 +235,8 @@ func Test_entryPodsMap_load(t *testing.T) { fields fields want want checkFunc func(want, []pod.Pod, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotValue []pod.Pod, gotOk bool) error { if !reflect.DeepEqual(gotValue, w.wantValue) { @@ -241,6 +257,12 @@ func Test_entryPodsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -254,6 +276,12 @@ func Test_entryPodsMap_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -265,10 +293,10 @@ func Test_entryPodsMap_load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -287,13 +315,11 @@ func Test_entryPodsMap_load(t *testing.T) { } func Test_podsMap_Store(t *testing.T) { - t.Parallel() type args struct { key string value []pod.Pod } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int @@ -305,8 +331,8 @@ func Test_podsMap_Store(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -321,13 +347,18 @@ func Test_podsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -341,13 +372,18 @@ func Test_podsMap_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -359,17 +395,16 @@ func Test_podsMap_Store(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -384,7 +419,6 @@ func Test_podsMap_Store(t *testing.T) { } func Test_entryPodsMap_tryStore(t *testing.T) { - t.Parallel() type args struct { i *[]pod.Pod } @@ -400,8 +434,8 @@ func Test_entryPodsMap_tryStore(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -422,6 +456,12 @@ func Test_entryPodsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -438,6 +478,12 @@ func Test_entryPodsMap_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -449,10 +495,10 @@ func Test_entryPodsMap_tryStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -471,7 +517,6 @@ func Test_entryPodsMap_tryStore(t *testing.T) { } func Test_entryPodsMap_unexpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -483,8 +528,8 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotWasExpunged bool) error { if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { @@ -502,6 +547,12 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -515,6 +566,12 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -526,10 +583,10 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -548,7 +605,6 @@ func Test_entryPodsMap_unexpungeLocked(t *testing.T) { } func Test_entryPodsMap_storeLocked(t *testing.T) { - t.Parallel() type args struct { i *[]pod.Pod } @@ -562,8 +618,8 @@ func Test_entryPodsMap_storeLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -581,6 +637,12 @@ func Test_entryPodsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -597,6 +659,12 @@ func Test_entryPodsMap_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -608,10 +676,10 @@ func Test_entryPodsMap_storeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -630,13 +698,11 @@ func Test_entryPodsMap_storeLocked(t *testing.T) { } func Test_podsMap_LoadOrStore(t *testing.T) { - t.Parallel() type args struct { key string value []pod.Pod } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int @@ -651,8 +717,8 @@ func Test_podsMap_LoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, []pod.Pod, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual []pod.Pod, gotLoaded bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -673,13 +739,18 @@ func Test_podsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -693,13 +764,18 @@ func Test_podsMap_LoadOrStore(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -711,17 +787,16 @@ func Test_podsMap_LoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -736,7 +811,6 @@ func Test_podsMap_LoadOrStore(t *testing.T) { } func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { - t.Parallel() type args struct { i []pod.Pod } @@ -754,8 +828,8 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { fields fields want want checkFunc func(want, []pod.Pod, bool, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotActual []pod.Pod, gotLoaded bool, gotOk bool) error { if !reflect.DeepEqual(gotActual, w.wantActual) { @@ -782,6 +856,12 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -798,6 +878,12 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -809,10 +895,10 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -831,12 +917,10 @@ func Test_entryPodsMap_tryLoadOrStore(t *testing.T) { } func Test_podsMap_Delete(t *testing.T) { - t.Parallel() type args struct { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int @@ -848,8 +932,8 @@ func Test_podsMap_Delete(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -863,13 +947,18 @@ func Test_podsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -882,13 +971,18 @@ func Test_podsMap_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -900,17 +994,16 @@ func Test_podsMap_Delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -925,7 +1018,6 @@ func Test_podsMap_Delete(t *testing.T) { } func Test_entryPodsMap_delete(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -937,8 +1029,8 @@ func Test_entryPodsMap_delete(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotHadValue bool) error { if !reflect.DeepEqual(gotHadValue, w.wantHadValue) { @@ -956,6 +1048,12 @@ func Test_entryPodsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -969,6 +1067,12 @@ func Test_entryPodsMap_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -980,10 +1084,10 @@ func Test_entryPodsMap_delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1002,12 +1106,10 @@ func Test_entryPodsMap_delete(t *testing.T) { } func Test_podsMap_Range(t *testing.T) { - t.Parallel() type args struct { f func(key string, value []pod.Pod) bool } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int @@ -1019,8 +1121,8 @@ func Test_podsMap_Range(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -1034,13 +1136,18 @@ func Test_podsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1053,13 +1160,18 @@ func Test_podsMap_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1071,17 +1183,16 @@ func Test_podsMap_Range(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1096,9 +1207,7 @@ func Test_podsMap_Range(t *testing.T) { } func Test_podsMap_missLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int @@ -1109,8 +1218,8 @@ func Test_podsMap_missLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1121,13 +1230,18 @@ func Test_podsMap_missLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1137,13 +1251,18 @@ func Test_podsMap_missLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1155,17 +1274,16 @@ func Test_podsMap_missLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1180,9 +1298,7 @@ func Test_podsMap_missLocked(t *testing.T) { } func Test_podsMap_dirtyLocked(t *testing.T) { - t.Parallel() type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryPodsMap misses int @@ -1193,8 +1309,8 @@ func Test_podsMap_dirtyLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -1205,13 +1321,18 @@ func Test_podsMap_dirtyLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1221,13 +1342,18 @@ func Test_podsMap_dirtyLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1239,17 +1365,16 @@ func Test_podsMap_dirtyLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } m := &podsMap{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1264,7 +1389,6 @@ func Test_podsMap_dirtyLocked(t *testing.T) { } func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { - t.Parallel() type fields struct { p unsafe.Pointer } @@ -1276,8 +1400,8 @@ func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotIsExpunged bool) error { if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { @@ -1295,6 +1419,12 @@ func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1308,6 +1438,12 @@ func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1319,10 +1455,10 @@ func Test_entryPodsMap_tryExpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil {