本文整理汇总了Golang中github.com/pivotal-golang/clock/fakeclock.NewFakeClock函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFakeClock函数的具体用法?Golang NewFakeClock怎么用?Golang NewFakeClock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFakeClock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: defaultConf
func defaultConf() HandlerConf {
return HandlerConf{
StoreAdapter: fakestoreadapter.New(),
Clock: fakeclock.NewFakeClock(time.Unix(100, 0)),
Logger: fakelogger.NewFakeLogger(),
}
}
示例2:
. "github.com/onsi/gomega"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
"github.com/pivotal-golang/clock/fakeclock"
. "github.com/cloudfoundry/bosh-utils/retrystrategy"
)
var _ = Describe("TimeoutRetryStrategy", func() {
var (
fakeTimeService *fakeclock.FakeClock
logger boshlog.Logger
)
BeforeEach(func() {
fakeTimeService = fakeclock.NewFakeClock(time.Now())
logger = boshlog.NewLogger(boshlog.LevelNone)
})
Describe("Try", func() {
Context("when there are errors during a try", func() {
It("retries until the timeout", func() {
retryable := newSimpleRetryable([]attemptOutput{
{
IsRetryable: true,
AttemptErr: errors.New("first-error"),
},
{
IsRetryable: true,
AttemptErr: errors.New("second-error"),
},
示例3:
fakeQueue *fake_operationq.FakeQueue
evacuatable evacuation_context.Evacuatable
evacuationNotifier evacuation_context.EvacuationNotifier
bulker *harmonizer.Bulker
process ifrit.Process
)
BeforeEach(func() {
sender = fake.NewFakeMetricSender()
metrics.Initialize(sender, nil)
logger = lagertest.NewTestLogger("test")
pollInterval = 30 * time.Second
evacuationPollInterval = 10 * time.Second
fakeClock = fakeclock.NewFakeClock(time.Unix(123, 456))
fakeGenerator = new(fake_generator.FakeGenerator)
fakeQueue = new(fake_operationq.FakeQueue)
evacuatable, _, evacuationNotifier = evacuation_context.New()
bulker = harmonizer.NewBulker(logger, pollInterval, evacuationPollInterval, evacuationNotifier, fakeClock, fakeGenerator, fakeQueue)
})
JustBeforeEach(func() {
process = ifrit.Invoke(bulker)
Eventually(fakeClock.WatcherCount).Should(Equal(1))
})
AfterEach(func() {
process.Signal(os.Interrupt)
示例4:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pivotal-golang/clock/fakeclock"
"github.com/tedsuo/ifrit"
)
var _ = Describe("Pipelines Sync Runner", func() {
var fakeSyncer *fakes.FakePipelineSyncer
var interval = 10 * time.Second
var fakeClock *fakeclock.FakeClock
var runner SyncRunner
var process ifrit.Process
BeforeEach(func() {
fakeSyncer = new(fakes.FakePipelineSyncer)
fakeClock = fakeclock.NewFakeClock(time.Unix(0, 123))
runner = SyncRunner{
Syncer: fakeSyncer,
Interval: interval,
Clock: fakeClock,
}
})
JustBeforeEach(func() {
process = ifrit.Invoke(runner)
})
AfterEach(func() {
process.Signal(os.Interrupt)
Eventually(process.Wait()).Should(Receive())
示例5: 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"}},
}
//.........这里部分代码省略.........
示例6:
. "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())
fakeClock.Increment(4 * time.Second)
Consistently(timeChan, Δ).ShouldNot(Receive())
fakeClock.Increment(1 * time.Second)
Eventually(timeChan).Should(Receive(Equal(initialTime.Add(10 * time.Second))))
示例7:
"github.com/pivotal-golang/clock/fakeclock"
)
var _ = Describe("SSH", func() {
Describe("SSHRetryStrategy", func() {
var (
sshRetryStrategy *SSHRetryStrategy
fakeTimeService *fakeclock.FakeClock
connectionRefusedTimeout time.Duration
authFailureTimeout time.Duration
startTime time.Time
)
BeforeEach(func() {
startTime = time.Now()
fakeTimeService = fakeclock.NewFakeClock(startTime)
connectionRefusedTimeout = 10 * time.Minute
authFailureTimeout = 5 * time.Minute
sshRetryStrategy = &SSHRetryStrategy{
ConnectionRefusedTimeout: connectionRefusedTimeout,
AuthFailureTimeout: authFailureTimeout,
TimeService: fakeTimeService,
}
})
Describe("IsRetryable", func() {
refusedErr := errors.New("connection refused")
authErr := errors.New("unable to authenticate")
Context("when err is connection refused", func() {
示例8:
fakeExitHandler *fake_exit_handler.FakeExitHandler
fakeGraphicalVisualizer *fake_graphical_visualizer.FakeGraphicalVisualizer
fakeTaskExaminer *fake_task_examiner.FakeTaskExaminer
systemDomain string
)
BeforeEach(func() {
fakeAppExaminer = &fake_app_examiner.FakeAppExaminer{}
fakeTaskExaminer = &fake_task_examiner.FakeTaskExaminer{}
outputBuffer = gbytes.NewBuffer()
terminalUI = terminal.NewUI(nil, outputBuffer, nil)
fakeTerm = &fake_terminal.FakeTerminal{}
osSignalChan = make(chan os.Signal, 1)
location, err := time.LoadLocation("Africa/Djibouti")
Expect(err).NotTo(HaveOccurred())
fakeClock = fakeclock.NewFakeClock(time.Date(2012, time.February, 29, 6, 45, 30, 820, location))
fakeExitHandler = &fake_exit_handler.FakeExitHandler{}
fakeGraphicalVisualizer = &fake_graphical_visualizer.FakeGraphicalVisualizer{}
systemDomain = "system.domain"
})
Describe("ListAppsCommand", func() {
var listAppsCommand cli.Command
BeforeEach(func() {
commandFactory := command_factory.NewAppExaminerCommandFactory(fakeAppExaminer, terminalUI, fakeTerm, fakeClock, fakeExitHandler, nil, fakeTaskExaminer, systemDomain)
listAppsCommand = commandFactory.MakeListAppCommand()
})
It("displays all the existing apps & tasks, making sure output spacing is correct", func() {
listApps := []app_examiner.AppInfo{
示例9:
)
var _ = Describe("Metrics Server", func() {
var (
store storepackage.Store
storeAdapter *fakestoreadapter.FakeStoreAdapter
timeProvider *fakeclock.FakeClock
metricsServer *MetricsServer
metricsAccountant *fakemetricsaccountant.FakeMetricsAccountant
)
BeforeEach(func() {
conf, _ := config.DefaultConfig()
storeAdapter = fakestoreadapter.New()
store = storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger())
timeProvider = fakeclock.NewFakeClock(time.Unix(100, 0))
metricsAccountant = &fakemetricsaccountant.FakeMetricsAccountant{}
metricsServer = New(nil, nil, metricsAccountant, fakelogger.NewFakeLogger(), store, timeProvider, conf)
})
Describe("message metrics", func() {
BeforeEach(func() {
metricsAccountant.GetMetricsReturns(map[string]float64{
"foo": 1,
"bar": 2,
}, nil)
})
Context("when the metrics fetch succesfully", func() {
示例10:
. "github.com/onsi/gomega"
)
var logger = lagertest.NewTestLogger("test")
var _ = Describe("Allocation Store", func() {
var (
allocationStore *allocationstore.AllocationStore
fakeClock *fakeclock.FakeClock
fakeEventEmitter *fakes.FakeEventEmitter
currentTime time.Time
)
BeforeEach(func() {
currentTime = time.Now()
fakeClock = fakeclock.NewFakeClock(currentTime)
fakeEventEmitter = &fakes.FakeEventEmitter{}
allocationStore = allocationstore.NewAllocationStore(fakeClock, fakeEventEmitter)
})
Describe("List", func() {
Context("when a container is allocated", func() {
var req executor.AllocationRequest
BeforeEach(func() {
resource := executor.NewResource(512, 512, "")
req = executor.NewAllocationRequest("banana", &resource, nil)
_, err := allocationStore.Allocate(logger, &req)
Expect(err).NotTo(HaveOccurred())
})
示例11:
radar *Radar
resourceConfig atc.ResourceConfig
savedResource db.SavedResource
fakeLease *dbfakes.FakeLease
process ifrit.Process
)
BeforeEach(func() {
epoch = time.Unix(123, 456).UTC()
fakeTracker = new(rfakes.FakeTracker)
fakeRadarDB = new(fakes.FakeRadarDB)
fakeClock = fakeclock.NewFakeClock(epoch)
interval = 1 * time.Minute
fakeRadarDB.GetPipelineNameReturns("some-pipeline")
radar = NewRadar(fakeTracker, interval, fakeRadarDB, fakeClock)
resourceConfig = atc.ResourceConfig{
Name: "some-resource",
Type: "git",
Source: atc.Source{"uri": "http://example.com"},
}
fakeRadarDB.ScopedNameStub = func(thing string) string {
return "pipeline:" + thing
}
示例12:
messageBus *fakeyagnats.FakeNATSConn
timeProvider *fakeclock.FakeClock
dea appfixture.DeaFixture
app appfixture.AppFixture
conf *config.Config
metricsAccountant *fakemetricsaccountant.FakeMetricsAccountant
)
BeforeEach(func() {
messageBus = fakeyagnats.Connect()
dea = appfixture.NewDeaFixture()
app = dea.GetApp(0)
conf, _ = config.DefaultConfig()
metricsAccountant = &fakemetricsaccountant.FakeMetricsAccountant{}
timeProvider = fakeclock.NewFakeClock(time.Unix(int64(10+conf.ActualFreshnessTTL()), 0))
storeAdapter = fakestoreadapter.New()
store = storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger())
sender = New(store, metricsAccountant, conf, messageBus, fakelogger.NewFakeLogger())
store.BumpActualFreshness(time.Unix(10, 0))
store.BumpDesiredFreshness(time.Unix(10, 0))
})
Context("when the sender fails to pull messages out of the start queue", func() {
BeforeEach(func() {
storeAdapter.ListErrInjector = fakestoreadapter.NewFakeStoreAdapterErrorInjector("start", errors.New("oops"))
})
It("should return an error and not send any messages", func() {
err := sender.Send(timeProvider)
示例13:
domain string = "192.168.11.11.xip.io"
fakeClock *fakeclock.FakeClock
fakeDockerMetadataFetcher *fake_docker_metadata_fetcher.FakeDockerMetadataFetcher
appRunnerCommandFactoryConfig command_factory.DockerRunnerCommandFactoryConfig
logger lager.Logger
fakeTailedLogsOutputter *fake_tailed_logs_outputter.FakeTailedLogsOutputter
fakeExitHandler *fake_exit_handler.FakeExitHandler
)
BeforeEach(func() {
fakeAppRunner = &fake_app_runner.FakeAppRunner{}
fakeAppExaminer = &fake_app_examiner.FakeAppExaminer{}
outputBuffer = gbytes.NewBuffer()
terminalUI = terminal.NewUI(nil, outputBuffer, nil)
fakeDockerMetadataFetcher = &fake_docker_metadata_fetcher.FakeDockerMetadataFetcher{}
fakeClock = fakeclock.NewFakeClock(time.Now())
logger = lager.NewLogger("ltc-test")
fakeTailedLogsOutputter = fake_tailed_logs_outputter.NewFakeTailedLogsOutputter()
fakeExitHandler = &fake_exit_handler.FakeExitHandler{}
})
Describe("CreateAppCommand", func() {
var createCommand cli.Command
BeforeEach(func() {
env := []string{"SHELL=/bin/bash", "COLOR=Blue"}
appRunnerCommandFactoryConfig = command_factory.DockerRunnerCommandFactoryConfig{
AppRunner: fakeAppRunner,
AppExaminer: fakeAppExaminer,
UI: terminalUI,
DockerMetadataFetcher: fakeDockerMetadataFetcher,
示例14:
var (
analyzer *Analyzer
storeAdapter *fakestoreadapter.FakeStoreAdapter
store storepackage.Store
clock *fakeclock.FakeClock
dea appfixture.DeaFixture
app appfixture.AppFixture
)
conf, _ := config.DefaultConfig()
BeforeEach(func() {
storeAdapter = fakestoreadapter.New()
store = storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger())
clock = fakeclock.NewFakeClock(time.Unix(1000, 0))
dea = appfixture.NewDeaFixture()
app = dea.GetApp(0)
store.BumpActualFreshness(time.Unix(100, 0))
store.BumpDesiredFreshness(time.Unix(100, 0))
analyzer = New(store, clock, fakelogger.NewFakeLogger(), conf)
})
startMessages := func() []models.PendingStartMessage {
messages, _ := store.GetPendingStartMessages()
messagesArr := []models.PendingStartMessage{}
for _, message := range messages {
messagesArr = append(messagesArr, message)
示例15: TestDB
var consulHelper *test_helpers.ConsulHelper
var serviceClient bbs.ServiceClient
var etcdDB db.DB
var etcdDBWithFakeStore db.DB
var workPoolCreateError error
var cryptor encryption.Cryptor
func TestDB(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "ETCD DB Suite")
}
var _ = BeforeSuite(func() {
clock = fakeclock.NewFakeClock(time.Unix(0, 1138))
etcdPort = 4001 + GinkgoParallelNode()
etcdUrl = fmt.Sprintf("http://127.0.0.1:%d", etcdPort)
etcdRunner = etcdstorerunner.NewETCDClusterRunner(etcdPort, 1, nil)
consulRunner = consulrunner.NewClusterRunner(
9001+config.GinkgoConfig.ParallelNode*consulrunner.PortOffsetLength,
1,
"http",
)
consulRunner.Start()
consulRunner.WaitUntilReady()
etcdRunner.Start()