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

Function TestTwoPhaseCommit

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

Source from the content-addressed store, hash-verified

418}
419
420func TestTwoPhaseCommit(t *testing.T) {
421 c := twopc.NewCoordinator(twopc.NewOptions(5 * time.Second))
422
423 testNodeReset()
424
425 policy = AllGood
426 res, err := c.Put(nodes, &RaftWriteBatchReq{TxID: 0, Cmds: []string{"+1", "-3", "+10"}})
427
428 if err != nil {
429 t.Fatalf("error occurred: %s", err.Error())
430 }
431
432 if res.(int64) != 8 {
433 t.Fatalf("TwoPC returns invalid result: %v", res)
434 }
435
436 testNodeReset()
437
438 policy = FailOnPrepare
439 res, err = c.Put(nodes, &RaftWriteBatchReq{TxID: 1, Cmds: []string{"-3", "-4", "+1"}})
440
441 if err == nil {
442 t.Fatal("unexpected result: returned nil while expecting an error")
443 } else {
444 t.Logf("Error occurred as expected: %s", err.Error())
445 }
446
447 testNodeReset()
448
449 policy = FailOnCommit
450 res, err = c.Put(nodes, &RaftWriteBatchReq{TxID: 2, Cmds: []string{"-5", "+9", "+1"}})
451
452 if err == nil {
453 t.Fatal("unexpected result: returned nil while expecting an error")
454 } else {
455 t.Logf("Error occurred as expected: %s", err.Error())
456 }
457}
458
459func TestTwoPhaseCommit_WithHooks(t *testing.T) {
460 errorBeforePrepare := false

Callers

nothing calls this directly

Calls 7

PutMethod · 0.95
NewCoordinatorFunction · 0.92
NewOptionsFunction · 0.92
testNodeResetFunction · 0.85
FatalfMethod · 0.80
ErrorMethod · 0.80
FatalMethod · 0.80

Tested by

no test coverage detected