Browse code

Use vol plugin creator instead of inserting spec

This makes the test a bit more robust to change and is a bit cleaner.
As implemented before this commit, we have two named plugins pointing to
the same http service. If the daemon makes any unexpected calls to the
plugin (e.g. during startup) we'll get more counts on the event counter
than expected since the daemon sees 2 plugins.

Found this while working on #29877 which broke this test originally (but
is no longer using V1 plugins, so is this is no longer broken there) and
took some time to debug what was going on.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2017/01/05 05:04:29
Showing 1 changed files
... ...
@@ -412,24 +412,23 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *
412 412
 
413 413
 func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverRetryNotImmediatelyExists(c *check.C) {
414 414
 	s.d.StartWithBusybox(c)
415
-
416
-	specPath := "/etc/docker/plugins/test-external-volume-driver-retry.spec"
417
-	os.RemoveAll(specPath)
418
-	defer os.RemoveAll(specPath)
415
+	driverName := "test-external-volume-driver-retry"
419 416
 
420 417
 	errchan := make(chan error)
418
+	started := make(chan struct{})
421 419
 	go func() {
422
-		if out, err := s.d.Cmd("run", "--rm", "--name", "test-data-retry", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", "test-external-volume-driver-retry", "busybox:latest"); err != nil {
420
+		close(started)
421
+		if out, err := s.d.Cmd("run", "--rm", "--name", "test-data-retry", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", driverName, "busybox:latest"); err != nil {
423 422
 			errchan <- fmt.Errorf("%v:\n%s", err, out)
424 423
 		}
425 424
 		close(errchan)
426 425
 	}()
427
-	go func() {
428
-		// wait for a retry to occur, then create spec to allow plugin to register
429
-		time.Sleep(2000 * time.Millisecond)
430
-		// no need to check for an error here since it will get picked up by the timeout later
431
-		ioutil.WriteFile(specPath, []byte(s.Server.URL), 0644)
432
-	}()
426
+
427
+	<-started
428
+	// wait for a retry to occur, then create spec to allow plugin to register
429
+	time.Sleep(2000 * time.Millisecond)
430
+	p := newVolumePlugin(c, driverName)
431
+	defer p.Close()
433 432
 
434 433
 	select {
435 434
 	case err := <-errchan:
... ...
@@ -441,11 +440,11 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverRetryNotImmediatelyE
441 441
 	_, err := s.d.Cmd("volume", "rm", "external-volume-test")
442 442
 	c.Assert(err, checker.IsNil)
443 443
 
444
-	c.Assert(s.ec.activations, checker.Equals, 1)
445
-	c.Assert(s.ec.creations, checker.Equals, 1)
446
-	c.Assert(s.ec.removals, checker.Equals, 1)
447
-	c.Assert(s.ec.mounts, checker.Equals, 1)
448
-	c.Assert(s.ec.unmounts, checker.Equals, 1)
444
+	c.Assert(p.ec.activations, checker.Equals, 1)
445
+	c.Assert(p.ec.creations, checker.Equals, 1)
446
+	c.Assert(p.ec.removals, checker.Equals, 1)
447
+	c.Assert(p.ec.mounts, checker.Equals, 1)
448
+	c.Assert(p.ec.unmounts, checker.Equals, 1)
449 449
 }
450 450
 
451 451
 func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c *check.C) {