Skip to content

Commit c1683fe

Browse files
committed
Only compute name for recording when required
1 parent 9b3f6c1 commit c1683fe

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* If not ``null``: Waits the amount of specified time before saving the recording
44
* This way no frames that may show the problem are accidentally lost
55
* Default value is set to ``70ms`` which is 1 full frame when recording at the default 15 FPS
6+
* Only compute name for recording when required
67

78
# 1.2.3
89
* Make some constants externally accessible

testcontainers-selenium/src/main/java/software/xdev/testcontainers/selenium/containers/browser/BrowserWebDriverContainer.java

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.Optional;
3636
import java.util.concurrent.TimeUnit;
3737
import java.util.function.Function;
38+
import java.util.function.Supplier;
3839
import java.util.stream.Collectors;
3940
import java.util.stream.IntStream;
4041

@@ -450,50 +451,56 @@ public void stop()
450451
@Override
451452
public void afterTest(final TestDescription description, final Optional<Throwable> throwable)
452453
{
453-
this.retainRecordingIfNeeded(description.getFilesystemFriendlyName(), throwable.isEmpty());
454+
this.retainRecordingIfNeeded(description::getFilesystemFriendlyName, throwable.isEmpty());
454455
}
455456

456-
protected void retainRecordingIfNeeded(final String testName, final boolean succeeded)
457+
protected void retainRecordingIfNeeded(final Supplier<String> testNameSupplier, final boolean succeeded)
457458
{
459+
// Should recording be retained?
458460
if(switch(this.recordingMode)
459461
{
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;
463465
})
464466
{
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+
{
477472
try
478473
{
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());
487475
}
488-
catch(final org.rnorth.ducttape.TimeoutException te)
476+
catch(final InterruptedException e)
489477
{
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);
495480
}
496481
}
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+
}
497504
}
498505

499506
@Override

0 commit comments

Comments
 (0)