defer GinkgoRecover()

					pid, err := pdr.Pid(pidFilePath)
					Expect(err).NotTo(HaveOccurred())
					Expect(pid).To(Equal(5621))

					close(pidReturns)
				}()

				// WaitForWatchersAndIncrement ensures that the implementation will try
				// first time and sleep. However the sleep interval is 20ms so
				// incrementing by 10ms won't get the loop moving. We do that to ensure
				// that the file write will happen before the implementation tries to
				// read the file. Hence, after we write the file the clock is
				// incremented by a further 10ms.
				clk.WaitForWatcherAndIncrement(time.Millisecond * 10)
				Expect(ioutil.WriteFile(pidFilePath, []byte("5621"), 0766)).To(Succeed())
				clk.Increment(time.Millisecond * 10)

				Eventually(pidReturns).Should(BeClosed())
				close(done)
			}, 1.0)
		})

		Context("and it is never created", func() {
			It("should return error after the timeout", func(done Done) {
				pidReturns := make(chan struct{})
				go func() {
					defer GinkgoRecover()

					_, err := pdr.Pid(pidFilePath)
			callback = func() error {
				called <- true

				callbackCount++
				if callbackCount == 6 {
					return nil
				}

				return errors.New("acaboom")
			}
		})

		It("should honor the polling interval", func(done Done) {
			finished := make(chan struct{})
			go func(ret *retrier.Retrier) {
				defer GinkgoRecover()
				Expect(ret.Retry(callback)).To(Succeed())
				close(finished)
			}(ret)

			for i := 0; i < 5; i++ {
				Eventually(called).Should(Receive())
				fakeClk.WaitForWatcherAndIncrement(pollingInterval)
			}

			Eventually(finished).Should(BeClosed())
			close(done)
		}, 1.0)
	})
})
	Describe("WaitForWatcherAndIncrement", func() {
		It("consistently fires timers that start asynchronously", func() {
			received := make(chan time.Time)

			stop := make(chan struct{})
			defer close(stop)

			duration := 10 * time.Second

			go func() {
				for {
					timer := fakeClock.NewTimer(duration)

					select {
					case ticked := <-timer.C():
						received <- ticked
					case <-stop:
						return
					}
				}
			}()

			for i := 0; i < 100; i++ {
				fakeClock.WaitForWatcherAndIncrement(duration)
				Expect((<-received).Sub(initialTime)).To(Equal(duration * time.Duration(i+1)))
			}
		})
	})
})
Beispiel #4
0
			lagertest.NewTestLogger("test"),
			fakeBaggageCollector,
			fakeDB,
			fakeClock,
			interval,
		))
	})

	AfterEach(func() {
		process.Signal(os.Interrupt)
		Expect(<-process.Wait()).ToNot(HaveOccurred())
	})

	Context("when the interval elapses", func() {
		JustBeforeEach(func() {
			fakeClock.WaitForWatcherAndIncrement(interval)
		})

		It("calls to get a lease for cache invalidation", func() {
			Eventually(fakeDB.LeaseCacheInvalidationCallCount).Should(Equal(1))
			actualInterval := fakeDB.LeaseCacheInvalidationArgsForCall(0)
			Expect(actualInterval).To(Equal(interval))
		})

		Context("when getting a lease succeeds", func() {
			BeforeEach(func() {
				fakeDB.LeaseCacheInvalidationReturns(fakeLease, true, nil)
			})

			It("it collects lost baggage", func() {
				Eventually(fakeBaggageCollector.CollectCallCount).Should(Equal(1))
Beispiel #5
0
			})

			It("does not check", func() {
				Consistently(times).ShouldNot(Receive())
			})
		})

		Context("when the lease can be acquired", func() {
			BeforeEach(func() {
				fakeRadarDB.LeaseResourceCheckingReturns(fakeLease, true, nil)
			})

			It("checks immediately and then on a specified interval", func() {
				Expect(<-times).To(Equal(epoch))

				fakeClock.WaitForWatcherAndIncrement(interval)
				Expect(<-times).To(Equal(epoch.Add(interval)))
			})

			It("constructs the resource of the correct type", func() {
				<-times

				_, metadata, session, typ, tags, customTypes, delegate := fakeTracker.InitArgsForCall(0)
				Expect(metadata).To(Equal(resource.EmptyMetadata{}))
				Expect(session).To(Equal(resource.Session{
					ID: worker.Identifier{
						ResourceID:  39,
						Stage:       db.ContainerStageRun,
						CheckType:   "git",
						CheckSource: atc.Source{"uri": "http://example.com"},
					},
		}
		macAddressDetector.macs = m
		return nil
	}

	BeforeEach(func() {
		runner = fakesys.NewFakeCmdRunner()
		clock = fakeclock.NewFakeClock(time.Now())
		logger := boshlog.NewLogger(boshlog.LevelNone)
		interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger)
		netManager = NewWindowsNetManager(runner, interfaceConfigurationCreator, macAddressDetector, logger, clock)
	})

	setupNetworking := func(networks boshsettings.Networks) error {
		// Allow 5 seconds to pass so that the Sleep() in the function can pass.
		go clock.WaitForWatcherAndIncrement(5 * time.Second)
		return netManager.SetupNetworking(networks, nil)
	}

	Describe("Setting NIC settings", func() {
		network1 := boshsettings.Network{
			Type:    "manual",
			DNS:     []string{"8.8.8.8"},
			Default: []string{"gateway", "dns"},
			IP:      "192.168.50.50",
			Gateway: "192.168.50.0",
			Netmask: "255.255.255.0",
			Mac:     "00:0C:29:0B:69:7A",
		}

		network2 := boshsettings.Network{
Beispiel #7
0
	It("pings the executor", func() {
		pingErrors <- nil
		maintainProcess = ginkgomon.Invoke(maintainer)
		Expect(fakeClient.PingCallCount()).To(Equal(1))
	})

	Context("when pinging the executor fails", func() {
		It("keeps pinging until it succeeds, then starts heartbeating the executor's presence", func() {
			maintainProcess = ifrit.Background(maintainer)
			ready := maintainProcess.Ready()

			for i := 1; i <= 4; i++ {
				pingErrors <- errors.New("ping failed")
				Eventually(fakeClient.PingCallCount).Should(Equal(i))
				clock.WaitForWatcherAndIncrement(1 * time.Second)
				Expect(ready).NotTo(BeClosed())
			}

			pingErrors <- nil
			clock.WaitForWatcherAndIncrement(1 * time.Second)
			Eventually(fakeClient.PingCallCount).Should(Equal(5))

			Eventually(ready).Should(BeClosed())
			Expect(fakeHeartbeater.RunCallCount()).To(Equal(1))
		})
	})

	Context("when pinging the executor succeeds", func() {
		Context("when the heartbeater is not ready", func() {
			BeforeEach(func() {