Call non-blocking informerFactory.Start synchronously to avoid races

Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
This commit is contained in:
Dr. Stefan Schimanski
2024-07-27 16:13:16 +02:00
parent 250f7b5d15
commit c7a1fa432a
9 changed files with 20 additions and 19 deletions

View File

@@ -60,7 +60,7 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) {
serviceConfig := NewServiceConfig(ctx, sharedInformers.Core().V1().Services(), time.Minute)
serviceConfig.RegisterEventHandler(handler)
go sharedInformers.Start(stopCh)
sharedInformers.Start(stopCh)
go serviceConfig.Run(stopCh)
// Add the first service
@@ -141,7 +141,7 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) {
endpointsliceConfig := NewEndpointSliceConfig(ctx, sharedInformers.Discovery().V1().EndpointSlices(), time.Minute)
endpointsliceConfig.RegisterEventHandler(handler)
go sharedInformers.Start(stopCh)
sharedInformers.Start(stopCh)
go endpointsliceConfig.Run(stopCh)
// Add the first endpoints

View File

@@ -240,7 +240,7 @@ func TestNewServiceAddedAndNotified(t *testing.T) {
config := NewServiceConfig(ctx, sharedInformers.Core().V1().Services(), time.Minute)
handler := NewServiceHandlerMock()
config.RegisterEventHandler(handler)
go sharedInformers.Start(stopCh)
sharedInformers.Start(stopCh)
go config.Run(stopCh)
service := &v1.Service{
@@ -265,7 +265,7 @@ func TestServiceAddedRemovedSetAndNotified(t *testing.T) {
config := NewServiceConfig(ctx, sharedInformers.Core().V1().Services(), time.Minute)
handler := NewServiceHandlerMock()
config.RegisterEventHandler(handler)
go sharedInformers.Start(stopCh)
sharedInformers.Start(stopCh)
go config.Run(stopCh)
service1 := &v1.Service{
@@ -304,7 +304,7 @@ func TestNewServicesMultipleHandlersAddedAndNotified(t *testing.T) {
handler2 := NewServiceHandlerMock()
config.RegisterEventHandler(handler)
config.RegisterEventHandler(handler2)
go sharedInformers.Start(stopCh)
sharedInformers.Start(stopCh)
go config.Run(stopCh)
service1 := &v1.Service{
@@ -339,7 +339,7 @@ func TestNewEndpointsMultipleHandlersAddedAndNotified(t *testing.T) {
handler2 := NewEndpointSliceHandlerMock()
config.RegisterEventHandler(handler)
config.RegisterEventHandler(handler2)
go sharedInformers.Start(stopCh)
sharedInformers.Start(stopCh)
go config.Run(stopCh)
endpoints1 := &discoveryv1.EndpointSlice{
@@ -386,7 +386,7 @@ func TestNewEndpointsMultipleHandlersAddRemoveSetAndNotified(t *testing.T) {
handler2 := NewEndpointSliceHandlerMock()
config.RegisterEventHandler(handler)
config.RegisterEventHandler(handler2)
go sharedInformers.Start(stopCh)
sharedInformers.Start(stopCh)
go config.Run(stopCh)
endpoints1 := &discoveryv1.EndpointSlice{