Skip to content

Commit 43bfeff

Browse files
authored
Fix race in agentless config source listener test
scheduledPollContinuesAfterListenerRuntimeException waited on FakeClient.calls, which is incremented when a request starts rather than when it completes. The barrier therefore released as soon as the second poll began, letting the assertion race the poll thread that applies the configuration and notifies the listener. Wait on a CountDownLatch counted down by the listener itself, so the second notification is guaranteed to have happened before the assertions run. Environment: Datadog workspace Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: vickie.fridge <vickie.fridge@datadoghq.com>
1 parent 5ce7fa3 commit 43bfeff

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

products/feature-flagging/feature-flagging-lib/src/test/java/com/datadog/featureflag/AgentlessConfigurationSourceTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,17 +920,22 @@ void scheduledPollContinuesAfterListenerRuntimeException() throws Exception {
920920
client,
921921
Executors.newSingleThreadScheduledExecutor());
922922
final AtomicInteger listenerCalls = new AtomicInteger();
923+
// Wait on the listener rather than on FakeClient.calls: the call counter is incremented when
924+
// a request starts, so it reaches 2 before the second configuration has been applied.
925+
final CountDownLatch listenerNotified = new CountDownLatch(2);
923926
final FeatureFlaggingGateway.ConfigListener flakyListener =
924927
configuration -> {
925-
if (listenerCalls.incrementAndGet() == 1) {
928+
final int call = listenerCalls.incrementAndGet();
929+
listenerNotified.countDown();
930+
if (call == 1) {
926931
throw new IllegalStateException("listener rejected first configuration");
927932
}
928933
};
929934
FeatureFlaggingGateway.addConfigListener(flakyListener);
930935

931936
try {
932937
service.init();
933-
awaitCalls(client, 2);
938+
assertTrue(listenerNotified.await(5, TimeUnit.SECONDS));
934939

935940
assertEquals(2, listenerCalls.get());
936941
assertNull(client.requests.get(1).etag);

0 commit comments

Comments
 (0)