當前位置: 首頁>>代碼示例>>Golang>>正文


Golang T.handleAddTask方法代碼示例

本文整理匯總了Golang中testing.T.handleAddTask方法的典型用法代碼示例。如果您正苦於以下問題:Golang T.handleAddTask方法的具體用法?Golang T.handleAddTask怎麽用?Golang T.handleAddTask使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在testing.T的用法示例。


在下文中一共展示了T.handleAddTask方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestTribeTaskAgreements

func TestTribeTaskAgreements(t *testing.T) {
	numOfTribes := 5
	tribes := getTribes(numOfTribes, nil)
	Convey(fmt.Sprintf("%d tribes are started", numOfTribes), t, func() {
		for i := 0; i < numOfTribes; i++ {
			log.Debugf("%v is reporting %v members", i, len(tribes[i].memberlist.Members()))
			So(len(tribes[0].memberlist.Members()), ShouldEqual, len(tribes[i].memberlist.Members()))
		}
		Convey("the cluster agrees on membership", func() {
			for i := 0; i < numOfTribes; i++ {
				So(
					len(tribes[0].memberlist.Members()),
					ShouldEqual,
					len(tribes[i].memberlist.Members()),
				)
				So(len(tribes[0].members), ShouldEqual, len(tribes[i].members))
			}

			agreementName := "agreement1"
			agreementName2 := "agreement2"
			task1 := agreement.Task{ID: uuid.New()}
			task2 := agreement.Task{ID: uuid.New()}
			Convey("a member handles", func() {
				t := tribes[0]
				t2 := tribes[1]
				Convey("an out of order 'add task' message", func() {
					msg := &taskMsg{
						LTime:         t.clock.Increment(),
						UUID:          uuid.New(),
						TaskID:        task1.ID,
						AgreementName: agreementName,
						Type:          addTaskMsgType,
					}
					b := t.handleAddTask(msg)
					So(b, ShouldEqual, true)
					t.broadcast(addTaskMsgType, msg, nil)
					So(len(t.intentBuffer), ShouldEqual, 1)
					err := t.AddTask(agreementName, task1)
					So(err.Error(), ShouldResemble, errAgreementDoesNotExist.Error())
					err = t.AddAgreement(agreementName)
					So(err, ShouldBeNil)
					So(len(t.intentBuffer), ShouldEqual, 0)
					So(len(t.agreements[agreementName].TaskAgreement.Tasks), ShouldEqual, 1)
					ok, _ := t.agreements[agreementName].TaskAgreement.Tasks.Contains(task1)
					So(ok, ShouldBeTrue)
					Convey("adding an existing task", func() {
						err := t.AddTask(agreementName, task1)
						So(err.Error(), ShouldResemble, errTaskAlreadyExists.Error())
						Convey("removing a task that doesn't exist", func() {
							err := t.RemoveTask(agreementName, agreement.Task{ID: uuid.New()})
							So(err.Error(), ShouldResemble, errTaskDoesNotExist.Error())
							err = t.RemoveTask("doesn't exist", task1)
							So(err.Error(), ShouldResemble, errAgreementDoesNotExist.Error())
							Convey("joining an agreement with tasks", func() {
								err := t.AddAgreement(agreementName2)
								So(err, ShouldBeNil)
								err = t.AddTask(agreementName2, task2)
								So(err, ShouldBeNil)
								err = t.JoinAgreement(agreementName, t.memberlist.LocalNode().Name)
								So(err, ShouldBeNil)
								err = t.JoinAgreement(agreementName, t2.memberlist.LocalNode().Name)
								So(err, ShouldBeNil)
								err = t.JoinAgreement(agreementName2, t.memberlist.LocalNode().Name)
								So(err, ShouldBeNil)
								So(len(t.members[t.memberlist.LocalNode().Name].TaskAgreements), ShouldEqual, 2)
								err = t.canJoinAgreement(agreementName2, t.memberlist.LocalNode().Name)
								So(err, ShouldBeNil)
								So(t.members[t.memberlist.LocalNode().Name].PluginAgreement, ShouldNotBeNil)
								So(len(t.members[t.memberlist.LocalNode().Name].TaskAgreements), ShouldEqual, 2)
								Convey("all members agree on tasks", func(c C) {
									var wg sync.WaitGroup
									for _, t := range tribes {
										wg.Add(1)
										go func(t *tribe) {
											defer wg.Done()
											for {
												if a, ok := t.agreements[agreementName]; ok {
													if ok, _ := a.TaskAgreement.Tasks.Contains(task1); ok {
														return
													}
												}
												time.Sleep(50 * time.Millisecond)
											}
										}(t)
									}
									wg.Wait()
									Convey("the agreement is queried for the state of a given task", func() {
										t := tribes[rand.Intn(numOfTribes)]
										resp := t.taskStateQuery(agreementName, task1.ID)
										So(resp, ShouldNotBeNil)
										responses := taskStateResponses{}
										for r := range resp.resp {
											responses = append(responses, r)
										}
										So(len(responses), ShouldEqual, 2)
										So(responses.State(), ShouldEqual, core.TaskSpinning)
										Convey("a member handles removing a task", func() {
											t := tribes[rand.Intn(numOfTribes)]
											ok, _ := t.agreements[agreementName].TaskAgreement.Tasks.Contains(task1)
											So(ok, ShouldBeTrue)
//.........這裏部分代碼省略.........
開發者ID:IRCody,項目名稱:snap,代碼行數:101,代碼來源:tribe_test.go


注:本文中的testing.T.handleAddTask方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。