mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #100218 from aojea/unitflakes1
unit test using metrics must reset the global registry
This commit is contained in:
commit
6850e0abf2
@ -30,6 +30,7 @@ import (
|
|||||||
|
|
||||||
func TestNetworkPluginManagerMetrics(t *testing.T) {
|
func TestNetworkPluginManagerMetrics(t *testing.T) {
|
||||||
metrics.Register()
|
metrics.Register()
|
||||||
|
defer legacyregistry.Reset()
|
||||||
|
|
||||||
operation := "test_operation"
|
operation := "test_operation"
|
||||||
recordOperation(operation, time.Now())
|
recordOperation(operation, time.Now())
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apiserver/pkg/admission"
|
"k8s.io/apiserver/pkg/admission"
|
||||||
|
"k8s.io/component-base/metrics/legacyregistry"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -35,7 +36,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestObserveAdmissionStep(t *testing.T) {
|
func TestObserveAdmissionStep(t *testing.T) {
|
||||||
Metrics.reset()
|
defer Metrics.reset()
|
||||||
|
defer legacyregistry.Reset()
|
||||||
handler := WithStepMetrics(&mutatingAndValidatingFakeHandler{admission.NewHandler(admission.Create), true, true})
|
handler := WithStepMetrics(&mutatingAndValidatingFakeHandler{admission.NewHandler(admission.Create), true, true})
|
||||||
if err := handler.(admission.MutationInterface).Admit(context.TODO(), attr, nil); err != nil {
|
if err := handler.(admission.MutationInterface).Admit(context.TODO(), attr, nil); err != nil {
|
||||||
t.Errorf("Unexpected error in admit: %v", err)
|
t.Errorf("Unexpected error in admit: %v", err)
|
||||||
@ -57,7 +59,8 @@ func TestObserveAdmissionStep(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestObserveAdmissionController(t *testing.T) {
|
func TestObserveAdmissionController(t *testing.T) {
|
||||||
Metrics.reset()
|
defer Metrics.reset()
|
||||||
|
defer legacyregistry.Reset()
|
||||||
handler := WithControllerMetrics(&mutatingAndValidatingFakeHandler{admission.NewHandler(admission.Create), true, true}, "a")
|
handler := WithControllerMetrics(&mutatingAndValidatingFakeHandler{admission.NewHandler(admission.Create), true, true}, "a")
|
||||||
if err := handler.(admission.MutationInterface).Admit(context.TODO(), attr, nil); err != nil {
|
if err := handler.(admission.MutationInterface).Admit(context.TODO(), attr, nil); err != nil {
|
||||||
t.Errorf("Unexpected error in admit: %v", err)
|
t.Errorf("Unexpected error in admit: %v", err)
|
||||||
@ -78,7 +81,8 @@ func TestObserveAdmissionController(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestObserveWebhook(t *testing.T) {
|
func TestObserveWebhook(t *testing.T) {
|
||||||
Metrics.reset()
|
defer Metrics.reset()
|
||||||
|
defer legacyregistry.Reset()
|
||||||
Metrics.ObserveWebhook(context.TODO(), 2*time.Second, false, attr, stepAdmit, "x")
|
Metrics.ObserveWebhook(context.TODO(), 2*time.Second, false, attr, stepAdmit, "x")
|
||||||
wantLabels := map[string]string{
|
wantLabels := map[string]string{
|
||||||
"name": "x",
|
"name": "x",
|
||||||
@ -121,8 +125,8 @@ func TestObserveWebhookRejection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWithMetrics(t *testing.T) {
|
func TestWithMetrics(t *testing.T) {
|
||||||
Metrics.reset()
|
defer Metrics.reset()
|
||||||
|
defer legacyregistry.Reset()
|
||||||
type Test struct {
|
type Test struct {
|
||||||
name string
|
name string
|
||||||
ns string
|
ns string
|
||||||
|
Loading…
Reference in New Issue
Block a user