mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 03:03:59 +00:00
Merge pull request #119127 from Mskxn/fix_leak
use stopCh to avoid goroutine leak in tests
This commit is contained in:
commit
4c7cda3e55
@ -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 {
|
||||
|
@ -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.
|
||||
|
@ -1656,8 +1656,11 @@ func Test_syncNode(t *testing.T) {
|
||||
nodeStatusUpdateFrequency: 1 * time.Second,
|
||||
}
|
||||
|
||||
factory.Start(nil)
|
||||
factory.WaitForCacheSync(nil)
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
|
||||
factory.Start(stopCh)
|
||||
factory.WaitForCacheSync(stopCh)
|
||||
|
||||
w := eventBroadcaster.StartLogging(klog.Infof)
|
||||
defer w.Stop()
|
||||
@ -1740,8 +1743,11 @@ func TestGCEConditionV2(t *testing.T) {
|
||||
nodeStatusUpdateFrequency: 1 * time.Second,
|
||||
}
|
||||
|
||||
factory.Start(nil)
|
||||
factory.WaitForCacheSync(nil)
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
|
||||
factory.Start(stopCh)
|
||||
factory.WaitForCacheSync(stopCh)
|
||||
|
||||
w := eventBroadcaster.StartLogging(klog.Infof)
|
||||
defer w.Stop()
|
||||
@ -1828,8 +1834,11 @@ func TestGCECondition(t *testing.T) {
|
||||
nodeStatusUpdateFrequency: 1 * time.Second,
|
||||
}
|
||||
|
||||
factory.Start(nil)
|
||||
factory.WaitForCacheSync(nil)
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
|
||||
factory.Start(stopCh)
|
||||
factory.WaitForCacheSync(stopCh)
|
||||
|
||||
w := eventBroadcaster.StartLogging(klog.Infof)
|
||||
defer w.Stop()
|
||||
@ -1934,10 +1943,13 @@ func Test_reconcileNodeLabels(t *testing.T) {
|
||||
nodeInformer: factory.Core().V1().Nodes(),
|
||||
}
|
||||
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
|
||||
// activate node informer
|
||||
factory.Core().V1().Nodes().Informer()
|
||||
factory.Start(nil)
|
||||
factory.WaitForCacheSync(nil)
|
||||
factory.Start(stopCh)
|
||||
factory.WaitForCacheSync(stopCh)
|
||||
|
||||
err := cnc.reconcileNodeLabels("node01")
|
||||
if err != test.expectedErr {
|
||||
|
Loading…
Reference in New Issue
Block a user