func TestNilStatusProcessWithIgnorePrepareReply(t *testing.T) {
	inst := commonTestlibExampleNilStatusInstance()
	instBallot := message.NewBallot(2, 2, inst.replica.Id)
	inst.ballot = instBallot
	pr := &message.PrepareReply{}
	action, m := inst.nilStatusProcess(pr)
	assert.Equal(t, action, noAction)
	assert.Equal(t, m, nil)
}
This function asserts that one instance will ignore a prepare-reply message
if the instance is not at initial round, which means it must have been reverted from
preparing, so the prepare-reply message is stale.
package replica
import (
	"fmt"
	"testing"
	"github.com/go-distributed/epaxos/message"
	"github.com/go-distributed/epaxos/test"
	"github.com/go-distributed/epaxos/transporter"
	"github.com/stretchr/testify/assert"
)
var _ = fmt.Printf
func commonTestlibExampleCommands() message.Commands {
	return message.Commands{
		message.Command("hello"),
	}
}
func commonTestlibExampleDeps() message.Dependencies {
	return message.Dependencies{
		1, 2, 1, 1, 8,
	}
}
func commonTestlibUnionedDeps() message.Dependencies {
	deps := commonTestlibExampleDeps()
	deps.Union(message.Dependencies{
		0, 1, 2, 3, 4,
	})
	return deps
}
func commonTestlibExampleReplica() *Replica {
	param := &Param{
		ReplicaId:    0,
		Size:         5,
		StateMachine: new(test.DummySM),
		Transporter:  transporter.NewDummyTR(0, 5),
	}
	r, _ := New(param)
	return r
}
func commonTestlibExampleInstance() *Instance {
	param := &Param{
		ReplicaId:    0,
		Size:         5,
		StateMachine: new(test.DummySM),
		Transporter:  transporter.NewDummyTR(0, 5),
	}
	r, err := New(param)
	if err != nil {
		panic(err)
	}
	i := NewInstance(r, r.Id+1, conflictNotFound+1)  
	return i
}
func commonTestlibExampleNilStatusInstance() *Instance {
	return commonTestlibExampleInstance()
}
func commonTestlibExamplePreAcceptedInstance() *Instance {
	i := commonTestlibExampleInstance()
	i.status = preAccepted
	i.ballot = i.replica.makeInitialBallot()
	i.cmds = message.Commands{
		message.Command("world"),
	}
	i.deps = message.Dependencies{
		0, 1, 2, 3, 4,
	}
	return i
}
func commonTestlibExampleAcceptedInstance() *Instance {
	i := commonTestlibExampleInstance()
	i.status = accepted
	i.ballot = i.replica.makeInitialBallot()
	i.cmds = message.Commands{
		message.Command("world"),
	}
	i.deps = message.Dependencies{
		0, 1, 2, 3, 4,
	}
	return i
}
func commonTestlibExampleCommittedInstance() *Instance {
	i := commonTestlibExampleInstance()
	i.status = committed
	i.ballot = i.replica.makeInitialBallot()
	i.cmds = message.Commands{
		message.Command("world"),
	}
	i.deps = message.Dependencies{
		0, 1, 2, 3, 4,
	}
	return i
}
func commonTestlibExamplePreparingInstance() *Instance {
	i := commonTestlibExampleInstance()
	i.enterPreparing()
	return i
}
func commonTestlibCloneInstance(inst *Instance) *Instance {
	copyInstanceInfo := &InstanceInfo{
		samePreAcceptReplies: inst.info.samePreAcceptReplies,
		preAcceptOkCount:     inst.info.preAcceptOkCount,
		preAcceptReplyCount:  inst.info.preAcceptReplyCount,
		acceptReplyCount:     inst.info.acceptReplyCount,
	}
	ir := inst.recoveryInfo
	copyReceveryInfo := NewRecoveryInfo()
	if inst.status == preparing {
		copyReceveryInfo = &RecoveryInfo{
			identicalCount: ir.identicalCount,
			replyCount:     ir.replyCount,
			ballot:         ir.ballot.Clone(),
			cmds:           ir.cmds.Clone(),
			deps:           ir.deps.Clone(),
			status:         ir.status,
			formerStatus:   ir.formerStatus,
		}
	}
	return &Instance{
		cmds:         inst.cmds.Clone(),
		deps:         inst.deps.Clone(),
		status:       inst.status,
		ballot:       inst.ballot.Clone(),
		info:         copyInstanceInfo,
		recoveryInfo: copyReceveryInfo,
		replica:      inst.replica,
		rowId:        inst.rowId,
		id:           inst.id,
		executed:     inst.executed,
		lastTouched:  inst.lastTouched,
	}
}
func TestNewInstance(t *testing.T) {
	expectedReplicaId := uint8(0)
	expectedInstanceId := uint64(1)
	param := &Param{
		ReplicaId:    expectedReplicaId,
		Size:         5,
		StateMachine: new(test.DummySM),
		Transporter:  transporter.NewDummyTR(expectedReplicaId, 5),
	}
	r, _ := New(param)
	i := NewInstance(r, expectedReplicaId, expectedInstanceId)
	assert.Equal(t, i.replica.Id, expectedReplicaId)
	assert.Equal(t, i.rowId, expectedReplicaId)
	assert.Equal(t, i.id, expectedInstanceId)
	assert.Equal(t, i.deps, i.replica.makeInitialDeps())
}
func TestNilStatusProcessWithHandlePropose(t *testing.T) {
	p := &message.Propose{
		Cmds: commonTestlibExampleCommands(),
	}
	instWithBallot := commonTestlibExampleNilStatusInstance()
	instWithBallot.ballot = instWithBallot.replica.makeInitialBallot()
	assert.Panics(t, func() { instWithBallot.nilStatusProcess(p) })
	preAcceptedInstance := commonTestlibExamplePreAcceptedInstance()
	assert.Panics(t, func() { preAcceptedInstance.nilStatusProcess(p) })
	i := commonTestlibExampleNilStatusInstance()
	i.rowId = i.replica.Id  
	assert.Panics(t, func() { i.nilStatusProcess(&message.Propose{}) })
	action, m := i.nilStatusProcess(p)
	if !assert.IsType(t, &message.PreAccept{}, m) {
		t.Fatal("")
	}
	pa := m.(*message.PreAccept)
	assert.Equal(t, i.status, preAccepted)
	assert.Equal(t, action, fastQuorumAction)
	assert.Equal(t, pa, &message.PreAccept{
		ReplicaId:  i.rowId,
		InstanceId: i.id,
		Cmds:       commonTestlibExampleCommands(),
		Deps:       i.deps,
		Ballot:     i.replica.makeInitialBallot(),
	})
	assert.Equal(t, i.info.preAcceptReplyCount, 0)
	assert.True(t, i.info.samePreAcceptReplies)
}
func TestNilStatusProcessWithIgnorePreAccept(t *testing.T) {
	inst := commonTestlibExampleNilStatusInstance()
	smallerBallot := message.NewBallot(2, 2, inst.replica.Id)
	largerBallot := message.NewBallot(2, 4, inst.replica.Id)
	inst.ballot = largerBallot
	p := &message.PreAccept{
		Ballot: smallerBallot,
	}
	action, m := inst.nilStatusProcess(p)
	assert.Equal(t, action, noAction)
	assert.Equal(t, m, nil)
}
func TestNilStatusProcessWithHandlePreAccept(t *testing.T) {
	inst := commonTestlibExampleNilStatusInstance()
	smallerBallot := message.NewBallot(2, 2, inst.replica.Id)
	largerBallot := message.NewBallot(2, 4, inst.replica.Id)
	expectedDeps := message.Dependencies{5, 0, 0, 0, 0}
	expectedCmds := commonTestlibExampleCommands()
	inst.ballot = smallerBallot
	p := &message.PreAccept{
		Cmds:   expectedCmds,
		Deps:   expectedDeps,
		Ballot: largerBallot,
	}
	action, m := inst.nilStatusProcess(p)
	assert.Equal(t, action, replyAction)
	assert.Equal(t, m, &message.PreAcceptReply{
		ReplicaId:  inst.rowId,
		InstanceId: inst.id,
		Ballot:     largerBallot,
		Deps:       expectedDeps,
	})
}
func TestNilStatusProcessWithIgnoreAccept(t *testing.T) {
	inst := commonTestlibExampleNilStatusInstance()
	smallerBallot := message.NewBallot(2, 2, inst.replica.Id)
	largerBallot := message.NewBallot(2, 4, inst.replica.Id)
	inst.ballot = largerBallot
	ac := &message.Accept{
		Ballot: smallerBallot,
	}
	action, m := inst.nilStatusProcess(ac)
	assert.Equal(t, action, noAction)
	assert.Equal(t, m, nil)
}
func TestNilStatusProcessWithHandleAccept(t *testing.T) {
	inst := commonTestlibExampleNilStatusInstance()
	smallerBallot := message.NewBallot(2, 2, inst.replica.Id)
	largerBallot := message.NewBallot(2, 4, inst.replica.Id)
	inst.ballot = smallerBallot
	expectedDeps := message.Dependencies{5, 0, 0, 0, 0}
	expectedCmds := commonTestlibExampleCommands()
	ac := &message.Accept{
		Cmds:   expectedCmds,
		Deps:   expectedDeps,
		Ballot: largerBallot,
	}
	action, m := inst.nilStatusProcess(ac)
	assert.Equal(t, action, replyAction)
	assert.Equal(t, m, &message.AcceptReply{
		ReplicaId:  inst.rowId,
		InstanceId: inst.id,
		Ballot:     largerBallot,
	})
}
func TestNilStatusProcessWithHandleCommit(t *testing.T) {
	inst := commonTestlibExampleNilStatusInstance()
	instBallot := message.NewBallot(2, 4, inst.replica.Id)
	inst.ballot = instBallot
	expectedDeps := message.Dependencies{5, 0, 0, 0, 0}
	expectedCmds := commonTestlibExampleCommands()
	cm := &message.Commit{
		Cmds: expectedCmds,
		Deps: expectedDeps,
	}
	action, m := inst.nilStatusProcess(cm)
	assert.Equal(t, action, noAction)
	assert.Nil(t, m)
}
func TestNilStatusProcessWithIgnorePrepare(t *testing.T) {
	inst := commonTestlibExampleNilStatusInstance()
	smallerBallot := message.NewBallot(2, 2, inst.replica.Id)
	largerBallot := message.NewBallot(2, 4, inst.replica.Id)
	inst.ballot = largerBallot
	p := &message.Prepare{
		Ballot: smallerBallot,
	}
	action, m := inst.nilStatusProcess(p)
	assert.Equal(t, action, noAction)
	assert.Equal(t, m, nil)
}
func TestNilStatusProcessWithHandlePrepare(t *testing.T) {
	inst := commonTestlibExampleNilStatusInstance()
	smallerBallot := message.NewBallot(2, 2, inst.replica.Id)
	largerBallot := message.NewBallot(2, 4, inst.replica.Id)
	expectedDeps := message.Dependencies{5, 0, 0, 0, 0}
	expectedCmds := commonTestlibExampleCommands()
	inst.cmds = expectedCmds
	inst.deps = expectedDeps
	inst.ballot = smallerBallot
	p := &message.Prepare{
		ReplicaId:  inst.rowId,
		InstanceId: inst.id,
		Ballot:     largerBallot,
	}
	action, m := inst.nilStatusProcess(p)
	assert.Equal(t, action, replyAction)
	assert.Equal(t, m, &message.PrepareReply{
		ReplicaId:      inst.rowId,
		InstanceId:     inst.id,
		Status:         nilStatus,
		Cmds:           expectedCmds,
		Deps:           expectedDeps,
		Ballot:         largerBallot,
		OriginalBallot: smallerBallot,
		IsFromLeader:   false,
	})
}