Skip to content

Commit

Permalink
Try to improve listLogsTest resilience (#627)
Browse files Browse the repository at this point in the history
Copy the changes made to listLogsGetTest
  • Loading branch information
therve authored Jan 27, 2021
1 parent 2889d6f commit 6b45134
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions src/test/java/com/datadog/api/v2/client/api/LogsApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,43 @@ public void listLogsTest() throws Exception {
}
});

// Sort works correctly
LogsListResponse responseAscending = api.listLogs()
.body(new LogsListRequest()
.filter(allLogsFilter)
.sort(LogsSort.TIMESTAMP_ASCENDING))
.execute();
AtomicReference<LogsListResponse> responseAscending = new AtomicReference<>();

assertEquals(2, responseAscending.getData().size());
assertEquals("test-log-list " + suffix, responseAscending.getData().get(0).getAttributes().getMessage());
assertEquals("test-log-list-2 " + suffix, responseAscending.getData().get(1).getAttributes().getMessage());
TestUtils.retry(5, 10, () -> {
try {
// Sort works correctly
responseAscending.set(api.listLogs()
.body(new LogsListRequest()
.filter(allLogsFilter)
.sort(LogsSort.TIMESTAMP_ASCENDING))
.execute());
return responseAscending.get().getData() != null && responseAscending.get().getData().size() == 2;
} catch (ApiException ignored) {
return false;
}
});

LogsListResponse responseDescending = api.listLogs()
.body(new LogsListRequest()
.filter(allLogsFilter)
.sort(LogsSort.TIMESTAMP_DESCENDING))
.execute();
assertEquals(2, responseAscending.get().getData().size());
assertEquals("test-log-list " + suffix, responseAscending.get().getData().get(0).getAttributes().getMessage());
assertEquals("test-log-list-2 " + suffix, responseAscending.get().getData().get(1).getAttributes().getMessage());

AtomicReference<LogsListResponse> responseDescending = new AtomicReference<>();
TestUtils.retry(5, 10, () -> {
try {
responseDescending.set(api.listLogs()
.body(new LogsListRequest()
.filter(allLogsFilter)
.sort(LogsSort.TIMESTAMP_DESCENDING))
.execute());
return responseDescending.get().getData() != null && responseDescending.get().getData().size() == 2;
} catch (ApiException ignored) {
return false;
}
});

assertEquals(2, responseDescending.getData().size());
assertEquals("test-log-list-2 " + suffix, responseDescending.getData().get(0).getAttributes().getMessage());
assertEquals("test-log-list " + suffix, responseDescending.getData().get(1).getAttributes().getMessage());
assertEquals(2, responseDescending.get().getData().size());
assertEquals("test-log-list-2 " + suffix, responseDescending.get().getData().get(0).getAttributes().getMessage());
assertEquals("test-log-list " + suffix, responseDescending.get().getData().get(1).getAttributes().getMessage());

// Paging
LogsListResponse pageOneResponse = api.listLogs()
Expand Down

0 comments on commit 6b45134

Please sign in to comment.