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


Golang FakeClock.Increment方法代码示例

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


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

示例1: incrementSleepInBackground

func incrementSleepInBackground(fakeTimeService *fakeclock.FakeClock, delay time.Duration) chan struct{} {
	doneChan := make(chan struct{})
	go func() {
		for {
			select {
			case <-doneChan:
				return
			default:
				if fakeTimeService.WatcherCount() > 0 {
					fakeTimeService.Increment(delay)
				}
			}
		}
	}()
	return doneChan
}
开发者ID:mattcui,项目名称:bosh-agent,代码行数:16,代码来源:timeout_retry_strategy_test.go

示例2: PollFuncWithTimeout

// PollFuncWithTimeout is used to periodically execute a check function, it
// returns error after timeout.
func PollFuncWithTimeout(clockSource *fakeclock.FakeClock, f func() error, timeout time.Duration) error {
	if f() == nil {
		return nil
	}
	timer := time.NewTimer(timeout)
	defer timer.Stop()
	for i := 0; ; i++ {
		if i%5 == 0 && clockSource != nil {
			clockSource.Increment(time.Second)
		}
		err := f()
		if err == nil {
			return nil
		}
		select {
		case <-timer.C:
			return errors.Wrap(err, "polling failed")
		case <-time.After(50 * time.Millisecond):
		}
	}
}
开发者ID:yongtang,项目名称:swarmkit,代码行数:23,代码来源:testutils.go

示例3:

					Eventually(spawnedProcess.SignalCallCount).Should(Equal(1))

					waitExited <- (128 + 15)

					Eventually(performErr).Should(Receive(Equal(steps.ErrCancelled)))

					Expect(spawnedProcess.SignalCallCount()).To(Equal(1))
					Expect(spawnedProcess.SignalArgsForCall(0)).To(Equal(garden.SignalTerminate))
				})
			})

			Context("when the process does not exit after 10s", func() {
				It("sends a kill signal to the process", func() {
					Eventually(spawnedProcess.SignalCallCount).Should(Equal(1))

					fakeClock.Increment(steps.TERMINATE_TIMEOUT + 1*time.Second)

					Eventually(spawnedProcess.SignalCallCount).Should(Equal(2))
					Expect(spawnedProcess.SignalArgsForCall(1)).To(Equal(garden.SignalKill))

					waitExited <- (128 + 9)

					Eventually(performErr).Should(Receive(Equal(steps.ErrCancelled)))
				})

				Context("when the process *still* does not exit after 1m", func() {
					It("finishes performing with failure", func() {
						Eventually(spawnedProcess.SignalCallCount).Should(Equal(1))

						fakeClock.Increment(steps.TERMINATE_TIMEOUT + 1*time.Second)
开发者ID:snowsnail,项目名称:executor,代码行数:30,代码来源:run_step_test.go

示例4:

		Eventually(process.Wait()).Should(Receive())
	})

	itPerformsBatchOperations := func() {
		Context("when generating the batch operations succeeds", func() {
			var (
				operation1 *fake_operationq.FakeOperation
				operation2 *fake_operationq.FakeOperation
			)

			BeforeEach(func() {
				operation1 = new(fake_operationq.FakeOperation)
				operation2 = new(fake_operationq.FakeOperation)

				fakeGenerator.BatchOperationsStub = func(lager.Logger) (map[string]operationq.Operation, error) {
					fakeClock.Increment(10 * time.Second)
					return map[string]operationq.Operation{"guid1": operation1, "guid2": operation2}, nil
				}
			})

			It("pushes them onto the queue", func() {
				Eventually(fakeQueue.PushCallCount).Should(Equal(2))

				enqueuedOperations := make([]operationq.Operation, 0, 2)
				enqueuedOperations = append(enqueuedOperations, fakeQueue.PushArgsForCall(0))
				enqueuedOperations = append(enqueuedOperations, fakeQueue.PushArgsForCall(1))

				Expect(enqueuedOperations).To(ConsistOf(operation1, operation2))
			})

			It("emits the duration it took to generate the batch operations", func() {
开发者ID:jiangytcn,项目名称:rep,代码行数:31,代码来源:bulker_test.go

示例5:

				go func() {
					errchan <- monit.StopAndWait()
				}()

				Eventually(timeService.WatcherCount).Should(Equal(2)) // we hit the sleep

				// never called stop since 2 jobs pending
				Expect(len(runner.RunCommands)).To(Equal(0))

				client.StatusStatus = fakemonit.FakeMonitStatus{
					Services: []boshmonit.Service{
						{Monitored: false, Name: "foo", Status: "unknown", Pending: false},
						{Monitored: true, Name: "bar", Status: "unknown", Pending: true},
					},
				}
				timeService.Increment(2 * time.Minute)

				Eventually(timeService.WatcherCount).Should(Equal(2)) // we hit the sleep

				// never called stop since 1 job pending
				Expect(len(runner.RunCommands)).To(Equal(0))

				client.StatusStatus = fakemonit.FakeMonitStatus{
					Services: []boshmonit.Service{
						{Monitored: false, Name: "foo", Status: "unknown", Pending: false},
						{Monitored: false, Name: "bar", Status: "unknown", Pending: false},
					},
				}
				timeService.Increment(2 * time.Minute)

				Eventually(errchan).Should(Receive(BeNil()))
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:31,代码来源:monit_job_supervisor_test.go

示例6:

		logErrBuffer = bytes.NewBufferString("")
		logger = boshlog.NewWriterLogger(boshlog.LevelDebug, logOutBuffer, logErrBuffer)

		ui = NewWriterUI(uiOut, uiErr, logger)
		fakeTimeService = fakeclock.NewFakeClock(time.Now())

		stage = NewStage(ui, fakeTimeService, logger)
	})

	Describe("Perform", func() {
		It("prints a single-line stage", func() {
			actionsPerformed := []string{}

			err := stage.Perform("Simple stage 1", func() error {
				actionsPerformed = append(actionsPerformed, "1")
				fakeTimeService.Increment(time.Minute)
				return nil
			})

			Expect(err).To(BeNil())

			expectedOutput := "Simple stage 1... Finished (00:01:00)\n"
			Expect(uiOut.String()).To(Equal(expectedOutput))
			Expect(actionsPerformed).To(Equal([]string{"1"}))
		})

		It("fails on error", func() {
			actionsPerformed := []string{}
			stageError := bosherr.Error("fake-stage-1-error")

			err := stage.Perform("Simple stage 1", func() error {
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:stage_test.go

示例7:

					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)
					Expect(err).To(MatchError(ContainSubstring("timeout")))
开发者ID:cloudfoundry,项目名称:guardian,代码行数:30,代码来源:pid_file_reader_test.go

示例8:

			err = allocationStore.Initialize(logger, &runReq)
			Expect(err).NotTo(HaveOccurred())

			expirationTime = 20 * time.Millisecond

			pruner := allocationStore.RegistryPruner(logger, expirationTime)
			process = ginkgomon.Invoke(pruner)
		})

		AfterEach(func() {
			ginkgomon.Interrupt(process)
		})

		Context("when the elapsed time is less than expiration period", func() {
			BeforeEach(func() {
				fakeClock.Increment(expirationTime / 2)
			})

			It("all containers are still in the list", func() {
				Consistently(allocationStore.List).Should(HaveLen(2))
			})
		})

		Context("when the elapsed time is more than expiration period", func() {
			BeforeEach(func() {
				fakeClock.Increment(2 * expirationTime)
			})

			It("it removes only RESERVED containers from the list", func() {
				Eventually(allocationStore.List).Should(HaveLen(1))
				Expect(allocationStore.List()[0].Guid).To(Equal("eventually-initialized"))
开发者ID:snowsnail,项目名称:executor,代码行数:31,代码来源:allocationstore_test.go

示例9:

		}

		dockerRecipeBuilder = new(fakes.FakeRecipeBuilder)
		dockerRecipeBuilder.BuildStub = func(ccRequest *cc_messages.DesireAppRequestFromCC) (*models.DesiredLRP, error) {
			createRequest := models.DesiredLRP{
				ProcessGuid: ccRequest.ProcessGuid,
				Annotation:  ccRequest.ETag,
			}
			return &createRequest, nil
		}

		bbsClient = new(fake_bbs.FakeClient)
		bbsClient.DesiredLRPSchedulingInfosReturns(existingSchedulingInfos, nil)

		bbsClient.UpsertDomainStub = func(string, time.Duration) error {
			clock.Increment(syncDuration)
			return nil
		}

		logger = lagertest.NewTestLogger("test")

		processor = bulk.NewProcessor(
			bbsClient,
			500*time.Millisecond,
			time.Second,
			10,
			50,
			false,
			logger,
			fetcher,
			map[string]recipebuilder.RecipeBuilder{
开发者ID:emc-xchallenge,项目名称:nsync,代码行数:31,代码来源:processor_test.go

示例10:

	})

	AfterEach(func() {
		process.Signal(os.Interrupt)
		Eventually(process.Wait()).Should(Receive(BeNil()))
		close(syncChannel)
	})

	Context("on a specified interval", func() {

		It("should sync", func() {
			process = ifrit.Invoke(syncerRunner)
			var t1 time.Time
			var t2 time.Time

			clock.Increment(syncInterval + 100*time.Millisecond)

			select {
			case <-syncChannel:
				t1 = clock.Now()
			case <-time.After(2 * syncInterval):
				Fail("did not receive a sync event")
			}

			clock.Increment(syncInterval + 100*time.Millisecond)

			select {
			case <-syncChannel:
				t2 = clock.Now()
			case <-time.After(2 * syncInterval):
				Fail("did not receive a sync event")
开发者ID:jmptrader,项目名称:cf-tcp-router,代码行数:31,代码来源:syncer_test.go

示例11:

							newConfig = atc.Config{
								Resources: atc.ResourceConfigs{newResource},
							}
						})

						It("goes back to the default interval", func() {
							Expect(<-times).To(Equal(epoch)) // ignore immediate first check

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

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

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

				Context("with the resource removed", func() {
					BeforeEach(func() {
						newConfig = atc.Config{
							Resources: atc.ResourceConfigs{},
						}
					})

					It("exits with the correct error", func() {
						<-times
开发者ID:pcfdev-forks,项目名称:atc,代码行数:30,代码来源:radar_test.go

示例12:

	It("To subscribe to the dea.advertise subject", func() {
		Expect(messageBus.Subscriptions("dea.advertise")).NotTo(BeNil())
		Expect(messageBus.Subscriptions("dea.advertise")).To(HaveLen(1))
	})

	It("To start tracking store usage", func() {
		Expect(usageTracker.StartTrackingUsageCallCount()).To(Equal(1))
		Expect(usageTracker.MeasureUsageCallCount()).To(Equal(1))
		Expect(metricsAccountant.TrackActualStateListenerStoreUsageFractionCallCount()).To(Equal(1))
		Expect(metricsAccountant.TrackActualStateListenerStoreUsageFractionArgsForCall(0)).To(Equal(0.7))
	})

	It("To save heartbeats on a timer", func() {
		beat()
		clock.Increment(conf.ListenerHeartbeatSyncInterval())
		Eventually(store.SyncHeartbeatsCallCount).Should(Equal(1))

		beat()
		Consistently(store.SyncHeartbeatsCallCount).Should(Equal(1))

		clock.Increment(conf.ListenerHeartbeatSyncInterval())
		Eventually(store.SyncHeartbeatsCallCount).Should(Equal(2))
	})

	Context("When it receives a dea advertisement over the message bus", func() {
		advertise := func() {
			messageBus.SubjectCallbacks("dea.advertise")[0](&nats.Msg{
				Data: []byte("doesn't matter"),
			})
		}
开发者ID:nagyistge,项目名称:hm9000,代码行数:30,代码来源:actual_state_listener_test.go

示例13:

				BeforeEach(func() {
					containerResponses := [][]executor.Container{
						containers,
						[]executor.Container{},
					}

					index := 0
					executorClient.ListContainersStub = func(lager.Logger) ([]executor.Container, error) {
						containersToReturn := containerResponses[index]
						index++
						return containersToReturn, nil
					}
				})

				It("waits for all the containers to go away and exits before evacuation timeout", func() {
					fakeClock.Increment(pollingInterval)
					Eventually(executorClient.ListContainersCallCount).Should(Equal(1))

					fakeClock.Increment(pollingInterval)
					Eventually(executorClient.ListContainersCallCount).Should(Equal(2))

					Eventually(errChan).Should(Receive(BeNil()))
				})

				Context("when the executor client returns an error", func() {
					BeforeEach(func() {
						index := 0
						executorClient.ListContainersStub = func(lager.Logger) ([]executor.Container, error) {
							if index == 0 {
								index++
								return nil, errors.New("whoops")
开发者ID:jiangytcn,项目名称:rep,代码行数:31,代码来源:evacuation_test.go

示例14:

	AfterEach(func() {
		pmn.Signal(os.Interrupt)
		Eventually(pmn.Wait(), 2*time.Second).Should(Receive())
	})

	Context("when the metron notifier starts up", func() {
		It("should emit an event that BBS has started", func() {
			Eventually(func() uint64 {
				return sender.GetCounter("BBSMasterElected")
			}).Should(Equal(uint64(1)))
		})
	})

	Context("when the report interval elapses", func() {
		JustBeforeEach(func() {
			fakeClock.Increment(reportInterval)
		})

		Context("when the etcd cluster is around", func() {
			var (
				etcd1 *ghttp.Server
				etcd2 *ghttp.Server
				etcd3 *ghttp.Server
			)

			BeforeEach(func() {
				etcd1 = ghttp.NewServer()
				etcd2 = ghttp.NewServer()
				etcd3 = ghttp.NewServer()

				etcdOptions.ClusterUrls = []string{
开发者ID:emc-xchallenge,项目名称:bbs,代码行数:31,代码来源:periodic_metron_notifier_test.go

示例15:

var _ = Describe("FakeClock", func() {
	const Δ time.Duration = 10 * time.Millisecond

	var (
		fakeClock   *fakeclock.FakeClock
		initialTime time.Time
	)

	BeforeEach(func() {
		initialTime = time.Date(2014, 1, 1, 3, 0, 30, 0, time.UTC)
		fakeClock = fakeclock.NewFakeClock(initialTime)
	})

	Describe("Now", func() {
		It("returns the current time, w/o race conditions", func() {
			go fakeClock.Increment(time.Minute)
			Eventually(fakeClock.Now).Should(Equal(initialTime.Add(time.Minute)))
		})
	})

	Describe("Sleep", func() {
		It("blocks until the given interval elapses", func() {
			doneSleeping := make(chan struct{})
			go func() {
				fakeClock.Sleep(10 * time.Second)
				close(doneSleeping)
			}()

			Consistently(doneSleeping, Δ).ShouldNot(BeClosed())

			fakeClock.Increment(5 * time.Second)
开发者ID:hpcloud,项目名称:statsd-injector,代码行数:31,代码来源:fake_clock_test.go


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