本文整理匯總了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")
}
示例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")
}
示例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...)
}
示例4: SetTestHooks
func SetTestHooks(c *gc.C, st *State, hooks ...jujutxn.TestHook) txntesting.TransactionChecker {
return txntesting.SetTestHooks(c, newRunnerForHooks(st), hooks...)
}
示例5: SetTestHooks
func SetTestHooks(c *gc.C, st *State, hooks ...jujutxn.TestHook) txntesting.TransactionChecker {
return txntesting.SetTestHooks(c, st.transactionRunner, hooks...)
}