本文整理汇总了Golang中github.com/tedsuo/ifrit.Process.Wait方法的典型用法代码示例。如果您正苦于以下问题:Golang Process.Wait方法的具体用法?Golang Process.Wait怎么用?Golang Process.Wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tedsuo/ifrit.Process
的用法示例。
在下文中一共展示了Process.Wait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: waitForEvents
func waitForEvents(
member Member,
process ifrit.Process,
entrance entranceEventChannel,
exit exitEventChannel,
) {
select {
case <-process.Ready():
entrance <- EntranceEvent{
Member: member,
Process: process,
}
exit <- ExitEvent{
Member: member,
Err: <-process.Wait(),
}
case err := <-process.Wait():
entrance <- EntranceEvent{
Member: member,
Process: process,
}
exit <- ExitEvent{
Member: member,
Err: err,
}
}
}
示例2: forwardSignals
func forwardSignals(signals <-chan os.Signal, process ifrit.Process) {
exit := process.Wait()
for {
select {
case sig := <-signals:
process.Signal(sig)
case <-exit:
return
}
}
}
示例3: waitUntilReady
func waitUntilReady(process ifrit.Process, logger lager.Logger) error {
//we could not find a reliable way for ifrit to report that all processes
//were ready without error, so we opted to simply report as ready if no errors
//were thrown within a timeout
ready := time.After(5 * time.Second)
select {
case <-ready:
logger.Info("All child processes are ready")
return nil
case err := <-process.Wait():
if err == nil {
//sometimes process will exit early, but will return a nil error
err = errors.New("Child process exited before becoming ready")
}
return err
}
}
示例4:
})
Context("when attempt 1 succeeds", func() {
BeforeEach(func() {
attempt1Step.ResultStub = successResult(true)
})
Describe("Run", func() {
var process ifrit.Process
JustBeforeEach(func() {
process = ifrit.Invoke(step)
})
It("returns nil having only run the first attempt", func() {
Expect(<-process.Wait()).ToNot(HaveOccurred())
Expect(attempt1Step.RunCallCount()).To(Equal(1))
Expect(attempt2Step.RunCallCount()).To(Equal(0))
Expect(attempt3Step.RunCallCount()).To(Equal(0))
})
Describe("Result", func() {
It("delegates to attempt 1", func() {
<-process.Wait()
// internal check for success within retry loop
Expect(attempt1Step.ResultCallCount()).To(Equal(1))
attempt1Step.ResultReturns(true)
示例5:
converger_process.New(
fakeBBSServiceClient,
fakeBBSClient,
logger,
fakeClock,
convergeRepeatInterval,
kickTaskDuration,
expirePendingTaskDuration,
expireCompletedTaskDuration,
),
)
})
AfterEach(func() {
ginkgomon.Interrupt(process)
Eventually(process.Wait()).Should(Receive())
})
Describe("converging over time", func() {
It("converges tasks, LRPs, and auctions when the lock is periodically reestablished", func() {
fakeClock.Increment(convergeRepeatInterval + aBit)
Eventually(fakeBBSClient.ConvergeTasksCallCount, aBit).Should(Equal(1))
Eventually(fakeBBSClient.ConvergeLRPsCallCount, aBit).Should(Equal(1))
actualKickTaskDuration, actualExpirePendingTaskDuration, actualExpireCompletedTaskDuration := fakeBBSClient.ConvergeTasksArgsForCall(0)
Expect(actualKickTaskDuration).To(Equal(kickTaskDuration))
Expect(actualExpirePendingTaskDuration).To(Equal(expirePendingTaskDuration))
Expect(actualExpireCompletedTaskDuration).To(Equal(expireCompletedTaskDuration))
fakeClock.Increment(convergeRepeatInterval + aBit)
示例6:
)
BeforeEach(func() {
healthPort = 10000 + GinkgoParallelNode()
logger = lagertest.NewTestLogger("HealthRunner Test")
healthRunner = health.NewRunner(uint(healthPort), logger)
healthProcess = ifrit.Invoke(healthRunner)
isReady := healthProcess.Ready()
Eventually(isReady, startupTimeout).Should(BeClosed(), "Error starting Health Runner")
})
AfterEach(func() {
healthProcess.Signal(os.Kill)
err := <-healthProcess.Wait()
Expect(err).ToNot(HaveOccurred())
})
Context("when the runner is running", func() {
It("accepts connections on health port", func() {
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", healthPort))
Expect(err).ToNot(HaveOccurred())
err = conn.Close()
Expect(err).ToNot(HaveOccurred())
})
})
It("shuts down gracefully when signalled", func() {
healthProcess.Signal(os.Kill)
示例7:
})
})
Describe("Run", func() {
BeforeEach(func() {
uaaClient.FetchTokenReturns(token, nil)
client.RoutesReturns(response, nil)
})
JustBeforeEach(func() {
process = ifrit.Invoke(fetcher)
})
AfterEach(func() {
process.Signal(os.Interrupt)
Eventually(process.Wait(), 5*time.Second).Should(Receive())
})
It("subscribes for events", func() {
Eventually(client.SubscribeToEventsWithMaxRetriesCallCount).Should(Equal(1))
})
Context("on specified interval", func() {
It("it fetches routes", func() {
// to be consumed by by the eventSource.NextStub to avoid starvation
eventChannel <- routing_api.Event{}
clock.Increment(cfg.PruneStaleDropletsInterval + 100*time.Millisecond)
Eventually(client.RoutesCallCount, 2*time.Second, 50*time.Millisecond).Should(Equal(1))
clock.Increment(cfg.PruneStaleDropletsInterval + 100*time.Millisecond)
Eventually(client.RoutesCallCount, 2*time.Second, 50*time.Millisecond).Should(Equal(2))
})
示例8:
_, err := io.Stdout.Write([]byte(outScriptStdout))
Ω(err).ShouldNot(HaveOccurred())
_, err = io.Stderr.Write([]byte(outScriptStderr))
Ω(err).ShouldNot(HaveOccurred())
return outScriptProcess, nil
}
versionedSource = resource.Put(ioConfig, source, params, fakeArtifactSource)
outProcess = ifrit.Invoke(versionedSource)
})
AfterEach(func() {
Eventually(outProcess.Wait()).Should(Receive())
})
itCanStreamOut := func() {
Describe("streaming bits out", func() {
Context("when streaming out succeeds", func() {
BeforeEach(func() {
fakeContainer.StreamOutStub = func(spec garden.StreamOutSpec) (io.ReadCloser, error) {
streamOut := new(bytes.Buffer)
if spec.Path == "/tmp/build/put/some/subdir" {
streamOut.WriteString("sup")
}
return ioutil.NopCloser(streamOut), nil
}
示例9:
restarter = restart.Restarter{
Runner: testRunner,
Load: func(runner ifrit.Runner, err error) ifrit.Runner {
return nil
},
}
})
JustBeforeEach(func() {
process = ifrit.Background(restarter)
})
AfterEach(func() {
process.Signal(os.Kill)
testRunner.EnsureExit()
Eventually(process.Wait()).Should(Receive())
})
Describe("Process Behavior", func() {
It("waits for the internal runner to be ready", func() {
Consistently(process.Ready()).ShouldNot(BeClosed())
testRunner.TriggerReady()
Eventually(process.Ready()).Should(BeClosed())
})
})
Describe("Load", func() {
Context("when load returns a runner", func() {
var loadedRunner *fake_runner.TestRunner
示例10:
expectedTTL := 30 * time.Second
Eventually(workerDB.SaveWorkerCallCount()).Should(Equal(1))
workerInfo, ttl := workerDB.SaveWorkerArgsForCall(0)
Expect(workerInfo).To(Equal(expectedWorkerInfo))
Expect(ttl).To(Equal(expectedTTL))
ginkgomon.Interrupt(process)
fakeClock.Increment(11 * time.Second)
Consistently(workerDB.SaveWorkerCallCount).Should(Equal(1))
})
})
Context("if saving to the DB fails", func() {
disaster := errors.New("bad bad bad")
BeforeEach(func() {
workerDB.SaveWorkerReturns(db.SavedWorker{}, disaster)
})
It("exits early", func() {
runner := worker.NewHardcoded(logger, workerDB, fakeClock, gardenAddr, baggageClaimAddr, resourceTypes)
process = ifrit.Invoke(runner)
Expect(<-process.Wait()).To(Equal(disaster))
})
})
})
示例11:
fakeClock = fakeclock.NewFakeClock(time.Unix(0, 123))
trackerRunner = TrackerRunner{
Tracker: fakeTracker,
Interval: interval,
Clock: fakeClock,
}
})
JustBeforeEach(func() {
process = ifrit.Invoke(trackerRunner)
})
AfterEach(func() {
process.Signal(os.Interrupt)
<-process.Wait()
})
It("tracks immediately", func() {
<-tracked
})
Context("when the interval elapses", func() {
JustBeforeEach(func() {
<-tracked
fakeClock.Increment(interval)
})
It("tracks", func() {
<-tracked
Consistently(tracked).ShouldNot(Receive())
示例12: untilTerminated
func untilTerminated(logger lager.Logger, process ifrit.Process) {
err := <-process.Wait()
exitOnFailure(logger, err)
}
示例13:
})
It("uses the input source for all steps", func() {
Ω(fakeStepA.UsingCallCount()).Should(Equal(1))
step, repo := fakeStepA.UsingArgsForCall(0)
Ω(step).Should(Equal(inStep))
Ω(repo).Should(Equal(repo))
Ω(fakeStepB.UsingCallCount()).Should(Equal(1))
step, repo = fakeStepB.UsingArgsForCall(0)
Ω(step).Should(Equal(inStep))
Ω(repo).Should(Equal(repo))
})
It("exits successfully", func() {
Eventually(process.Wait()).Should(Receive(BeNil()))
})
Describe("executing each source", func() {
BeforeEach(func() {
wg := new(sync.WaitGroup)
wg.Add(2)
outStepA.RunStub = func(signals <-chan os.Signal, ready chan<- struct{}) error {
wg.Done()
wg.Wait()
close(ready)
return nil
}
outStepB.RunStub = func(signals <-chan os.Signal, ready chan<- struct{}) error {
示例14:
}))
})
})
})
})
Context("when the service has already been registered", func() {
BeforeEach(func() {
oldregistration := *registration
oldregistration.Port = 9000
err := consulClient.Agent().ServiceRegister(&oldregistration)
Expect(err).NotTo(HaveOccurred())
})
It("does not exit", func() {
Consistently(registrationProcess.Wait()).ShouldNot(Receive())
})
It("updates the service", func() {
services, err := consulClient.Agent().Services()
Expect(err).NotTo(HaveOccurred())
service, ok := services[registration.ID]
Expect(ok).To(BeTrue())
Expect(*service).To(Equal(api.AgentService{
ID: registration.ID,
Service: registration.Name,
Tags: registration.Tags,
Port: registration.Port,
Address: registration.Address,
}))
})
示例15:
{Guid: "container-2"},
{Guid: "container-3"},
}, nil)
})
JustBeforeEach(func() {
reporter = ifrit.Envoke(&metrics.Reporter{
ExecutorSource: executorClient,
Interval: reportInterval,
Logger: logger,
})
})
AfterEach(func() {
reporter.Signal(os.Interrupt)
Eventually(reporter.Wait()).Should(Receive())
})
It("reports the current capacity on the given interval", func() {
Eventually(func() fake.Metric {
return sender.GetValue("CapacityTotalMemory")
}, reportInterval*2).Should(Equal(fake.Metric{
Value: 1024,
Unit: "MiB",
}))
Eventually(func() fake.Metric {
return sender.GetValue("CapacityTotalDisk")
}, reportInterval*2).Should(Equal(fake.Metric{
Value: 2048,
Unit: "MiB",