@@ -573,36 +573,45 @@ public void testAssignmentEventCorrectlyDeduplicatedFromBackgroundThreads() {
573
573
int numThreads = 10 ;
574
574
final CountDownLatch threadStartCountDownLatch = new CountDownLatch (numThreads );
575
575
final CountDownLatch getAssignmentStartCountDownLatch = new CountDownLatch (1 );
576
- final List <Integer > assignments = Collections .synchronizedList (Arrays .asList (new Integer [numThreads ]));
577
- try (ExecutorService pool = Executors .newFixedThreadPool (numThreads , new ThreadFactory () {
578
- private final AtomicInteger threadIndexAtomicInteger = new AtomicInteger (0 );
579
- @ Override
580
- public Thread newThread (@ NotNull Runnable runnable ) {
581
- final int threadIndex = threadIndexAtomicInteger .getAndIncrement ();
582
- return new Thread (runnable , "testAssignmentEventCorrectlyDeduplicatedFromBackgroundThreads-" + threadIndex );
583
- }
584
- })) {
576
+ final List <Integer > assignments =
577
+ Collections .synchronizedList (Arrays .asList (new Integer [numThreads ]));
578
+ ExecutorService pool =
579
+ Executors .newFixedThreadPool (
580
+ numThreads ,
581
+ new ThreadFactory () {
582
+ private final AtomicInteger threadIndexAtomicInteger = new AtomicInteger (0 );
583
+
584
+ @ Override
585
+ public Thread newThread (@ NotNull Runnable runnable ) {
586
+ final int threadIndex = threadIndexAtomicInteger .getAndIncrement ();
587
+ return new Thread (
588
+ runnable ,
589
+ "testAssignmentEventCorrectlyDeduplicatedFromBackgroundThreads-" + threadIndex );
590
+ }
591
+ });
592
+ try {
585
593
for (int i = 0 ; i < numThreads ; i += 1 ) {
586
594
final int threadIndex = i ;
587
595
pool .execute (
588
- () -> {
589
- threadStartCountDownLatch .countDown ();
590
- boolean shouldStart ;
591
- try {
592
- shouldStart = getAssignmentStartCountDownLatch .await (1000 , TimeUnit .SECONDS );
593
- } catch (InterruptedException ignored ) {
594
- shouldStart = false ;
595
- }
596
- final Integer assignment ;
597
- if (shouldStart ) {
598
- assignment = eppoClient .getIntegerAssignment ("numeric-one-of" , "alice" , subjectAttributes , 0 );
599
- } else {
600
- assignment = null ;
601
- }
602
-
603
- assignments .set (threadIndex , assignment );
604
- }
605
- );
596
+ () -> {
597
+ threadStartCountDownLatch .countDown ();
598
+ boolean shouldStart ;
599
+ try {
600
+ shouldStart = getAssignmentStartCountDownLatch .await (1000 , TimeUnit .SECONDS );
601
+ } catch (InterruptedException ignored ) {
602
+ shouldStart = false ;
603
+ }
604
+ final Integer assignment ;
605
+ if (shouldStart ) {
606
+ assignment =
607
+ eppoClient .getIntegerAssignment (
608
+ "numeric-one-of" , "alice" , subjectAttributes , 0 );
609
+ } else {
610
+ assignment = null ;
611
+ }
612
+
613
+ assignments .set (threadIndex , assignment );
614
+ });
606
615
}
607
616
608
617
boolean shouldStart ;
@@ -614,6 +623,16 @@ public Thread newThread(@NotNull Runnable runnable) {
614
623
615
624
assertTrue (shouldStart , "All worker threads did not start" );
616
625
getAssignmentStartCountDownLatch .countDown ();
626
+ } finally {
627
+ pool .shutdown ();
628
+ try {
629
+ if (!pool .awaitTermination (5 , TimeUnit .SECONDS )) {
630
+ pool .shutdownNow ();
631
+ }
632
+ } catch (InterruptedException e ) {
633
+ pool .shutdownNow ();
634
+ Thread .currentThread ().interrupt ();
635
+ }
617
636
}
618
637
619
638
final List <Integer > expectedAssignments ;
0 commit comments