当前位置: 首页>>代码示例>>Golang>>正文


Golang FakeClock.WaitForWatcherAndIncrement方法代码示例

本文整理汇总了Golang中github.com/pivotal-golang/clock/fakeclock.FakeClock.WaitForWatcherAndIncrement方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeClock.WaitForWatcherAndIncrement方法的具体用法?Golang FakeClock.WaitForWatcherAndIncrement怎么用?Golang FakeClock.WaitForWatcherAndIncrement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/pivotal-golang/clock/fakeclock.FakeClock的用法示例。


在下文中一共展示了FakeClock.WaitForWatcherAndIncrement方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1:

					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)
开发者ID:cloudfoundry,项目名称:guardian,代码行数:31,代码来源:pid_file_reader_test.go

示例2:

			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)
	})
})
开发者ID:cloudfoundry,项目名称:garden-shed,代码行数:30,代码来源:retrier_test.go

示例3:

	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)))
			}
		})
	})
})
开发者ID:digideskweb,项目名称:bosh-softlayer-cpi,代码行数:29,代码来源:fake_timer_test.go

示例4:

			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))
开发者ID:ACPK,项目名称:atc,代码行数:31,代码来源:runner_test.go

示例5:

			})

			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"},
					},
开发者ID:pcfdev-forks,项目名称:atc,代码行数:31,代码来源:radar_test.go

示例6:

		}
		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{
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:31,代码来源:windows_net_manager_test.go

示例7:

	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() {
开发者ID:jiangytcn,项目名称:rep,代码行数:30,代码来源:maintain_test.go


注:本文中的github.com/pivotal-golang/clock/fakeclock.FakeClock.WaitForWatcherAndIncrement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。