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


Golang testing.SetTestHooks函數代碼示例

本文整理匯總了Golang中github.com/juju/txn/testing.SetTestHooks函數的典型用法代碼示例。如果您正苦於以下問題:Golang SetTestHooks函數的具體用法?Golang SetTestHooks怎麽用?Golang SetTestHooks使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: TestClaimLease_Pathological

func (s *ClientSimpleRaceSuite) TestClaimLease_Pathological(c *gc.C) {
	sut := s.EasyFixture(c)
	blocker := s.NewFixture(c, FixtureParams{Id: "blocker"})

	// Set up hooks to claim a lease just before every transaction, but remove
	// it again before the SUT goes and looks to figure out what it should do.
	interfere := jujutxn.TestHook{
		Before: func() {
			err := blocker.Client.ClaimLease("name", lease.Request{"ha-haa", time.Second})
			c.Check(err, jc.ErrorIsNil)
		},
		After: func() {
			blocker.Clock.Advance(time.Minute)
			err := blocker.Client.ExpireLease("name")
			c.Check(err, jc.ErrorIsNil)
		},
	}
	defer txntesting.SetTestHooks(
		c, sut.Runner,
		interfere, interfere, interfere,
	)()

	// Try to claim, and watch the poor thing collapse in exhaustion.
	err := sut.Client.ClaimLease("name", lease.Request{"trying", time.Minute})
	c.Check(err, gc.ErrorMatches, "state changing too quickly; try again soon")
}
開發者ID:Pankov404,項目名稱:juju,代碼行數:26,代碼來源:client_race_test.go

示例2: TestExtendLease_Pathological

func (s *ClientTrickyRaceSuite) TestExtendLease_Pathological(c *gc.C) {

	// Set up hooks to remove the lease just before every transaction, but
	// replace it before the SUT goes and looks to figure out what it should do.
	interfere := jujutxn.TestHook{
		Before: func() {
			s.blocker.Clock.Advance(time.Minute + time.Second)
			err := s.blocker.Client.ExpireLease("name")
			c.Check(err, jc.ErrorIsNil)
		},
		After: func() {
			err := s.blocker.Client.ClaimLease("name", lease.Request{"holder", time.Second})
			c.Check(err, jc.ErrorIsNil)
		},
	}
	defer txntesting.SetTestHooks(
		c, s.sut.Runner,
		interfere, interfere, interfere,
	)()

	// Try to extend, and watch the poor thing collapse in exhaustion.
	err := s.sut.Client.ExtendLease("name", lease.Request{"holder", time.Minute})
	c.Check(err, gc.ErrorMatches, "state changing too quickly; try again soon")
}
開發者ID:Pankov404,項目名稱:juju,代碼行數:24,代碼來源:client_race_test.go

示例3: SetTestHooks

func SetTestHooks(c *gc.C, st *State, hooks ...jujutxn.TestHook) txntesting.TransactionChecker {
	runner := jujutxn.NewRunner(jujutxn.RunnerParams{Database: st.db})
	st.transactionRunner = runner
	return txntesting.SetTestHooks(c, runner, hooks...)
}
開發者ID:zhouqt,項目名稱:juju,代碼行數:5,代碼來源:export_test.go

示例4: SetTestHooks

func SetTestHooks(c *gc.C, st *State, hooks ...jujutxn.TestHook) txntesting.TransactionChecker {
	return txntesting.SetTestHooks(c, newRunnerForHooks(st), hooks...)
}
開發者ID:makyo,項目名稱:juju,代碼行數:3,代碼來源:export_test.go

示例5: SetTestHooks

func SetTestHooks(c *gc.C, st *State, hooks ...jujutxn.TestHook) txntesting.TransactionChecker {
	return txntesting.SetTestHooks(c, st.transactionRunner, hooks...)
}
開發者ID:klyachin,項目名稱:juju,代碼行數:3,代碼來源:export_test.go


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