2424
2525import org .junit .jupiter .api .BeforeEach ;
2626import org .junit .jupiter .api .Test ;
27+ import org .junit .jupiter .api .TestInstance ;
2728
2829import io .fabric8 .kubernetes .api .model .HasMetadata ;
2930import io .fabric8 .kubernetes .api .model .ObjectMeta ;
6465import static org .mockito .Mockito .when ;
6566
6667@ SuppressWarnings ({"rawtypes" , "unchecked" })
68+ @ TestInstance (value = TestInstance .Lifecycle .PER_METHOD )
6769class InformerEventSourceTest {
6870
6971 private static final String PREV_RESOURCE_VERSION = "0" ;
7072 private static final String DEFAULT_RESOURCE_VERSION = "1" ;
7173
72- ExecutorService executorService = Executors .newSingleThreadExecutor ();
74+ ExecutorService executorService = Executors .newCachedThreadPool ();
7375
7476 private InformerEventSource <Deployment , TestCustomResource > informerEventSource ;
7577 private final KubernetesClient clientMock = MockKubernetesClient .client (Deployment .class );
@@ -205,7 +207,7 @@ void filtersOnDeleteEvents() {
205207 }
206208
207209 @ Test
208- void handlesPrevResourceVersionForUpdate () {
210+ void handlesPrevResourceVersionForUpdate () throws InterruptedException {
209211 withRealTemporaryResourceCache ();
210212 var deployment = testDeployment ();
211213 CountDownLatch latch = new CountDownLatch (1 );
@@ -224,7 +226,10 @@ void handlesPrevResourceVersionForUpdate() {
224226 }
225227 return resp ;
226228 }));
227- informerEventSource .onUpdate (deployment , incResourceVersion (testDeployment (), 2 ));
229+ Thread .sleep (50 );
230+ informerEventSource .onUpdate (
231+ incResourceVersion (deployment , 1 ), incResourceVersion (testDeployment (), 2 ));
232+
228233 latch .countDown ();
229234
230235 await ()
@@ -251,7 +256,7 @@ void handlesPrevResourceVersionForUpdate() {
251256 }
252257
253258 @ Test
254- void handlesPrevResourceVersionForUpdateInCaseOfException () {
259+ void handlesPrevResourceVersionForUpdateInCaseOfException () throws InterruptedException {
255260 withRealTemporaryResourceCache ();
256261
257262 withRealTemporaryResourceCache ();
@@ -270,6 +275,7 @@ void handlesPrevResourceVersionForUpdateInCaseOfException() {
270275 throw new RuntimeException (e );
271276 }
272277 }));
278+ Thread .sleep (50 );
273279 informerEventSource .onUpdate (deployment , incResourceVersion (testDeployment (), 1 ));
274280 latch .countDown ();
275281
@@ -297,7 +303,7 @@ void handlesPrevResourceVersionForUpdateInCaseOfException() {
297303 }
298304
299305 @ Test
300- void handlesPrevResourceVersionForUpdateInCaseOfMultipleUpdates () {
306+ void handlesPrevResourceVersionForUpdateInCaseOfMultipleUpdates () throws InterruptedException {
301307 withRealTemporaryResourceCache ();
302308
303309 withRealTemporaryResourceCache ();
@@ -318,7 +324,7 @@ void handlesPrevResourceVersionForUpdateInCaseOfMultipleUpdates() {
318324 }
319325 return resp ;
320326 }));
321-
327+ Thread . sleep ( 50 );
322328 informerEventSource .onUpdate (
323329 incResourceVersion (testDeployment (), 1 ), incResourceVersion (testDeployment (), 2 ));
324330 informerEventSource .onUpdate (
@@ -349,7 +355,7 @@ void handlesPrevResourceVersionForUpdateInCaseOfMultipleUpdates() {
349355 }
350356
351357 @ Test
352- void doesNotPropagateEventIfReceivedBeforeUpdate () {
358+ void doesNotPropagateEventIfReceivedBeforeUpdate () throws InterruptedException {
353359 withRealTemporaryResourceCache ();
354360 var deployment = testDeployment ();
355361 CountDownLatch latch = new CountDownLatch (1 );
@@ -368,6 +374,7 @@ void doesNotPropagateEventIfReceivedBeforeUpdate() {
368374 }
369375 return resp ;
370376 }));
377+ Thread .sleep (50 );
371378 informerEventSource .onUpdate (deployment , incResourceVersion (testDeployment (), 1 ));
372379 latch .countDown ();
373380
0 commit comments