Skip to content

Commit 60368a0

Browse files
committed
Add debug logging and increase timeouts for flaky OpAMP client tests
- Increase takeRequest timeout from 1s to 5s - Increase await timeouts from 1s to 5s - Add detailed debug logging to failing test methods - This should help identify the root cause of sporadic test failures
1 parent 417ae7f commit 60368a0

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

opamp-client/src/test/java/io/opentelemetry/opamp/client/internal/impl/OpampClientImplTest.java

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void onSuccess_withChangesToReport_notifyCallbackOnMessage() {
209209
requestService.sendRequest();
210210

211211
// Await for onMessage call
212-
await().atMost(Duration.ofSeconds(1)).until(() -> callbacks.onMessageCalls.get() == 1);
212+
await().atMost(Duration.ofSeconds(5)).until(() -> callbacks.onMessageCalls.get() == 1);
213213

214214
verify(callbacks).onMessage(MessageData.builder().setRemoteConfig(remoteConfig).build());
215215
}
@@ -231,50 +231,67 @@ void onSuccess_withNoChangesToReport_doNotNotifyCallbackOnMessage() {
231231

232232
@Test
233233
void verifyAgentDescriptionSetter() {
234+
System.out.println("DEBUG: Starting verifyAgentDescriptionSetter test");
234235
initializeClient();
235236
AgentDescription agentDescription =
236237
getAgentDescriptionWithOneIdentifyingValue("service.name", "My service");
237238

238239
// Update when changed
240+
System.out.println("DEBUG: Setting agent description and expecting request...");
239241
enqueueServerToAgentResponse(new ServerToAgent.Builder().build());
240242
client.setAgentDescription(agentDescription);
241-
assertThat(takeRequest()).isNotNull();
243+
RecordedRequest firstRequest = takeRequest();
244+
System.out.println("DEBUG: First request result: " + (firstRequest != null));
245+
assertThat(firstRequest).isNotNull();
242246

243247
// Ignore when the provided value is the same as the current one
248+
System.out.println("DEBUG: Setting same agent description and expecting no request...");
244249
enqueueServerToAgentResponse(new ServerToAgent.Builder().build());
245250
client.setAgentDescription(agentDescription);
246-
assertThat(takeRequest()).isNull();
251+
RecordedRequest secondRequest = takeRequest();
252+
System.out.println("DEBUG: Second request result: " + (secondRequest != null));
253+
assertThat(secondRequest).isNull();
254+
System.out.println("DEBUG: verifyAgentDescriptionSetter test completed");
247255
}
248256

249257
@Test
250258
void verifyRemoteConfigStatusSetter() {
259+
System.out.println("DEBUG: Starting verifyRemoteConfigStatusSetter test");
251260
initializeClient();
252261
RemoteConfigStatus remoteConfigStatus =
253262
getRemoteConfigStatus(RemoteConfigStatuses.RemoteConfigStatuses_APPLYING);
254263

255264
// Update when changed
265+
System.out.println("DEBUG: Setting remote config status and expecting request...");
256266
enqueueServerToAgentResponse(new ServerToAgent.Builder().build());
257267
client.setRemoteConfigStatus(remoteConfigStatus);
258-
assertThat(takeRequest()).isNotNull();
268+
RecordedRequest firstRequest = takeRequest();
269+
System.out.println("DEBUG: First request result: " + (firstRequest != null));
270+
assertThat(firstRequest).isNotNull();
259271

260272
// Ignore when the provided value is the same as the current one
273+
System.out.println("DEBUG: Setting same remote config status and expecting no request...");
261274
enqueueServerToAgentResponse(new ServerToAgent.Builder().build());
262275
client.setRemoteConfigStatus(remoteConfigStatus);
263-
assertThat(takeRequest()).isNull();
276+
RecordedRequest secondRequest = takeRequest();
277+
System.out.println("DEBUG: Second request result: " + (secondRequest != null));
278+
assertThat(secondRequest).isNull();
279+
System.out.println("DEBUG: verifyRemoteConfigStatusSetter test completed");
264280
}
265281

266282
@Test
267283
void onConnectionSuccessful_notifyCallback() {
268284
initializeClient();
269285

270-
await().atMost(Duration.ofSeconds(1)).until(() -> callbacks.onConnectCalls.get() == 1);
286+
await().atMost(Duration.ofSeconds(5)).until(() -> callbacks.onConnectCalls.get() == 1);
271287

272288
verify(callbacks).onConnect();
273289
verify(callbacks, never()).onConnectFailed(any());
274290
}
275291

276292
@Test
277293
void onFailedResponse_keepFieldsForNextRequest() {
294+
System.out.println("DEBUG: Starting onFailedResponse_keepFieldsForNextRequest test");
278295
initializeClient();
279296

280297
// Mock failed request
@@ -283,22 +300,35 @@ void onFailedResponse_keepFieldsForNextRequest() {
283300
// Adding a non-constant field
284301
AgentDescription agentDescription =
285302
getAgentDescriptionWithOneIdentifyingValue("service.namespace", "something");
303+
System.out.println("DEBUG: Setting agent description and expecting first request...");
286304
client.setAgentDescription(agentDescription);
287305

288306
// Assert first request contains it
289-
assertThat(getAgentToServerMessage(takeRequest()).agent_description)
307+
RecordedRequest firstRequest = takeRequest();
308+
System.out.println("DEBUG: First request agent_description: " +
309+
(getAgentToServerMessage(firstRequest).agent_description != null ? "present" : "null"));
310+
assertThat(getAgentToServerMessage(firstRequest).agent_description)
290311
.isEqualTo(agentDescription);
291312

292313
// Since it failed, send the agent description field in the next request
314+
System.out.println("DEBUG: Sending request after failure, expecting agent description to be kept...");
293315
enqueueServerToAgentResponse(new ServerToAgent.Builder().build());
294316
requestService.sendRequest();
295-
assertThat(getAgentToServerMessage(takeRequest()).agent_description)
317+
RecordedRequest secondRequest = takeRequest();
318+
System.out.println("DEBUG: Second request agent_description: " +
319+
(getAgentToServerMessage(secondRequest).agent_description != null ? "present" : "null"));
320+
assertThat(getAgentToServerMessage(secondRequest).agent_description)
296321
.isEqualTo(agentDescription);
297322

298323
// When there's no failure, do not keep it.
324+
System.out.println("DEBUG: Sending request after success, expecting agent description to be null...");
299325
enqueueServerToAgentResponse(new ServerToAgent.Builder().build());
300326
requestService.sendRequest();
301-
assertThat(getAgentToServerMessage(takeRequest()).agent_description).isNull();
327+
RecordedRequest thirdRequest = takeRequest();
328+
System.out.println("DEBUG: Third request agent_description: " +
329+
(getAgentToServerMessage(thirdRequest).agent_description != null ? "present" : "null"));
330+
assertThat(getAgentToServerMessage(thirdRequest).agent_description).isNull();
331+
System.out.println("DEBUG: onFailedResponse_keepFieldsForNextRequest test completed");
302332
}
303333

304334
@Test
@@ -311,7 +341,7 @@ void onFailedResponse_withServerErrorData_notifyCallback() {
311341
// Force request
312342
requestService.sendRequest();
313343

314-
await().atMost(Duration.ofSeconds(1)).until(() -> callbacks.onErrorResponseCalls.get() == 1);
344+
await().atMost(Duration.ofSeconds(5)).until(() -> callbacks.onErrorResponseCalls.get() == 1);
315345

316346
verify(callbacks).onErrorResponse(errorResponse);
317347
verify(callbacks, never()).onMessage(any());
@@ -344,7 +374,7 @@ void whenServerProvidesNewInstanceUid_useIt() {
344374
enqueueServerToAgentResponse(response);
345375
requestService.sendRequest();
346376

347-
await().atMost(Duration.ofSeconds(1)).until(() -> state.instanceUid.get() != initialUid);
377+
await().atMost(Duration.ofSeconds(5)).until(() -> state.instanceUid.get() != initialUid);
348378

349379
assertThat(state.instanceUid.get()).isEqualTo(serverProvidedUid);
350380
}
@@ -359,8 +389,12 @@ private static AgentToServer getAgentToServerMessage(RecordedRequest request) {
359389

360390
private RecordedRequest takeRequest() {
361391
try {
362-
return server.takeRequest(1, TimeUnit.SECONDS);
392+
System.out.println("DEBUG: Attempting to take request with 5 second timeout...");
393+
RecordedRequest request = server.takeRequest(5, TimeUnit.SECONDS);
394+
System.out.println("DEBUG: Request received: " + (request != null ? request.getRequestLine() : "null"));
395+
return request;
363396
} catch (InterruptedException e) {
397+
System.out.println("DEBUG: takeRequest interrupted");
364398
throw new RuntimeException(e);
365399
}
366400
}

0 commit comments

Comments
 (0)