Merge pull request #119127 from Mskxn/fix_leak

use stopCh to avoid goroutine leak in tests

Kubernetes-commit: 4c7cda3e55736822bdee4c2ac93f989cf8f1501c
This commit is contained in:
Kubernetes Publisher 2023-07-06 14:39:25 -07:00
commit 0d62f07a5d
4 changed files with 14 additions and 8 deletions

4
go.mod
View File

@ -41,7 +41,7 @@ require (
google.golang.org/protobuf v1.30.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/square/go-jose.v2 v2.6.0
k8s.io/api v0.0.0-20230706062605-a69cc64b8aea
k8s.io/api v0.0.0-20230706213904-5d126b39754e
k8s.io/apimachinery v0.0.0-20230628220152-83d6d372b1a4
k8s.io/client-go v0.0.0-20230706193217-d31edad7e26d
k8s.io/component-base v0.0.0-20230706070231-63369697f0ec
@ -125,7 +125,7 @@ require (
)
replace (
k8s.io/api => k8s.io/api v0.0.0-20230706062605-a69cc64b8aea
k8s.io/api => k8s.io/api v0.0.0-20230706213904-5d126b39754e
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20230628220152-83d6d372b1a4
k8s.io/client-go => k8s.io/client-go v0.0.0-20230706193217-d31edad7e26d
k8s.io/component-base => k8s.io/component-base v0.0.0-20230706070231-63369697f0ec

4
go.sum
View File

@ -668,8 +668,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.0.0-20230706062605-a69cc64b8aea h1:Wmw+hwQKZdnoXQWQKf+yzCoPY8/rDBmzRvhnQ/63jbw=
k8s.io/api v0.0.0-20230706062605-a69cc64b8aea/go.mod h1:ghFHmaoujTvUqKl24+WADIX4gEvgTA8BEpgFe3ZPylQ=
k8s.io/api v0.0.0-20230706213904-5d126b39754e h1:n5vIa/QSWmYhVnhhqHU8vd+j9Q1YHJUp/5flNUA5V+U=
k8s.io/api v0.0.0-20230706213904-5d126b39754e/go.mod h1:ghFHmaoujTvUqKl24+WADIX4gEvgTA8BEpgFe3ZPylQ=
k8s.io/apimachinery v0.0.0-20230628220152-83d6d372b1a4 h1:ntS2ZHGzNY/ISRKPPU937LFSwjYZ7poMcwAeu1xCnKM=
k8s.io/apimachinery v0.0.0-20230628220152-83d6d372b1a4/go.mod h1:tAiIbF8KB8+Ri2DfUWwZGwNOThIwM0fhXLnOymriu+4=
k8s.io/client-go v0.0.0-20230706193217-d31edad7e26d h1:dV/RK6/9qiCbyWrVhPaiFojP/1/YOjnw6i1Z3JyeuEE=

View File

@ -107,7 +107,11 @@ func TestAccessReviewCheckOnMissingNamespace(t *testing.T) {
if err != nil {
t.Errorf("unexpected error initializing handler: %v", err)
}
informerFactory.Start(wait.NeverStop)
stopCh := make(chan struct{})
defer close(stopCh)
informerFactory.Start(stopCh)
err = handler.Admit(context.TODO(), admission.NewAttributesRecord(nil, nil, schema.GroupVersionKind{Group: "authorization.k8s.io", Version: "v1", Kind: "LocalSubjectAccesReview"}, namespace, "", schema.GroupVersionResource{Group: "authorization.k8s.io", Version: "v1", Resource: "localsubjectaccessreviews"}, "", admission.Create, &metav1.CreateOptions{}, false, nil), nil)
if err != nil {

View File

@ -115,15 +115,17 @@ func TestQueueWaitTimeLatencyTracker(t *testing.T) {
QueueSetFactory: fqs.NewQueueSetFactory(clk),
})
informerFactory.Start(nil)
stopCh := make(chan struct{})
defer close(stopCh)
status := informerFactory.WaitForCacheSync(nil)
informerFactory.Start(stopCh)
status := informerFactory.WaitForCacheSync(stopCh)
if names := unsynced(status); len(names) > 0 {
t.Fatalf("WaitForCacheSync did not successfully complete, resources=%#v", names)
}
go func() {
controller.Run(nil)
controller.Run(stopCh)
}()
// ensure that the controller has run its first loop.