@@ -1804,7 +1804,7 @@ var _ = Describe("manger.Manager", func() {
1804
1804
Eventually (func () error { return goleak .Find (currentGRs ) }).Should (Succeed ())
1805
1805
})
1806
1806
1807
- It ("should not leak goroutines if the default event broadcaster is used & events are emitted" , func (specCtx SpecContext ) {
1807
+ It ("should not leak goroutines if the deprecated event broadcaster is used & events are emitted" , func (specCtx SpecContext ) {
1808
1808
currentGRs := goleak .IgnoreCurrent ()
1809
1809
1810
1810
m , err := New (cfg , Options { /* implicit: default setting for EventBroadcaster */ })
@@ -1852,6 +1852,54 @@ var _ = Describe("manger.Manager", func() {
1852
1852
Eventually (func () error { return goleak .Find (currentGRs ) }).Should (Succeed ())
1853
1853
})
1854
1854
1855
+ It ("should not leak goroutines if the default event broadcaster is used & events are emitted" , func (specCtx SpecContext ) {
1856
+ currentGRs := goleak .IgnoreCurrent ()
1857
+
1858
+ m , err := New (cfg , Options { /* implicit: default setting for EventBroadcaster */ })
1859
+ Expect (err ).NotTo (HaveOccurred ())
1860
+
1861
+ By ("adding a runnable that emits an event" )
1862
+ ns := corev1.Namespace {}
1863
+ ns .Name = "default"
1864
+
1865
+ recorder := m .GetEventRecorder ("rock-and-roll" )
1866
+ Expect (m .Add (RunnableFunc (func (_ context.Context ) error {
1867
+ recorder .Eventf (& ns , nil , "Warning" , "BallroomBlitz" , "dance action" , "yeah, yeah, yeah-yeah-yeah" )
1868
+ return nil
1869
+ }))).To (Succeed ())
1870
+
1871
+ By ("starting the manager & waiting till we've sent our event" )
1872
+ ctx , cancel := context .WithCancel (specCtx )
1873
+ doneCh := make (chan struct {})
1874
+ go func () {
1875
+ defer GinkgoRecover ()
1876
+ defer close (doneCh )
1877
+ Expect (m .Start (ctx )).To (Succeed ())
1878
+ }()
1879
+ <- m .Elected ()
1880
+
1881
+ Eventually (func () * corev1.Event {
1882
+ evts , err := clientset .CoreV1 ().Events ("" ).SearchWithContext (ctx , m .GetScheme (), & ns )
1883
+ Expect (err ).NotTo (HaveOccurred ())
1884
+
1885
+ for i , evt := range evts .Items {
1886
+ if evt .Reason == "BallroomBlitz" {
1887
+ return & evts .Items [i ]
1888
+ }
1889
+ }
1890
+ return nil
1891
+ }).ShouldNot (BeNil ())
1892
+
1893
+ By ("making sure there's no extra go routines still running after we stop" )
1894
+ cancel ()
1895
+ <- doneCh
1896
+
1897
+ // force-close keep-alive connections. These'll time anyway (after
1898
+ // like 30s or so) but force it to speed up the tests.
1899
+ clientTransport .CloseIdleConnections ()
1900
+ Eventually (func () error { return goleak .Find (currentGRs ) }).Should (Succeed ())
1901
+ })
1902
+
1855
1903
It ("should not leak goroutines when a runnable returns error slowly after being signaled to stop" , func (specCtx SpecContext ) {
1856
1904
// This test reproduces the race condition where the manager's Start method
1857
1905
// exits due to context cancellation, leaving no one to drain errChan
@@ -1932,11 +1980,16 @@ var _ = Describe("manger.Manager", func() {
1932
1980
Expect (m .GetFieldIndexer ()).To (Equal (mgr .cluster .GetFieldIndexer ()))
1933
1981
})
1934
1982
1935
- It ("should provide a function to get the EventRecorder" , func () {
1983
+ It ("should provide a function to get the deprecated EventRecorder" , func () {
1936
1984
m , err := New (cfg , Options {})
1937
1985
Expect (err ).NotTo (HaveOccurred ())
1938
1986
Expect (m .GetEventRecorderFor ("test" )).NotTo (BeNil ()) //nolint:staticcheck
1939
1987
})
1988
+ It ("should provide a function to get the EventRecorder" , func () {
1989
+ m , err := New (cfg , Options {})
1990
+ Expect (err ).NotTo (HaveOccurred ())
1991
+ Expect (m .GetEventRecorder ("test" )).NotTo (BeNil ())
1992
+ })
1940
1993
It ("should provide a function to get the APIReader" , func () {
1941
1994
m , err := New (cfg , Options {})
1942
1995
Expect (err ).NotTo (HaveOccurred ())
0 commit comments