MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestTwoPhaseCommit_WithHooks

Function TestTwoPhaseCommit_WithHooks

twopc/twopc_test.go:459–551  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

457}
458
459func TestTwoPhaseCommit_WithHooks(t *testing.T) {
460 errorBeforePrepare := false
461 beforePrepareError := errors.New("before prepare error")
462 errorBeforeCommit := false
463 beforeCommitError := errors.New("before commit error")
464 errorBeforeRollback := false
465 beforeRollbackError := errors.New("before rollback error")
466 policy = AllGood
467
468 c := twopc.NewCoordinator(twopc.NewOptionsWithCallback(
469 5*time.Second,
470 func(cxt context.Context) error {
471 if errorBeforePrepare {
472 return beforePrepareError
473 }
474
475 return nil
476 }, // before prepare
477 func(ctx context.Context) error {
478 if errorBeforeCommit {
479 return beforeCommitError
480 }
481
482 return nil
483 }, // before commit
484 func(ctx context.Context) error {
485 if errorBeforeRollback {
486 return beforeRollbackError
487 }
488
489 return nil
490 }, // before rollback
491 nil))
492
493 testNodeReset()
494
495 res, err := c.Put(nodes, &RaftWriteBatchReq{TxID: 0, Cmds: []string{"+1", "-3", "+10"}})
496 if err != nil {
497 t.Fatalf("error occurred: %s", err.Error())
498 }
499
500 if res.(int64) != 8 {
501 t.Fatalf("TwoPC returns invalid result: %v", res)
502 }
503
504 // error before prepare
505 errorBeforePrepare = true
506 errorBeforeCommit = false
507 errorBeforeRollback = false
508
509 testNodeReset()
510
511 res, err = c.Put(nodes, &RaftWriteBatchReq{TxID: 1, Cmds: []string{"+1", "-3", "+10"}})
512 if err == nil {
513 t.Fatal("unexpected result: returned nil while expecting an error")
514 } else if err != beforePrepareError {
515 t.Fatal("unexpected result: beforePrepare error is expected")
516 } else {

Callers

nothing calls this directly

Calls 8

PutMethod · 0.95
NewCoordinatorFunction · 0.92
NewOptionsWithCallbackFunction · 0.92
testNodeResetFunction · 0.85
FatalfMethod · 0.80
ErrorMethod · 0.80
FatalMethod · 0.80
NewMethod · 0.65

Tested by

no test coverage detected