예제 #1
0
파일: txn_test.go 프로젝트: juju/txn
func (s *txnSuite) TestRunTransactionObserver(c *gc.C) {
	type args struct {
		ops []txn.Op
		err error
	}
	var calls []args
	runner := jujutxn.NewRunner(jujutxn.RunnerParams{
		RunTransactionObserver: func(ops []txn.Op, err error) {
			calls = append(calls, args{ops, err})
		},
	})
	fake := &fakeRunner{errors: []error{
		txn.ErrAborted,
		nil,
	}}
	jujutxn.SetRunnerFunc(runner, fake.new)
	ops := []txn.Op{{}}
	buildTxn := func(attempt int) ([]txn.Op, error) {
		return ops, nil
	}
	err := runner.Run(buildTxn)
	c.Check(err, gc.IsNil)
	c.Check(calls, gc.HasLen, 2)
	c.Check(calls[0].ops, gc.DeepEquals, ops)
	c.Check(calls[0].err, gc.Equals, txn.ErrAborted)
	c.Check(calls[1].ops, gc.DeepEquals, ops)
	c.Check(calls[1].err, gc.IsNil)
}
예제 #2
0
파일: txn_test.go 프로젝트: juju/txn
func (s *txnSuite) TestRunFailureIntermittentUnexpectedMessage(c *gc.C) {
	runner := jujutxn.NewRunner(jujutxn.RunnerParams{})
	fake := &fakeRunner{errors: []error{errors.New("unexpected message")}}
	jujutxn.SetRunnerFunc(runner, fake.new)
	tries := 0
	// Doesn't matter what this returns as long as it isn't an error.
	buildTxn := func(attempt int) ([]txn.Op, error) {
		tries++
		return nil, nil
	}
	err := runner.Run(buildTxn)
	c.Check(err, gc.Equals, nil)
	c.Check(tries, gc.Equals, 2)
}