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


Golang AgentClient.Stop方法代码示例

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


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

示例1:

	BeforeEach(func() {
		logger := boshlog.NewLogger(boshlog.LevelNone)
		fakeHTTPClient = fakehttpclient.NewFakeHTTPClient()
		toleratedErrorCount := 2
		agentClient = NewAgentClient("http://localhost:6305", "fake-uuid", 0, toleratedErrorCount, fakeHTTPClient, logger)
	})

	Describe("get_task", func() {
		Context("when the http client errors", func() {
			It("should retry", func() {
				fakeHTTPClient.SetPostBehavior(`{"value":{"agent_task_id":"fake-agent-task-id","state":"running"}}`, 200, nil)
				fakeHTTPClient.SetPostBehavior("", 0, errors.New("connection reset by peer"))
				fakeHTTPClient.SetPostBehavior("", 0, errors.New("connection reset by peer"))
				fakeHTTPClient.SetPostBehavior(`{"value":{"agent_task_id":"fake-agent-task-id","state":"running"}}`, 200, nil)
				fakeHTTPClient.SetPostBehavior(`{"value":"stopped"}`, 200, nil)
				err := agentClient.Stop()
				Expect(err).ToNot(HaveOccurred())
			})

			Context("when the http client errors more times than the error retry count", func() {
				It("should return the error", func() {
					fakeHTTPClient.SetPostBehavior(`{"value":{"agent_task_id":"fake-agent-task-id","state":"running"}}`, 200, nil)
					fakeHTTPClient.SetPostBehavior("", 0, errors.New("connection reset by peer 1"))
					fakeHTTPClient.SetPostBehavior("", 0, errors.New("connection reset by peer 2"))
					fakeHTTPClient.SetPostBehavior("", 0, errors.New("connection reset by peer 3"))
					err := agentClient.Stop()
					Expect(err).To(HaveOccurred())
					Expect(err.Error()).To(ContainSubstring("connection reset by peer 3"))
				})
			})
开发者ID:yingkitw,项目名称:bosh-agent,代码行数:30,代码来源:agent_client_test.go


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