Skip to content

Commit 242b37a

Browse files
committed
Improve SHM configuration
1 parent f2c3aef commit 242b37a

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 1.2.2
2+
* [Browser] Improve SHM configuration
3+
14
# 1.2.1
25
* Migrated deployment to _Sonatype Maven Central Portal_ [#155](https://github.com/xdev-software/standard-maven-template/issues/155)
36
* Updated dependencies

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public class BrowserWebDriverContainer<SELF extends BrowserWebDriverContainer<SE
8989

9090
protected static final String TC_TEMP_DIR_PREFIX = "tc";
9191

92+
protected static Boolean currentOsWindows; // You should use the method instead, this might be NULL
93+
9294
protected boolean mapTimezoneIntoContainer = true;
9395

9496
protected boolean validateImageEnabled = true;
@@ -280,19 +282,33 @@ protected void configureShm()
280282
{
281283
if(this.getShmSize() == null)
282284
{
283-
if(Optional.ofNullable(System.getProperty("os.name"))
284-
.map(osName -> osName.startsWith("Windows"))
285-
.orElse(false))
285+
if(this.shouldDirectMountShm())
286286
{
287-
this.withSharedMemorySize(512 * FileUtils.ONE_MB);
287+
this.getBinds().add(new Bind("/dev/shm", new Volume("/dev/shm"), AccessMode.rw));
288288
}
289289
else
290290
{
291-
this.getBinds().add(new Bind("/dev/shm", new Volume("/dev/shm"), AccessMode.rw));
291+
this.withSharedMemorySize(512 * FileUtils.ONE_MB);
292292
}
293293
}
294294
}
295295

296+
protected boolean shouldDirectMountShm()
297+
{
298+
return !isCurrentOsWindows();
299+
}
300+
301+
protected static boolean isCurrentOsWindows()
302+
{
303+
if(currentOsWindows == null)
304+
{
305+
currentOsWindows = Optional.ofNullable(System.getProperty("os.name"))
306+
.map(osName -> osName.startsWith("Windows"))
307+
.orElse(false);
308+
}
309+
return !currentOsWindows;
310+
}
311+
296312
protected void configureVNC()
297313
{
298314
if(this.disableVNC)

0 commit comments

Comments
 (0)