Skip to content

Containers are not stopped on OSX #253

Closed

Description

@pavelpp

System: OSX 10.10.5
Tried with latest docker-machine and Docker for Mac
TC version 1.1.7

HW:
Model Name: MacBook Pro
Model Identifier: MacBookPro11,5
Processor Name: Intel Core i7
Processor Speed: 2,5 GHz
Number of Processors: 1
Total Number of Cores: 4
L2 Cache (per Core): 256 KB
L3 Cache: 6 MB
Memory: 16 GB

Problem: When running parallel selenium tests with gradle (4 forks), sometimes tests leave containers running even though in shutdown hooks I do stop them. Mostly the problem happens with BrowserWebDriverContainer, but sometimes other GenericContainer's are showing the same behaviour. The problem can't be reproduced when single tests are run, so it's kind of difficult to debug. Only when I run all tests in parallel "ghost" browser containers start piling up after 5 minutes or so and I have to kill them manually from command line (if I don't them my tests will start failing and new containers fail to start). I know this is a very vague way to report a problem, but maybe someone can give me a hint on where to start with debugging. At this point I'm stuck and out of ideas.

docker info:
Containers: 7
Running: 7
Paused: 0
Stopped: 0
Images: 11
Server Version: 1.12.4-rc1
Storage Driver: aufs
Root Dir: /mnt/sda1/var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 107
Dirperm1 Supported: true
Logging Driver: json-file
Plugins:
Volume: local
Network: null bridge host overlay
Kernel Version: 4.4.36-boot2docker
Operating System: Boot2Docker 1.12.4-rc1 (TCL 7.2); HEAD : 2a30a73 - Thu Dec 8 18:24:06 UTC 2016
OSType: linux
Architecture: x86_64
CPUs: 7
Total Memory: 7.789 GiB
Name: default
ID: HPQP:JBG2:NSWF:IUFQ:5QTM:CMOY:WQK5:OSKY:OBTV:ZIKS:T5AD:FVSA
Debug mode (server): true
File Descriptors: 63
Goroutines: 57
System Time: 2016-12-09T20:26:44.574994251Z
EventsListeners: 0
Init SHA1:
Init Path:
Docker Root Dir: /mnt/sda1/var/lib/docker
Labels:
provider=virtualbox

Activity

  1. rnorth commented on Dec 9, 2016

    @rnorth
    Member
  2. pavelpp commented on Dec 9, 2016

    @pavelpp
    ContributorAuthor

    These are forked JVM's. Tests are started like this:

    test {
        includes = [
                "zt/selenium/junit/*Test.class",
                "Scenario*"
        ]
    
        maxParallelForks 4
    
        testLogging {
            displayGranularity 1
            events "PASSED", "FAILED", "SKIPPED"
            showStandardStreams true
            exceptionFormat = 'full'
        }
    
        afterTest {
            System.out.println()
        }
    

    Can't really share the repo. Logs - will try to get.

  3. pavelpp commented on Dec 10, 2016

    @pavelpp
    ContributorAuthor

    I noticed timezone is incorrect in my browser container. Is there a way to set correct timezone via testcontainers?

  4. bsideup commented on Dec 10, 2016

    @bsideup
    Member

    @rnorth this is my colleague, I'll try to debug his project since I have an access to the project:)

    Maybe you have some ideas what to check?

    FYI: the project is based on Cucumber, all container management is done manually (not with JUnit rules), I suspect it to be an issue.

  5. rnorth commented on Dec 10, 2016

    @rnorth
    Member
  6. pavelpp commented on Dec 10, 2016

    @pavelpp
    ContributorAuthor

    @after("@web")
    cleanup method is invoked after every scenario with tag @web. I suspect that the problem might be in how container is started. Is it possible that start() method somehow starts two copies of the container, thus stop() method will only stop the last copy? I'm not getting any errors when stopping containers.

    Yesterday experimented with this instead of calling stop():

        public void forceKill(String containerId) {
            try {
                DockerClientFactory.instance().client().removeContainerCmd(containerId).withForce(Boolean.TRUE).exec();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    

    same result. No change, so my only theory is that sometimes two browser containers are started with one start() method, leaving one of them orphaned, until all tests finish running

  7. pavelpp commented on Dec 11, 2016

    @pavelpp
    ContributorAuthor

    Regarding timezones. I did not set any timezone myself, maybe that was the issue, but it's not documented anywhere. I've added browserContainer.withEnv("TZ", "Europe/Helsinki") and now time seems to be correct.

  8. pavelpp commented on Dec 12, 2016

    @pavelpp
    ContributorAuthor

    Case closed. Problem with orphaned containers boiled down to me not calling driver.quit() before stopping container. Still don't quite understand why this is necessary though.

  9. rnorth commented on Dec 12, 2016

    @rnorth
    Member
  10. pavelpp commented on Dec 12, 2016

    @pavelpp
    ContributorAuthor

    After further investigation I still face the issue. Tracked the problem down to simultaneous initialization of browser in several parallel tests. Sometimes (randomly) one of the started instances is not going the usual route (I rename containers at start, adding "browser" prefix). And for some reason this very container it is not getting stopped after test is over. As I have lots of tests and each of them starts new browser container, during an hour or so such orphaned containers keep piling up. I've run the same sub-set of tests multiple times and sometimes they create containers as expected - sometimes not. It's random, but I suspect it has something to do with timing of browser container creation.

    $ docker ps
    CONTAINER ID        IMAGE                                           COMMAND                  CREATED             STATUS              PORTS                                              NAMES
    e1e309c3ee18        selenium/standalone-chrome-debug:3.0.1-barium   "/opt/bin/entry_point"   14 seconds ago      Up 12 seconds           0.0.0.0:33077->4444/tcp, 0.0.0.0:33076->5900/tcp   browser_awesome_babbage
    69b73e2ebf15        selenium/standalone-chrome-debug:3.0.1-barium   "/opt/bin/entry_point"   14 seconds ago      Up 13 seconds           0.0.0.0:33075->4444/tcp, 0.0.0.0:33074->5900/tcp   admiring_poincare
    

    This is how I create container:

    import org.jetbrains.annotations.NotNull;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.testcontainers.containers.BrowserWebDriverContainer;
    import org.testcontainers.images.RemoteDockerImage;
    
    import java.time.Duration;
    
    public class BrowserContainerProvider {
    
        @NotNull
        public static BrowserWebDriverContainer getBrowserWebDriverContainer() {
            return new BrowserWebDriverContainer() {
                @Override
                protected void configure() {
                    super.configure();
                    withStartupAttempts(5);
                    withStartupTimeout(Duration.ofMinutes(5));
                    withDesiredCapabilities(DesiredCapabilities.chrome());
                }
    
                @Override
                public String getDockerImageName() {
                    setImage(new RemoteDockerImage("selenium/standalone-chrome-debug:3.0.1-barium"));
                    return super.getDockerImageName();
                }
            };
        }
    }
    

    Am I doing it wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions