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


Golang fakeclock.FakeClock类代码示例

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


在下文中一共展示了FakeClock类的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:

package fakeclock_test

import (
	"time"

	"github.com/pivotal-golang/clock/fakeclock"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("FakeTicker", func() {
	const Δ = 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)
	})

	It("provides a channel that receives the time at each interval", func() {
		ticker := fakeClock.NewTicker(10 * time.Second)
		timeChan := ticker.C()
		Consistently(timeChan, Δ).ShouldNot(Receive())

		fakeClock.Increment(5 * time.Second)
		Consistently(timeChan, Δ).ShouldNot(Receive())
开发者ID:andrew-edgar,项目名称:clock,代码行数:31,代码来源:fake_ticker_test.go

示例4:

	"github.com/pivotal-golang/clock/fakeclock"

	"github.com/cloudfoundry-incubator/converger/converger_process"
)

const aBit = 100 * time.Millisecond

var _ = Describe("ConvergerProcess", func() {
	var (
		fakeBBSServiceClient        *fake_bbs.FakeServiceClient
		fakeBBSClient               *fake_bbs.FakeClient
		logger                      *lagertest.TestLogger
		fakeClock                   *fakeclock.FakeClock
		convergeRepeatInterval      time.Duration
		kickTaskDuration            time.Duration
		expirePendingTaskDuration   time.Duration
		expireCompletedTaskDuration time.Duration

		process ifrit.Process

		waitEvents chan<- models.CellEvent
		waitErrs   chan<- error
	)

	BeforeEach(func() {
		fakeBBSServiceClient = new(fake_bbs.FakeServiceClient)
		fakeBBSClient = new(fake_bbs.FakeClient)
		logger = lagertest.NewTestLogger("test")
		fakeClock = fakeclock.NewFakeClock(time.Now())

		convergeRepeatInterval = 1 * time.Second
开发者ID:emc-xchallenge,项目名称:converger,代码行数:31,代码来源:converger_process_test.go

示例5:

	"os"
	"time"

	"code.cloudfoundry.org/guardian/rundmc/dadoo"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/pivotal-golang/clock/fakeclock"
)

var _ = Describe("PidFileReader", func() {

	var (
		clk     *fakeclock.FakeClock
		timeout time.Duration

		pdr *dadoo.PidFileReader

		pidFileContents string
		pidFilePath     string
	)

	BeforeEach(func() {
		clk = fakeclock.NewFakeClock(time.Now())
		timeout = time.Millisecond * 60

		pidFileContents = "5621"
	})

	JustBeforeEach(func() {
		pdr = &dadoo.PidFileReader{
			Clock:         clk,
开发者ID:cloudfoundry,项目名称:guardian,代码行数:31,代码来源:pid_file_reader_test.go

示例6:

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("MonitorStep", func() {
	var (
		fakeStep1 *fakes.FakeStep
		fakeStep2 *fakes.FakeStep

		checkSteps chan *fakes.FakeStep

		checkFunc        func() steps.Step
		hasBecomeHealthy <-chan struct{}
		clock            *fakeclock.FakeClock
		fakeStreamer     *fake_log_streamer.FakeLogStreamer

		startTimeout      time.Duration
		healthyInterval   time.Duration
		unhealthyInterval time.Duration

		step   steps.Step
		logger *lagertest.TestLogger
	)

	const numOfConcurrentMonitorSteps = 3

	BeforeEach(func() {
		startTimeout = 0
		healthyInterval = 1 * time.Second
		unhealthyInterval = 500 * time.Millisecond
开发者ID:snowsnail,项目名称:executor,代码行数:31,代码来源:monitor_step_test.go

示例7:

)

var _ = Describe("Watcher", func() {
	const (
		expectedProcessGuid  = "some-process-guid"
		expectedInstanceGuid = "some-instance-guid"
		retryWaitDuration    = 50 * time.Millisecond
	)

	var (
		bbs             *fake_bbs.FakeReceptorBBS
		hub             *eventfakes.FakeHub
		clock           *fakeclock.FakeClock
		receptorWatcher watcher.Watcher
		process         ifrit.Process

		desiredLRPStop   chan bool
		desiredLRPErrors chan error

		actualLRPStop   chan bool
		actualLRPErrors chan error
	)

	BeforeEach(func() {
		bbs = new(fake_bbs.FakeReceptorBBS)
		hub = new(eventfakes.FakeHub)
		clock = fakeclock.NewFakeClock(time.Now())
		logger := lagertest.NewTestLogger("test")

		desiredLRPStop = make(chan bool, 1)
		desiredLRPErrors = make(chan error)
开发者ID:rajkumargithub,项目名称:lattice,代码行数:31,代码来源:watcher_test.go

示例8:

	"github.com/tedsuo/ifrit"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/ghttp"
)

// a bit of grace time for eventuallys
const aBit = 50 * time.Millisecond

var _ = Describe("PeriodicMetronNotifier", func() {
	var (
		sender *fake.FakeMetricSender

		etcdOptions    etcd.ETCDOptions
		reportInterval time.Duration
		fakeClock      *fakeclock.FakeClock

		pmn ifrit.Process
	)

	BeforeEach(func() {
		reportInterval = 100 * time.Millisecond

		fakeClock = fakeclock.NewFakeClock(time.Unix(123, 456))

		sender = fake.NewFakeMetricSender()
		dropsonde_metrics.Initialize(sender, nil)
	})

	JustBeforeEach(func() {
开发者ID:emc-xchallenge,项目名称:bbs,代码行数:31,代码来源:periodic_metron_notifier_test.go

示例9:

	boshalert "github.com/cloudfoundry/bosh-agent/agent/alert"
	. "github.com/cloudfoundry/bosh-agent/jobsupervisor"
	boshmonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit"
	fakemonit "github.com/cloudfoundry/bosh-agent/jobsupervisor/monit/fakes"
	boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
	boshlog "github.com/cloudfoundry/bosh-utils/logger"
	fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
)

var _ = Describe("monitJobSupervisor", func() {
	var (
		fs                    *fakesys.FakeFileSystem
		runner                *fakesys.FakeCmdRunner
		client                *fakemonit.FakeMonitClient
		logger                boshlog.Logger
		dirProvider           boshdir.Provider
		jobFailuresServerPort int
		monit                 JobSupervisor
		timeService           *fakeclock.FakeClock
	)

	var jobFailureServerPort = 5000

	getJobFailureServerPort := func() int {
		jobFailureServerPort++
		return jobFailureServerPort
	}

	BeforeEach(func() {
		fs = fakesys.NewFakeFileSystem()
		runner = fakesys.NewFakeCmdRunner()
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:31,代码来源:monit_job_supervisor_test.go

示例10:

	"github.com/pivotal-golang/clock/fakeclock"
	"github.com/pivotal-golang/lager"
	"github.com/pivotal-golang/lager/lagertest"

	"github.com/concourse/atc"
	"github.com/concourse/atc/db"
	"github.com/concourse/atc/worker"
	"github.com/concourse/atc/worker/fakes"
)

var _ = Describe("Hardcoded", func() {
	var (
		logger           lager.Logger
		workerDB         *fakes.FakeSaveWorkerDB
		gardenAddr       string
		baggageClaimAddr string
		resourceTypes    []atc.WorkerResourceType
		fakeClock        *fakeclock.FakeClock

		process ifrit.Process
	)

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("hardcoded-worker")
		workerDB = &fakes.FakeSaveWorkerDB{}
		gardenAddr = "http://garden.example.com"
		baggageClaimAddr = "http://volumes.example.com"
		resourceTypes = []atc.WorkerResourceType{
			{
				Type:  "type",
				Image: "image",
			},
开发者ID:pcfdev-forks,项目名称:atc,代码行数:32,代码来源:hardcoded_test.go

示例11:

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/concourse/atc/worker"
	"github.com/concourse/atc/worker/fakes"
	"github.com/concourse/baggageclaim"
	bfakes "github.com/concourse/baggageclaim/fakes"
	"github.com/pivotal-golang/clock/fakeclock"
	"github.com/pivotal-golang/lager/lagertest"
)

var _ = Describe("Volumes", func() {
	var (
		volumeFactory worker.VolumeFactory
		fakeVolume    *bfakes.FakeVolume
		fakeDB        *fakes.FakeVolumeFactoryDB
		fakeClock     *fakeclock.FakeClock
		logger        *lagertest.TestLogger
	)

	BeforeEach(func() {
		fakeVolume = new(bfakes.FakeVolume)
		fakeDB = new(fakes.FakeVolumeFactoryDB)
		fakeClock = fakeclock.NewFakeClock(time.Unix(123, 456))
		logger = lagertest.NewTestLogger("test")

		volumeFactory = worker.NewVolumeFactory(fakeDB, fakeClock)
	})

	Context("VolumeFactory", func() {
		Describe("Build", func() {
开发者ID:pcfdev-forks,项目名称:atc,代码行数:31,代码来源:volume_test.go

示例12:

	"github.com/pivotal-golang/clock/fakeclock"
	"github.com/pivotal-golang/lager"

	"github.com/cloudfoundry-incubator/auction/auctionrunner"
	"github.com/cloudfoundry-incubator/auction/auctiontypes"
	"github.com/cloudfoundry-incubator/rep"
	"github.com/cloudfoundry-incubator/rep/repfakes"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Scheduler", func() {
	var clients map[string]*repfakes.FakeSimClient
	var zones map[string]auctionrunner.Zone
	var clock *fakeclock.FakeClock
	var workPool *workpool.WorkPool
	var results auctiontypes.AuctionResults
	var logger lager.Logger

	BeforeEach(func() {
		clock = fakeclock.NewFakeClock(time.Now())

		var err error
		workPool, err = workpool.NewWorkPool(5)
		Expect(err).NotTo(HaveOccurred())

		clients = map[string]*repfakes.FakeSimClient{}
		zones = map[string]auctionrunner.Zone{}

		logger = lager.NewLogger("fakelogger")
开发者ID:emc-xchallenge,项目名称:auction,代码行数:31,代码来源:scheduler_test.go

示例13:

			}
		})

		It("should call the callback 12 times", func() {
			Expect(ret.Retry(callback)).NotTo(Succeed())
			Expect(callbackCount).To(Equal(12))
		})

		It("should return the error", func() {
			Expect(ret.Retry(callback)).To(MatchError("banana"))
		})
	})

	Context("when the callback succeeds after a while", func() {
		var (
			fakeClk *fakeclock.FakeClock
			called  chan bool
		)

		BeforeEach(func() {
			fakeClk = fakeclock.NewFakeClock(time.Now())
			clk = fakeClk
			called = make(chan bool, 12)

			callback = func() error {
				called <- true

				callbackCount++
				if callbackCount == 6 {
					return nil
				}
开发者ID:cloudfoundry,项目名称:garden-shed,代码行数:31,代码来源:retrier_test.go

示例14:

	"github.com/pivotal-golang/clock/fakeclock"
	"github.com/pivotal-golang/lager"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("StagingCompletedHandler", func() {
	var (
		logger lager.Logger
		appId  string
		taskId string

		fakeCCClient        *fakes.FakeCcClient
		fakeBackend         *fake_backend.FakeBackend
		backendResponse     cc_messages.StagingResponseForCC
		backendError        error
		fakeClock           *fakeclock.FakeClock
		metricSender        *fake.FakeMetricSender
		stagingDurationNano time.Duration

		responseRecorder *httptest.ResponseRecorder
		handler          handlers.CompletionHandler
	)

	BeforeEach(func() {
		logger = lager.NewLogger("fakelogger")
		logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.DEBUG))

		appId = "my_app_id"
		taskId = "do_this"
开发者ID:cfibmers,项目名称:stager,代码行数:31,代码来源:staging_completed_handler_test.go

示例15: init

func init() {
	Describe("Agent", func() {
		var (
			logger           boshlog.Logger
			handler          *fakembus.FakeHandler
			platform         *fakeplatform.FakePlatform
			actionDispatcher *fakeagent.FakeActionDispatcher
			jobSupervisor    *fakejobsuper.FakeJobSupervisor
			specService      *fakeas.FakeV1Service
			syslogServer     *fakesyslog.FakeServer
			settingsService  *fakesettings.FakeSettingsService
			uuidGenerator    *fakeuuid.FakeGenerator
			timeService      *fakeclock.FakeClock
			agent            Agent
		)

		BeforeEach(func() {
			logger = boshlog.NewLogger(boshlog.LevelNone)
			handler = &fakembus.FakeHandler{}
			platform = fakeplatform.NewFakePlatform()
			actionDispatcher = &fakeagent.FakeActionDispatcher{}
			jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
			specService = fakeas.NewFakeV1Service()
			syslogServer = &fakesyslog.FakeServer{}
			settingsService = &fakesettings.FakeSettingsService{}
			uuidGenerator = &fakeuuid.FakeGenerator{}
			timeService = fakeclock.NewFakeClock(time.Now())
			agent = New(
				logger,
				handler,
				platform,
				actionDispatcher,
				jobSupervisor,
				specService,
				syslogServer,
				5*time.Millisecond,
				settingsService,
				uuidGenerator,
				timeService,
			)
		})

		Describe("Run", func() {
			It("lets dispatcher handle requests arriving via handler", func() {
				err := agent.Run()
				Expect(err).ToNot(HaveOccurred())

				expectedResp := boshhandler.NewValueResponse("pong")
				actionDispatcher.DispatchResp = expectedResp

				req := boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
				resp := handler.RunFunc(req)

				Expect(actionDispatcher.DispatchReq).To(Equal(req))
				Expect(resp).To(Equal(expectedResp))
			})

			It("resumes persistent actions *before* dispatching new requests", func() {
				resumedBeforeStartingToDispatch := false
				handler.RunCallBack = func() {
					resumedBeforeStartingToDispatch = actionDispatcher.ResumedPreviouslyDispatchedTasks
				}

				err := agent.Run()
				Expect(err).ToNot(HaveOccurred())
				Expect(resumedBeforeStartingToDispatch).To(BeTrue())
			})

			Context("when heartbeats can be sent", func() {
				BeforeEach(func() {
					handler.KeepOnRunning()
				})

				BeforeEach(func() {
					jobName := "fake-job"
					nodeID := "node-id"
					jobIndex := 1
					specService.Spec = boshas.V1ApplySpec{
						JobSpec: boshas.JobSpec{Name: &jobName},
						Index:   &jobIndex,
						NodeID:  nodeID,
					}

					jobSupervisor.StatusStatus = "fake-state"

					platform.FakeVitalsService.GetVitals = boshvitals.Vitals{
						Load: []string{"a", "b", "c"},
					}
				})

				expectedJobName := "fake-job"
				expectedJobIndex := 1
				expectedNodeID := "node-id"
				expectedHb := Heartbeat{
					Job:      &expectedJobName,
					Index:    &expectedJobIndex,
					JobState: "fake-state",
					NodeID:   expectedNodeID,
					Vitals:   boshvitals.Vitals{Load: []string{"a", "b", "c"}},
				}
//.........这里部分代码省略.........
开发者ID:nimbus-cloud,项目名称:bosh-agent,代码行数:101,代码来源:agent_test.go


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