@@ -37,6 +37,7 @@ func TestHandleCommit(t *testing.T) {
3737 Proposal : makeBlock (1 ),
3838 }
3939 c .acceptPreprepare (preprepare )
40+ c .state = StatePreprepared
4041 }
4142
4243 testCases := []struct {
@@ -83,6 +84,26 @@ func TestHandleCommit(t *testing.T) {
8384 }(),
8485 errFutureMessage ,
8586 },
87+ {
88+ // future message because still at StateAcceptRequest
89+ func () * testSystem {
90+ sys := NewTestSystemWithBackend (N , F )
91+
92+ for i , backend := range sys .backends {
93+ c := backend .engine .(* core )
94+
95+ // replica0 is still waiting for preprepare message
96+ // other replicas are at StatePrepared
97+ if i != 0 {
98+ toPreprepare (c )
99+ // change to prepared
100+ c .state = StatePrepared
101+ }
102+ }
103+ return sys
104+ }(),
105+ errFutureMessage ,
106+ },
86107 {
87108 // subject not match
88109 func () * testSystem {
@@ -124,6 +145,26 @@ func TestHandleCommit(t *testing.T) {
124145 }(),
125146 nil ,
126147 },
148+ {
149+ // jump state
150+ func () * testSystem {
151+ sys := NewTestSystemWithBackend (N , F )
152+
153+ for i , backend := range sys .backends {
154+ c := backend .engine .(* core )
155+ // should have subject for each backend
156+ toPreprepare (c )
157+
158+ // only replica0 stays at StatePreprepared
159+ // other replicas are at StatePrepared
160+ if i != 0 {
161+ c .state = StatePrepared
162+ }
163+ }
164+ return sys
165+ }(),
166+ nil ,
167+ },
127168 // TODO: double send message
128169 }
129170
@@ -135,17 +176,20 @@ OUTER:
135176 r0 := v0 .engine .(* core )
136177
137178 for i , v := range test .system .backends {
138- validator := v .Validators ().GetByIndex (uint64 (i ))
139- m , _ := Encode (v .engine .(* core ).subject )
140- if err := r0 .handleCommit (& message {
141- Code : msgCommit ,
142- Msg : m ,
143- Address : validator .Address (),
144- }, validator ); err != nil {
145- if err != test .expectedErr {
146- t .Error ("unexpected error: " , err )
179+ // send commit message to replica0 if has subject
180+ if v .engine .(* core ).subject != nil {
181+ validator := v .Validators ().GetByIndex (uint64 (i ))
182+ m , _ := Encode (v .engine .(* core ).subject )
183+ if err := r0 .handleCommit (& message {
184+ Code : msgCommit ,
185+ Msg : m ,
186+ Address : validator .Address (),
187+ }, validator ); err != nil {
188+ if err != test .expectedErr {
189+ t .Error ("unexpected error: " , err )
190+ }
191+ continue OUTER
147192 }
148- continue OUTER
149193 }
150194 }
151195
0 commit comments