|
33 | 33 | import static java.lang.Integer.parseInt; |
34 | 34 | import static org.junit.Assert.assertEquals; |
35 | 35 | import static org.junit.Assert.fail; |
| 36 | +import static org.labkey.test.WebDriverWrapper.WAIT_FOR_JAVASCRIPT; |
| 37 | +import static org.labkey.test.WebDriverWrapper.waitFor; |
36 | 38 |
|
37 | 39 | public class AuditLogHelper |
38 | 40 | { |
@@ -232,10 +234,39 @@ public void checkAuditEventDiffCount(String containerPath, AuditEvent auditEvent |
232 | 234 | } |
233 | 235 | } |
234 | 236 |
|
235 | | - public Integer getLastTransactionId(String containerPath, AuditEvent auditEventName) throws IOException, CommandException |
| 237 | + public Integer getLastTransactionId(String containerPath, AuditEvent auditEventName) |
236 | 238 | { |
237 | | - List<Map<String, Object>> events = getAuditLogsFromLKS(containerPath, auditEventName, List.of("TransactionId"), Collections.emptyList(), 1, ContainerFilter.CurrentAndSubfolders).getRows(); |
238 | | - return events.size() == 1 ? (Integer) events.get(0).get("TransactionId") : null; |
| 239 | + try |
| 240 | + { |
| 241 | + List<Map<String, Object>> events = getAuditLogsFromLKS(containerPath, auditEventName, List.of("TransactionId"), Collections.emptyList(), 1, ContainerFilter.CurrentAndSubfolders).getRows(); |
| 242 | + return events.size() == 1 ? (Integer) events.get(0).get("TransactionId") : null; |
| 243 | + } |
| 244 | + catch (Exception e) |
| 245 | + { |
| 246 | + throw new RuntimeException(e); |
| 247 | + } |
| 248 | + } |
| 249 | + |
| 250 | + public Integer doAndWaitForTransaction(Runnable action, String containerPath, AuditEvent auditEventName) |
| 251 | + { |
| 252 | + int prevTransactionId; |
| 253 | + if (action != null) |
| 254 | + { |
| 255 | + prevTransactionId = Objects.requireNonNullElse(getLastTransactionId(containerPath, auditEventName), -1); |
| 256 | + action.run(); |
| 257 | + } |
| 258 | + else |
| 259 | + { |
| 260 | + prevTransactionId = -1; |
| 261 | + } |
| 262 | + |
| 263 | + return waitFor(() -> { |
| 264 | + Integer transactionId = getLastTransactionId(containerPath, auditEventName); |
| 265 | + if (transactionId != null && transactionId > prevTransactionId) |
| 266 | + return transactionId; |
| 267 | + else |
| 268 | + return null; |
| 269 | + }, "Error waiting for next transactionId in " + auditEventName, WAIT_FOR_JAVASCRIPT); |
239 | 270 | } |
240 | 271 |
|
241 | 272 | /** |
|
0 commit comments