@@ -20,12 +20,15 @@ import (
2020)
2121
2222const (
23- CONTAINER_STATE_CHANGE_TIMEOUT = time .Second * 15
24- DOCKER_STATE_CHANGE_TIMEOUT = time .Second * 5
25- SYSTEMD_ACTION_DELAY = time .Second * 1
26- CONTAINER_CHECK_INTERVAL = time .Second / 20
27- TestImage = "pmorie/sti-html-app"
28- EnvImage = "ccoleman/envtest"
23+ TimeoutContainerStateChange = time .Second * 15
24+ TimeoutDockerStateChange = time .Second * 5
25+ TimeoutDockerWait = time .Second * 2
26+
27+ IntervalContainerCheck = time .Second / 20
28+ IntervalHttpCheck = time .Second / 10
29+
30+ TestImage = "pmorie/sti-html-app"
31+ EnvImage = "ccoleman/envtest"
2932)
3033
3134//Hookup gocheck with go test
@@ -72,7 +75,10 @@ func (s *IntegrationTestSuite) assertFileAbsent(c *chk.C, path string) {
7275}
7376
7477func (s * IntegrationTestSuite ) getContainerPid (id containers.Identifier ) int {
75- container , _ := s .dockerClient .GetContainer (id .ContainerFor (), true )
78+ container , err := s .dockerClient .InspectContainer (id .ContainerFor ())
79+ if err != nil {
80+ return 0
81+ }
7682 return container .State .Pid
7783}
7884
@@ -164,7 +170,7 @@ func (s *IntegrationTestSuite) assertContainerStarts(c *chk.C, id containers.Ide
164170 return false
165171 }
166172
167- if ! until (CONTAINER_STATE_CHANGE_TIMEOUT , time .Second / 20 , isRunning ) {
173+ if ! until (TimeoutContainerStateChange , time .Second / 20 , isRunning ) {
168174 c .Errorf ("Timeout during start of %s, never got to 'active' state" , id )
169175 c .FailNow ()
170176 }
@@ -182,7 +188,7 @@ func (s *IntegrationTestSuite) assertContainerStarts(c *chk.C, id containers.Ide
182188 return done
183189 }
184190
185- if ! until (time . Second * 2 , time . Second / 10 , isContainerUp ) {
191+ if ! until (TimeoutDockerWait , IntervalHttpCheck , isContainerUp ) {
186192 if ! failed {
187193 c .Errorf ("Docker never reported the container running %s" , id )
188194 }
@@ -215,12 +221,12 @@ func (s *IntegrationTestSuite) assertContainerStops(c *chk.C, id containers.Iden
215221 return false
216222 }
217223
218- if ! until (CONTAINER_STATE_CHANGE_TIMEOUT , CONTAINER_CHECK_INTERVAL , isStopped ) {
224+ if ! until (TimeoutContainerStateChange , IntervalContainerCheck , isStopped ) {
219225 c .Errorf ("Timeout during start of %s, never got to 'inactive' state" , id )
220226 c .FailNow ()
221227 }
222228
223- _ , err := s .dockerClient .GetContainer (id .ContainerFor (), false )
229+ _ , err := s .dockerClient .InspectContainer (id .ContainerFor ())
224230 if err == nil {
225231 c .Errorf ("Container %s is still active in docker, should be stopped and removed" , id .ContainerFor ())
226232 c .FailNow ()
@@ -241,7 +247,7 @@ func (s *IntegrationTestSuite) assertContainerRestarts(c *chk.C, id containers.I
241247 return false
242248 }
243249
244- if ! until (CONTAINER_STATE_CHANGE_TIMEOUT , CONTAINER_CHECK_INTERVAL , isStarted ) {
250+ if ! until (TimeoutContainerStateChange , IntervalContainerCheck , isStarted ) {
245251 active , sub := s .unitState (id )
246252 c .Errorf ("Timeout during restart of %s, never got back to 'active' state (%s/%s)" , id , active , sub )
247253 c .FailNow ()
@@ -260,7 +266,7 @@ func (s *IntegrationTestSuite) assertContainerRestarts(c *chk.C, id containers.I
260266 return done
261267 }
262268
263- if ! until (time . Second * 2 , time . Second / 10 , isContainerUp ) {
269+ if ! until (TimeoutDockerWait , IntervalHttpCheck , isContainerUp ) {
264270 if ! failed {
265271 c .Errorf ("Docker never reported the container running %s" , id )
266272 }
@@ -291,7 +297,7 @@ func (s *IntegrationTestSuite) SetUpSuite(c *chk.C) {
291297 containers , err := s .dockerClient .ListContainers ()
292298 c .Assert (err , chk .IsNil )
293299 for _ , cinfo := range containers {
294- container , err := s .dockerClient .GetContainer (cinfo .ID , false )
300+ container , err := s .dockerClient .InspectContainer (cinfo .ID )
295301 c .Assert (err , chk .IsNil )
296302 if strings .HasPrefix (container .Name , "IntTest" ) {
297303 s .dockerClient .ForceCleanContainer (cinfo .ID )
@@ -366,7 +372,6 @@ func (s *IntegrationTestSuite) TestSimpleInstallWithEnv(c *chk.C) {
366372 c .Log (string (data ))
367373 c .Assert (err , chk .IsNil )
368374 s .assertContainerStarts (c , id )
369- //time.Sleep(time.Second * 5) // startup time is indeterminate unfortunately because gear init --post continues to run
370375
371376 cmd = exec .Command ("/usr/bin/gear" , "status" , hostContainerId )
372377 data , err = cmd .CombinedOutput ()
@@ -409,7 +414,7 @@ func (s *IntegrationTestSuite) TestIsolateInstallAndStartImage(c *chk.C) {
409414 }
410415 return false
411416 }
412- if ! until (time . Second * 15 , time . Second / 10 , httpAlive ) {
417+ if ! until (TimeoutContainerStateChange , IntervalHttpCheck , httpAlive ) {
413418 c .Errorf ("Unable to retrieve a 200 status code from port %d" , ports [0 ].External )
414419 c .FailNow ()
415420 }
@@ -469,7 +474,7 @@ func (s *IntegrationTestSuite) TestStartStopContainer(c *chk.C) {
469474 }
470475 return false
471476 }
472- if ! until (time . Second * 15 , time . Second / 10 , httpAlive ) {
477+ if ! until (TimeoutContainerStateChange , IntervalHttpCheck , httpAlive ) {
473478 c .Errorf ("Unable to retrieve a 200 status code from port %d" , ports [0 ].External )
474479 c .FailNow ()
475480 }
@@ -584,7 +589,7 @@ func (s *IntegrationTestSuite) TestLongContainerName(c *chk.C) {
584589 }
585590 return false
586591 }
587- if ! until (time . Second * 15 , time . Second / 10 , httpAlive ) {
592+ if ! until (TimeoutContainerStateChange , IntervalHttpCheck , httpAlive ) {
588593 c .Errorf ("Unable to retrieve a 200 status code from port %d" , ports [0 ].External )
589594 c .FailNow ()
590595 }
@@ -619,51 +624,6 @@ func (s *IntegrationTestSuite) TestContainerNetLinks(c *chk.C) {
619624 c .Assert (strings .Contains (string (data ), "tcp dpt:tproxy to:74.125.239.114" ), chk .Equals , true )
620625}
621626
622- // func (s *IntegrationTestSuite) TestSocketActivatedInstallAndStartImage(c *chk.C) {
623- // id, err := containers.NewIdentifier("IntTest007")
624- // c.Assert(err, chk.IsNil)
625- // s.containerIds = append(s.containerIds, id)
626- //
627- // hostContainerId := fmt.Sprintf("%v/%v", s.daemonURI, id)
628- //
629- // cmd := exec.Command("/usr/bin/gear", "install", "pmorie/sti-html-app", hostContainerId, "--start", "--ports=8080:4005", "--socket-activated")
630- // data, err := cmd.CombinedOutput()
631- // c.Log(string(data))
632- // c.Assert(err, chk.IsNil)
633- //
634- // s.assertFilePresent(c, id.UnitPathFor(), 0664, true)
635- // paths, err := filepath.Glob(id.VersionedUnitPathFor("*"))
636- // c.Assert(err, chk.IsNil)
637- // for _, p := range paths {
638- // s.assertFilePresent(c, p, 0664, true)
639- // }
640- //
641- // ports, err := containers.GetExistingPorts(id)
642- // c.Assert(err, chk.IsNil)
643- // c.Assert(len(ports), chk.Equals, 1)
644- //
645- // t := time.NewTicker(time.Second/10)
646- // defer t.Stop()
647- // for true {
648- // select {
649- // case <-t.C:
650- // resp, err := http.Get(fmt.Sprintf("http://0.0.0.0:%v", ports[0].External))
651- // if err == nil {
652- // c.Logf("attempting http .. response code %v", resp.StatusCode)
653- // if resp.StatusCode == 200 {
654- // break
655- // }
656- // }else{
657- // c.Logf("attempting http .. error %v", err)
658- // }
659- // case <-time.After(time.Second * 15):
660- // c.Fail()
661- // }
662- // }
663- // s.assertFilePresent(c, filepath.Join(id.RunPathFor(), "container-init.sh"), 0700, false)
664- // s.assertContainerState(c, id, CONTAINER_STARTED)
665- // }
666-
667627func (s * IntegrationTestSuite ) TearDownSuite (c * chk.C ) {
668628 for _ , id := range s .containerIds {
669629 hostContainerId := fmt .Sprintf ("%v/%v" , s .daemonURI , id )
0 commit comments