mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 11:38:15 +00:00
use stopCh to avoid goroutine leak in tests
This commit is contained in:
parent
d48fc2ad2d
commit
132d477cb7
@ -107,7 +107,11 @@ func TestAccessReviewCheckOnMissingNamespace(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error initializing handler: %v", err)
|
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)
|
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 {
|
if err != nil {
|
||||||
|
@ -115,15 +115,17 @@ func TestQueueWaitTimeLatencyTracker(t *testing.T) {
|
|||||||
QueueSetFactory: fqs.NewQueueSetFactory(clk),
|
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 {
|
if names := unsynced(status); len(names) > 0 {
|
||||||
t.Fatalf("WaitForCacheSync did not successfully complete, resources=%#v", names)
|
t.Fatalf("WaitForCacheSync did not successfully complete, resources=%#v", names)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
controller.Run(nil)
|
controller.Run(stopCh)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// ensure that the controller has run its first loop.
|
// ensure that the controller has run its first loop.
|
||||||
|
@ -1656,8 +1656,11 @@ func Test_syncNode(t *testing.T) {
|
|||||||
nodeStatusUpdateFrequency: 1 * time.Second,
|
nodeStatusUpdateFrequency: 1 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
factory.Start(nil)
|
stopCh := make(chan struct{})
|
||||||
factory.WaitForCacheSync(nil)
|
defer close(stopCh)
|
||||||
|
|
||||||
|
factory.Start(stopCh)
|
||||||
|
factory.WaitForCacheSync(stopCh)
|
||||||
|
|
||||||
w := eventBroadcaster.StartLogging(klog.Infof)
|
w := eventBroadcaster.StartLogging(klog.Infof)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
@ -1740,8 +1743,11 @@ func TestGCEConditionV2(t *testing.T) {
|
|||||||
nodeStatusUpdateFrequency: 1 * time.Second,
|
nodeStatusUpdateFrequency: 1 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
factory.Start(nil)
|
stopCh := make(chan struct{})
|
||||||
factory.WaitForCacheSync(nil)
|
defer close(stopCh)
|
||||||
|
|
||||||
|
factory.Start(stopCh)
|
||||||
|
factory.WaitForCacheSync(stopCh)
|
||||||
|
|
||||||
w := eventBroadcaster.StartLogging(klog.Infof)
|
w := eventBroadcaster.StartLogging(klog.Infof)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
@ -1828,8 +1834,11 @@ func TestGCECondition(t *testing.T) {
|
|||||||
nodeStatusUpdateFrequency: 1 * time.Second,
|
nodeStatusUpdateFrequency: 1 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
factory.Start(nil)
|
stopCh := make(chan struct{})
|
||||||
factory.WaitForCacheSync(nil)
|
defer close(stopCh)
|
||||||
|
|
||||||
|
factory.Start(stopCh)
|
||||||
|
factory.WaitForCacheSync(stopCh)
|
||||||
|
|
||||||
w := eventBroadcaster.StartLogging(klog.Infof)
|
w := eventBroadcaster.StartLogging(klog.Infof)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
@ -1934,10 +1943,13 @@ func Test_reconcileNodeLabels(t *testing.T) {
|
|||||||
nodeInformer: factory.Core().V1().Nodes(),
|
nodeInformer: factory.Core().V1().Nodes(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stopCh := make(chan struct{})
|
||||||
|
defer close(stopCh)
|
||||||
|
|
||||||
// activate node informer
|
// activate node informer
|
||||||
factory.Core().V1().Nodes().Informer()
|
factory.Core().V1().Nodes().Informer()
|
||||||
factory.Start(nil)
|
factory.Start(stopCh)
|
||||||
factory.WaitForCacheSync(nil)
|
factory.WaitForCacheSync(stopCh)
|
||||||
|
|
||||||
err := cnc.reconcileNodeLabels("node01")
|
err := cnc.reconcileNodeLabels("node01")
|
||||||
if err != test.expectedErr {
|
if err != test.expectedErr {
|
||||||
|
Loading…
Reference in New Issue
Block a user