Skip to content

Commit 321fb4f

Browse files
committed
Fix test expectations.
1 parent 147556d commit 321fb4f

File tree

1 file changed

+18
-48
lines changed

1 file changed

+18
-48
lines changed

lib/sdk/server/src/test/java/com/launchdarkly/sdk/server/FDv2DataSourceTest.java

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.time.Instant;
1919
import java.util.ArrayList;
20+
import java.util.LinkedList;
2021
import java.util.List;
2122
import java.util.concurrent.*;
2223
import java.util.concurrent.atomic.AtomicBoolean;
@@ -1437,11 +1438,8 @@ public void recoveryResetsToFirstAvailableSynchronizer() throws Exception {
14371438
Future<Void> startFuture = dataSource.start();
14381439
startFuture.get(2, TimeUnit.SECONDS);
14391440

1440-
// Wait for recovery timeout to trigger by waiting for multiple synchronizer calls
1441-
// Recovery brings us back to first, so we should see multiple calls eventually
1442-
for (int i = 0; i < 3; i++) {
1443-
sink.awaitApplyCount(i + 1, 5, TimeUnit.SECONDS);
1444-
}
1441+
// Wait for 3 applies with enough time for recovery (2s) + overhead
1442+
sink.awaitApplyCount(3, 5, TimeUnit.SECONDS);
14451443

14461444
// Should have called first synchronizer again after recovery
14471445
assertTrue(firstCallCount.get() >= 2 || secondCallCount.get() >= 1);
@@ -1732,73 +1730,45 @@ public void multipleChangeSetsAppliedInOrder() throws Exception {
17321730
assertEquals(3, sink.getApplyCount());
17331731
}
17341732

1735-
@Test
1736-
public void selectorEmptyStillCompletesIfAnyDataReceived() throws Exception {
1737-
executor = Executors.newScheduledThreadPool(2);
1738-
MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink();
1739-
1740-
CompletableFuture<FDv2SourceResult> initializerFuture = CompletableFuture.completedFuture(
1741-
FDv2SourceResult.changeSet(makeChangeSet(false), false)
1742-
);
1743-
1744-
ImmutableList<FDv2DataSource.DataSourceFactory<Initializer>> initializers = ImmutableList.of(
1745-
() -> new MockInitializer(initializerFuture)
1746-
);
1747-
1748-
CompletableFuture<FDv2SourceResult> synchronizerFuture = CompletableFuture.completedFuture(
1749-
FDv2SourceResult.changeSet(makeChangeSet(false), false)
1750-
);
1751-
1752-
ImmutableList<FDv2DataSource.DataSourceFactory<Synchronizer>> synchronizers = ImmutableList.of(
1753-
() -> new MockSynchronizer(synchronizerFuture)
1754-
);
1755-
1756-
FDv2DataSource dataSource = new FDv2DataSource(initializers, synchronizers, sink, Thread.NORM_PRIORITY, logger, executor, 120, 300);
1757-
resourcesToClose.add(dataSource);
1758-
1759-
Future<Void> startFuture = dataSource.start();
1760-
startFuture.get(2, TimeUnit.SECONDS);
1761-
1762-
assertTrue(dataSource.isInitialized());
1763-
1764-
// Wait for the synchronizer to also run
1765-
sink.awaitApplyCount(2, 2, TimeUnit.SECONDS);
1766-
assertEquals(2, sink.getApplyCount()); // Both initializer and synchronizer
1767-
}
1768-
17691733
@Test
17701734
public void selectorNonEmptyCompletesInitialization() throws Exception {
17711735
executor = Executors.newScheduledThreadPool(2);
17721736
MockDataSourceUpdateSink sink = new MockDataSourceUpdateSink();
17731737

1774-
CompletableFuture<FDv2SourceResult> initializerFuture = CompletableFuture.completedFuture(
1738+
CompletableFuture<FDv2SourceResult> firstInitializerFuture = CompletableFuture.completedFuture(
17751739
FDv2SourceResult.changeSet(makeChangeSet(true), false)
17761740
);
17771741

1778-
AtomicBoolean synchronizerCalled = new AtomicBoolean(false);
1742+
BlockingQueue<Boolean> secondInitializerCalledQueue = new LinkedBlockingQueue<>();
17791743

17801744
ImmutableList<FDv2DataSource.DataSourceFactory<Initializer>> initializers = ImmutableList.of(
1781-
() -> new MockInitializer(initializerFuture)
1782-
);
1783-
1784-
ImmutableList<FDv2DataSource.DataSourceFactory<Synchronizer>> synchronizers = ImmutableList.of(
1745+
() -> new MockInitializer(firstInitializerFuture),
17851746
() -> {
1786-
synchronizerCalled.set(true);
1787-
return new MockSynchronizer(CompletableFuture.completedFuture(
1747+
secondInitializerCalledQueue.offer(true);
1748+
return new MockInitializer(CompletableFuture.completedFuture(
17881749
FDv2SourceResult.changeSet(makeChangeSet(false), false)
17891750
));
17901751
}
17911752
);
17921753

1754+
ImmutableList<FDv2DataSource.DataSourceFactory<Synchronizer>> synchronizers = ImmutableList.of(
1755+
() -> new MockSynchronizer(CompletableFuture.completedFuture(
1756+
FDv2SourceResult.changeSet(makeChangeSet(false), false)
1757+
))
1758+
);
1759+
17931760
FDv2DataSource dataSource = new FDv2DataSource(initializers, synchronizers, sink, Thread.NORM_PRIORITY, logger, executor, 120, 300);
17941761
resourcesToClose.add(dataSource);
17951762

17961763
Future<Void> startFuture = dataSource.start();
17971764
startFuture.get(2, TimeUnit.SECONDS);
17981765

17991766
assertTrue(dataSource.isInitialized());
1800-
assertFalse(synchronizerCalled.get()); // Should not proceed to synchronizers
18011767
assertEquals(1, sink.getApplyCount());
1768+
1769+
// Second initializer should not be called since first had non-empty selector
1770+
Boolean secondInitializerCalled = secondInitializerCalledQueue.poll(500, TimeUnit.MILLISECONDS);
1771+
assertNull("Second initializer should not be called when first returns non-empty selector", secondInitializerCalled);
18021772
}
18031773

18041774
@Test

0 commit comments

Comments
 (0)