Yelp/fig — pull request #3 by dnephin (2014-08-24 19:29:44+00:00)
Title: Do less work during integration testing.

From https://github.com/docker/fig/pull/439

After running the integration test suite many times it seemed unusually slow. Running it on a jenkins host takes close to an hour, (on my desktop it's just over 2min).

I ran the suite with profiling enabled and noticed a few things that seemed like low hanging fruit. After these changes the test suite ran on my desktop in ~112s, so it's almost 10% off. I believe the savings on the jenkins host may actually be a lot greater because the time spent doing `Service.containers` and filtering them actually increases as the number of containers increases. So a host with lots of containers will see a lot faster test runs.

Primary changes:
* Don't `docker pull busybox` on every integration test class. At most this only has to be done once as part of the `tox.ini`/`.travis.yml`. fig already does this pull for us, so I think it's somewhat unnecessary (unless we really care about updates, but it seems like we shouldn't).
* `Service._next_container_name` calls `self.containers()` on every call, but most of the time this is duplicated work (it was just called and all the containers were already filtered). Since this is only called from inside the `Service` class itself, it seems safe enough to modify the interface and make it private. This will actually improve the performance of `fig` itself as well on any host with many containers.

Secondary changes:
* Don't modify the class under test in the `Service` unit test suite. Instead mock out a dependency
* use a namedtuple for the service name tuple, which lets us remove some indexing into tuples with a more readable attribute