@@ -21,10 +21,15 @@ import (
21
21
"testing"
22
22
"time"
23
23
24
+ "math"
25
+
24
26
"github.com/golang/protobuf/proto"
25
27
"github.com/op/go-logging"
26
28
)
27
29
30
+ const lowN uint64 = 4 //keep lowN greater or equal to 4
31
+ const highN uint64 = 10 //keep highN greater or equal to 10
32
+
28
33
var testLog = logging .MustGetLogger ("test" )
29
34
30
35
func init () {
@@ -69,7 +74,7 @@ func connectAll(sys *testSystem) {
69
74
70
75
func TestSBFT (t * testing.T ) {
71
76
skipInShortMode (t )
72
- N := uint64 ( 4 )
77
+ N := lowN
73
78
sys := newTestSystem (N )
74
79
var repls []* SBFT
75
80
var adapters []* testSystemAdapter
@@ -104,9 +109,47 @@ func TestSBFT(t *testing.T) {
104
109
}
105
110
}
106
111
112
+ func TestQuorumSizes (t * testing.T ) {
113
+ for N := uint64 (1 ); N < 100 ; N ++ {
114
+ for f := uint64 (0 ); f <= uint64 (math .Floor (float64 (N - 1 )/ float64 (3 ))); f ++ {
115
+ sys := newTestSystem (N )
116
+ a := sys .NewAdapter (0 )
117
+ s , err := New (0 , & Config {N : N , F : f , BatchDurationNsec : 2000000000 , BatchSizeBytes : 10 , RequestTimeoutNsec : 20000000000 }, a )
118
+ if err != nil {
119
+ t .Fatal (err )
120
+ }
121
+ if uint64 (2 * s .commonCaseQuorum ())- N < f + 1 {
122
+ t .Fatal ("insufficient intersection of two common case quorums" , "N = " , N , " F = " , f )
123
+ }
124
+ if uint64 (s .commonCaseQuorum ()+ s .viewChangeQuorum ())- N < f + 1 {
125
+ t .Fatal ("insufficient intersection of common case and view change quorums" , "N = " , N , " F = " , f )
126
+ }
127
+ if f < uint64 (math .Floor (float64 (N - 1 )/ float64 (3 ))) {
128
+ //end test for unoptimized f
129
+ continue
130
+ }
131
+ //test additionally when f is optimized
132
+ switch int (math .Mod (float64 (N ), float64 (3 ))) {
133
+ case 1 :
134
+ if s .commonCaseQuorum () != int (N - f ) || s .viewChangeQuorum () != int (N - f ) {
135
+ t .Fatal ("quorum sizes are wrong in default case N mod 3 == 1" )
136
+ }
137
+ case 2 :
138
+ if s .viewChangeQuorum () >= s .commonCaseQuorum () || s .viewChangeQuorum () >= int (N - f ) {
139
+ t .Fatal ("view change quorums size not optimized when N mod 3 == 2" )
140
+ }
141
+ case 3 :
142
+ if s .commonCaseQuorum () >= int (N - f ) || s .viewChangeQuorum () >= int (N - f ) {
143
+ t .Fatal ("quorum sizes not optimized when N mod 3 == 3" )
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+
107
150
func TestSBFTDelayed (t * testing.T ) {
108
151
skipInShortMode (t )
109
- N := uint64 ( 4 )
152
+ N := lowN
110
153
sys := newTestSystem (N )
111
154
var repls []* SBFT
112
155
var adapters []* testSystemAdapter
@@ -177,7 +220,7 @@ func TestN1(t *testing.T) {
177
220
178
221
func TestMonotonicViews (t * testing.T ) {
179
222
skipInShortMode (t )
180
- N := uint64 ( 4 )
223
+ N := lowN
181
224
sys := newTestSystem (N )
182
225
var repls []* SBFT
183
226
var adapters []* testSystemAdapter
@@ -211,7 +254,7 @@ func TestMonotonicViews(t *testing.T) {
211
254
}
212
255
}
213
256
214
- func TestByzPrimary (t * testing.T ) {
257
+ func TestByzPrimaryN4 (t * testing.T ) {
215
258
skipInShortMode (t )
216
259
N := uint64 (4 )
217
260
sys := newTestSystem (N )
@@ -320,7 +363,7 @@ func TestNewPrimaryHandlingViewChange(t *testing.T) {
320
363
321
364
func TestByzPrimaryBullyingSingleReplica (t * testing.T ) {
322
365
skipInShortMode (t )
323
- N := uint64 ( 10 )
366
+ N := highN
324
367
sys := newTestSystem (N )
325
368
var repls []* SBFT
326
369
var adapters []* testSystemAdapter
@@ -369,7 +412,7 @@ func TestByzPrimaryBullyingSingleReplica(t *testing.T) {
369
412
370
413
func TestViewChange (t * testing.T ) {
371
414
skipInShortMode (t )
372
- N := uint64 ( 4 )
415
+ N := lowN
373
416
sys := newTestSystem (N )
374
417
var repls []* SBFT
375
418
var adapters []* testSystemAdapter
@@ -409,7 +452,7 @@ func TestViewChange(t *testing.T) {
409
452
410
453
func TestMsgReordering (t * testing.T ) {
411
454
skipInShortMode (t )
412
- N := uint64 ( 4 )
455
+ N := lowN
413
456
sys := newTestSystem (N )
414
457
var repls []* SBFT
415
458
var adapters []* testSystemAdapter
@@ -462,7 +505,7 @@ func TestMsgReordering(t *testing.T) {
462
505
463
506
func TestBacklogReordering (t * testing.T ) {
464
507
skipInShortMode (t )
465
- N := uint64 ( 4 )
508
+ N := lowN
466
509
sys := newTestSystem (N )
467
510
var repls []* SBFT
468
511
var adapters []* testSystemAdapter
@@ -515,7 +558,7 @@ func TestBacklogReordering(t *testing.T) {
515
558
516
559
func TestViewChangeWithRetransmission (t * testing.T ) {
517
560
skipInShortMode (t )
518
- N := uint64 ( 4 )
561
+ N := lowN
519
562
sys := newTestSystem (N )
520
563
var repls []* SBFT
521
564
var adapters []* testSystemAdapter
@@ -555,7 +598,7 @@ func TestViewChangeWithRetransmission(t *testing.T) {
555
598
556
599
func TestViewChangeXset (t * testing.T ) {
557
600
skipInShortMode (t )
558
- N := uint64 ( 4 )
601
+ N := lowN
559
602
sys := newTestSystem (N )
560
603
var repls []* SBFT
561
604
var adapters []* testSystemAdapter
@@ -632,7 +675,7 @@ func TestViewChangeXset(t *testing.T) {
632
675
633
676
func TestRestart (t * testing.T ) {
634
677
skipInShortMode (t )
635
- N := uint64 ( 4 )
678
+ N := lowN
636
679
sys := newTestSystem (N )
637
680
var repls []* SBFT
638
681
var adapters []* testSystemAdapter
@@ -686,7 +729,7 @@ func TestRestart(t *testing.T) {
686
729
687
730
func TestAbdicatingPrimary (t * testing.T ) {
688
731
skipInShortMode (t )
689
- N := uint64 ( 4 )
732
+ N := lowN
690
733
sys := newTestSystem (N )
691
734
var repls []* SBFT
692
735
var adapters []* testSystemAdapter
@@ -745,7 +788,7 @@ func TestAbdicatingPrimary(t *testing.T) {
745
788
746
789
func TestRestartAfterPrepare (t * testing.T ) {
747
790
skipInShortMode (t )
748
- N := uint64 ( 4 )
791
+ N := lowN
749
792
sys := newTestSystem (N )
750
793
var repls []* SBFT
751
794
var adapters []* testSystemAdapter
@@ -815,7 +858,7 @@ func TestRestartAfterPrepare(t *testing.T) {
815
858
816
859
func TestRestartAfterCommit (t * testing.T ) {
817
860
skipInShortMode (t )
818
- N := uint64 ( 4 )
861
+ N := lowN
819
862
sys := newTestSystem (N )
820
863
var repls []* SBFT
821
864
var adapters []* testSystemAdapter
@@ -885,7 +928,7 @@ func TestRestartAfterCommit(t *testing.T) {
885
928
886
929
func TestRestartAfterCheckpoint (t * testing.T ) {
887
930
skipInShortMode (t )
888
- N := uint64 ( 4 )
931
+ N := lowN
889
932
sys := newTestSystem (N )
890
933
var repls []* SBFT
891
934
var adapters []* testSystemAdapter
@@ -955,7 +998,7 @@ func TestRestartAfterCheckpoint(t *testing.T) {
955
998
956
999
func TestErroneousViewChange (t * testing.T ) {
957
1000
skipInShortMode (t )
958
- N := uint64 ( 4 )
1001
+ N := lowN
959
1002
sys := newTestSystem (N )
960
1003
var repls []* SBFT
961
1004
var adapters []* testSystemAdapter
@@ -1045,7 +1088,7 @@ func TestErroneousViewChange(t *testing.T) {
1045
1088
1046
1089
func TestRestartMissedViewChange (t * testing.T ) {
1047
1090
skipInShortMode (t )
1048
- N := uint64 ( 4 )
1091
+ N := lowN
1049
1092
sys := newTestSystem (N )
1050
1093
var repls []* SBFT
1051
1094
var adapters []* testSystemAdapter
@@ -1118,7 +1161,7 @@ func TestRestartMissedViewChange(t *testing.T) {
1118
1161
1119
1162
func TestFullBacklog (t * testing.T ) {
1120
1163
skipInShortMode (t )
1121
- N := uint64 ( 4 )
1164
+ N := lowN
1122
1165
sys := newTestSystem (N )
1123
1166
var repls []* SBFT
1124
1167
var adapters []* testSystemAdapter
@@ -1160,7 +1203,7 @@ func TestFullBacklog(t *testing.T) {
1160
1203
1161
1204
func TestHelloMsg (t * testing.T ) {
1162
1205
skipInShortMode (t )
1163
- N := uint64 ( 4 )
1206
+ N := lowN
1164
1207
sys := newTestSystemWOTimers (N )
1165
1208
var repls []* SBFT
1166
1209
var adapters []* testSystemAdapter
@@ -1227,7 +1270,7 @@ func TestHelloMsg(t *testing.T) {
1227
1270
1228
1271
func TestViewChangeTimer (t * testing.T ) {
1229
1272
skipInShortMode (t )
1230
- N := uint64 ( 4 )
1273
+ N := lowN
1231
1274
sys := newTestSystem (N )
1232
1275
var repls []* SBFT
1233
1276
var adapters []* testSystemAdapter
@@ -1311,7 +1354,7 @@ func TestViewChangeTimer(t *testing.T) {
1311
1354
1312
1355
func TestResendViewChange (t * testing.T ) {
1313
1356
skipInShortMode (t )
1314
- N := uint64 ( 4 )
1357
+ N := lowN
1315
1358
sys := newTestSystem (N )
1316
1359
var repls []* SBFT
1317
1360
var adapters []* testSystemAdapter
@@ -1371,7 +1414,7 @@ func TestResendViewChange(t *testing.T) {
1371
1414
1372
1415
func TestTenReplicasBombedWithRequests (t * testing.T ) {
1373
1416
skipInShortMode (t )
1374
- N := uint64 ( 10 )
1417
+ N := highN
1375
1418
requestNumber := 11
1376
1419
sys := newTestSystem (N )
1377
1420
var repls []* SBFT
0 commit comments