1

Hi, all

In our project we have one persistent problem - our UI tests very flaky and dependent on machine resources. Sometimes tests passed perfect, sometimes fails, even when memory usage is low.

Main reason - selenium/standalone-chrome container is dropping in the middle of execution.

Our approximate docker configuration (docker-compose file):

    version: "2.3"
    services:
      tests:
        mem_limit: 1500m
        memswap_limit: 3g
        oom_score_adj: -500
        extends:
          file: docker-compose.build.yml
          service: jdk-mvn
        depends_on:
          - selenium
        environment:
          - SELENIUM_PORT_4444_TCP_ADDR=selenium
          - SELENIUM_PORT_4444_TCP_PORT=4444
        command: >
          sh -c "mvn -B -U clean install -DskipTests -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
          && mvn -B test -pl module -Pprofile -Denvironment=staging -Dbrowser.type=REMOTE_CHROME_LINUX"
    
      selenium:
        container_name: selenium
        image: selenium/standalone-chrome:3.141.59
        shm_size: '2gb'
        mem_limit: 1100m
        memswap_limit: 4g
        oom_score_adj: -1000
        oom_kill_disable: true
        expose:
          - 4444

Tests is running by maven command from tests container. We use several forks (3-4) for parallel execution via maven-surefire-plugin, so tests is running in several JVMs.

Often we get such error:

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: '58877d6015f7', ip: '172.23.0.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-1128-aws', java.version: '11.0.4'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [009beb8f09ce87a15690dd3cbe53ca77, getAlertText {}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 86.0.4240.75, chrome: {chromedriverVersion: 86.0.4240.22 (398b0743353ff..., userDataDir: /tmp/.com.google.Chrome.W5uYnf}, goog:chromeOptions: {debuggerAddress: localhost:44673}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true, webdriver.remote.sessionid: 009beb8f09ce87a15690dd3cbe5...}
Session ID: 009beb8f09ce87a15690dd3cbe53ca77
...
Caused by: java.io.UncheckedIOException: java.net.UnknownHostException: selenium: Try again

Line

java.net.UnknownHostException: selenium: Try again

means that selenium container was dropped.

All this options: shm-size, mem_limit etc. was added to improve somehow current situation. It helped, nut not so much. Even if we prevent container itself from dropping, browser sessions inside container start dropping.

In general, question is: how to improve this situation? I mean, any points are appreciated: docker, selenium settings, JVM argument, code refactoring to reduce memory usage etc. Main, but not only point of this issue seems to be limited machine resources

IvanMikhalka
  • 184
  • 10
  • 1
    If you run 3-4 parallel threads, you have to set `shm_size: '6gb' ` \ `shm_size: '8gb'` based on this doc. ​https://github.com/SeleniumHQ/docker-selenium#--shm-size2g, try this, (but I'm not sure). Also available CPUs cout matters. At least 0.5 CPU per browser. – Max Daroshchanka Feb 02 '22 at 19:13
  • @MaxDaroshchanka thank you, I didn't notice that `shm_size: '2gb'` is only for single thread. Start testing, and now it looks good, I want test several times to assume, so, maybe, our 2-years issue will be resolved. I hope so be that and appreciate your comment – IvanMikhalka Feb 03 '22 at 08:11
  • Let me know if it helped, I'll move the comment to the answer if it really works. Since this might be useful also for someone else. – Max Daroshchanka Feb 03 '22 at 10:57
  • @MaxDaroshchanka I guess you could. I've tested several most heavyweight suites with any crashes. Also I increased mem_limit: `mem_limit: 2500m` – IvanMikhalka Feb 03 '22 at 11:03
  • Oh, I see it marked as duplicated and not accepting answers any more, but great that it helped you. Good luck! – Max Daroshchanka Feb 03 '22 at 11:07

0 Answers0