|
35 | 35 | import java.util.Optional;
|
36 | 36 | import java.util.concurrent.TimeUnit;
|
37 | 37 | import java.util.function.Function;
|
| 38 | +import java.util.function.Supplier; |
38 | 39 | import java.util.stream.Collectors;
|
39 | 40 | import java.util.stream.IntStream;
|
40 | 41 |
|
@@ -450,50 +451,56 @@ public void stop()
|
450 | 451 | @Override
|
451 | 452 | public void afterTest(final TestDescription description, final Optional<Throwable> throwable)
|
452 | 453 | {
|
453 |
| - this.retainRecordingIfNeeded(description.getFilesystemFriendlyName(), throwable.isEmpty()); |
| 454 | + this.retainRecordingIfNeeded(description::getFilesystemFriendlyName, throwable.isEmpty()); |
454 | 455 | }
|
455 | 456 |
|
456 |
| - protected void retainRecordingIfNeeded(final String testName, final boolean succeeded) |
| 457 | + protected void retainRecordingIfNeeded(final Supplier<String> testNameSupplier, final boolean succeeded) |
457 | 458 | {
|
| 459 | + // Should recording be retained? |
458 | 460 | if(switch(this.recordingMode)
|
459 | 461 | {
|
460 |
| - case RECORD_ALL -> true; |
461 |
| - case RECORD_FAILING -> !succeeded; |
462 |
| - default -> false; |
| 462 | + case RECORD_ALL -> false; |
| 463 | + case RECORD_FAILING -> succeeded; |
| 464 | + default -> true; |
463 | 465 | })
|
464 | 466 | {
|
465 |
| - if(this.beforeRecordingSaveWaitTime != null) |
466 |
| - { |
467 |
| - try |
468 |
| - { |
469 |
| - Thread.sleep(this.beforeRecordingSaveWaitTime.toMillis()); |
470 |
| - } |
471 |
| - catch(final InterruptedException e) |
472 |
| - { |
473 |
| - Thread.currentThread().interrupt(); |
474 |
| - throw new IllegalStateException("Got interrupted", e); |
475 |
| - } |
476 |
| - } |
| 467 | + return; |
| 468 | + } |
| 469 | + |
| 470 | + if(this.beforeRecordingSaveWaitTime != null) |
| 471 | + { |
477 | 472 | try
|
478 | 473 | {
|
479 |
| - final Path recording = Timeouts.getWithTimeout( |
480 |
| - (int)this.recordingSaveTimeout.toSeconds(), |
481 |
| - TimeUnit.SECONDS, |
482 |
| - () -> this.recordingContainer.saveRecordingToFile( |
483 |
| - this.recordingDirectory, |
484 |
| - this.testRecordingFileNameFactory.buildNameWithoutExtension(testName, succeeded)) |
485 |
| - ); |
486 |
| - LOG.info("Screen recordings for test {} will be stored at: {}", testName, recording); |
| 474 | + Thread.sleep(this.beforeRecordingSaveWaitTime.toMillis()); |
487 | 475 | }
|
488 |
| - catch(final org.rnorth.ducttape.TimeoutException te) |
| 476 | + catch(final InterruptedException e) |
489 | 477 | {
|
490 |
| - LOG.warn("Timed out while saving recording for test {}", testName, te); |
491 |
| - } |
492 |
| - catch(final Exception ex) |
493 |
| - { |
494 |
| - LOG.warn("Failed to save recording for test {}", testName, ex); |
| 478 | + Thread.currentThread().interrupt(); |
| 479 | + throw new IllegalStateException("Got interrupted", e); |
495 | 480 | }
|
496 | 481 | }
|
| 482 | + |
| 483 | + // Get testname only when required to improve performance |
| 484 | + final String testName = testNameSupplier.get(); |
| 485 | + try |
| 486 | + { |
| 487 | + final Path recording = Timeouts.getWithTimeout( |
| 488 | + (int)this.recordingSaveTimeout.toSeconds(), |
| 489 | + TimeUnit.SECONDS, |
| 490 | + () -> this.recordingContainer.saveRecordingToFile( |
| 491 | + this.recordingDirectory, |
| 492 | + this.testRecordingFileNameFactory.buildNameWithoutExtension(testName, succeeded)) |
| 493 | + ); |
| 494 | + LOG.info("Screen recordings for test {} will be stored at: {}", testName, recording); |
| 495 | + } |
| 496 | + catch(final org.rnorth.ducttape.TimeoutException te) |
| 497 | + { |
| 498 | + LOG.warn("Timed out while saving recording for test {}", testName, te); |
| 499 | + } |
| 500 | + catch(final Exception ex) |
| 501 | + { |
| 502 | + LOG.warn("Failed to save recording for test {}", testName, ex); |
| 503 | + } |
497 | 504 | }
|
498 | 505 |
|
499 | 506 | @Override
|
|
0 commit comments