-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsm_tester.pl
executable file
·918 lines (670 loc) · 21 KB
/
rsm_tester.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
#!/usr/bin/perl -w
use POSIX ":sys_wait_h";
use Getopt::Std;
use strict;
my @pid;
my @logs = ();
my @views = (); #expected views
my %in_views; #the number of views a node is expected to be present
my @p;
my $t;
my $always_kill = 0;
use sigtrap 'handler' => \&killprocess, 'HUP', 'INT', 'ABRT', 'QUIT', 'TERM';
sub paxos_log {
my $port = shift;
return "paxos-$port.log";
}
sub mydie {
my ($s) = @_;
killprocess() if ($always_kill);
die $s;
}
sub killprocess {
print "killprocess: forcestop all spawned processes...@pid \n";
kill 9, @pid;
}
sub cleanup {
kill 9, @pid;
unlink(@logs);
sleep 2;
}
sub spawn {
my ($p, @a) = @_;
my $aa = join("-", @a);
if (my $pid = fork) {
# parent
push( @logs, "$p-$aa.log" );
if( $p =~ /config_server/ ) {
push( @logs, paxos_log($a[1]) );
}
if( $p =~ /lock_server/ ) {
push( @logs, paxos_log($a[1]) );
}
return $pid;
} elsif (defined $pid) {
# child
open(STDOUT, ">>$p-$aa.log")
or mydie "Couln't redirect stout\n";
open(STDERR, ">&STDOUT")
or mydie "Couln't redirect stderr\n";
$| = 1;
print "$p @a\n";
exec "$p @a"
or mydie "Cannot start new $p @a $!\n";
} else {
mydie "Cannot fork: $!\n";
}
}
sub findPortFreeAndNotIn {
my @alreadyChosenPorts = @_;
my %portsHashMap = map { $_ => 1 } @alreadyChosenPorts;
my $r;
my $isPortUsed;
my $alreadyChosen;
my $randomStart;
if (!@alreadyChosenPorts) {
$randomStart = 1500; # if no ports chosen yet, start from small port
} else {
$randomStart = $alreadyChosenPorts[-1]; # else start from the last/biggest port
}
do {
$r = $randomStart + int(rand(10000));
$isPortUsed = qx(ss -nat | grep :$r); # there may be false positives (e.g., prefixes of port numbers will match) but it's OK
$alreadyChosen = exists($portsHashMap{$r});
if ($isPortUsed) { print "[PORTSELECT] Port $r BUSY: output was [$isPortUsed]\n"; }
if ($alreadyChosen) { print "[PORTSELECT] Port $r already chosen\n"; }
} until (!$isPortUsed and !$alreadyChosen and (!@alreadyChosenPorts or $r > $alreadyChosenPorts[-1])); # loop until the value is OK
return $r;
}
sub spawn_ls {
my $master = shift;
my $port = shift;
return spawn( "./lock_server", $master, $port );
}
sub spawn_config {
my $master = shift;
my $port = shift;
return spawn( "./config_server", $master, $port );
}
sub check_views {
my $l = shift;
my $v = shift;
my $last_v = shift;
open( LOG, "<$l" )
or mydie( "Failed: couldn't read $l" );
my @log = <LOG>;
close(LOG);
my @vs = @{$v};
my $i = 0;
my @last_view;
foreach my $line (@log) {
if( $line =~ /^done (\d+) ([\d\s]+)$/ ) {
my $num = $1;
my @view = split( /\s+/, $2 );
@last_view = @view;
if( $i > $#vs ) {
# let there be extra views
next;
}
my $e = $vs[$i];
my @expected = @{$e};
if( @expected != @view ) {
mydie( "Failed: In log $l at view $num is (@view), but expected $i (@expected)" );
}
$i++;
}
}
if( $i <= $#vs ) {
mydie( "Failed: In log $l, not enough views seen!" );
}
if( defined $last_v ) {
my @last_exp_v = @{$last_v};
if( @last_exp_v != @last_view ) {
mydie( "Failed: In log $l last view didn't match, got view @last_view, but expected @last_exp_v" );
}
}
}
sub get_num_views {
my $log = shift;
my $including = shift;
my $nv = `grep "done " $log | grep "$including" | wc -l`;
chomp $nv;
return $nv;
}
sub wait_for_view_change {
my $log = shift;
my $num_views = shift;
my $including = shift;
my $timeout = shift;
my $start = time();
while( (get_num_views( $log, $including ) < $num_views) and
($start + $timeout > time()) ) {
my $lastv = `grep done $log | tail -n 1`;
chomp $lastv;
print " Waiting for $including to be present in >=$num_views views in $log (Last view: $lastv)\n";
sleep 1;
}
if( get_num_views( $log, $including ) < $num_views) {
mydie( "Failed: Timed out waiting for $including to be in >=$num_views in log $log" );
}else{
print " Done: $including is in >=$num_views views in $log\n";
}
}
sub waitpid_to {
my $pid = shift;
my $to = shift;
my $start = time();
my $done_pid;
do {
sleep 1;
$done_pid = waitpid($pid, POSIX::WNOHANG);
} while( $done_pid <= 0 and (time() - $start) < $to );
if( $done_pid <= 0 ) {
kill 9,$pid;
mydie( "Failed: Timed out waiting for process $pid\n" );
} else {
return 1;
}
}
sub wait_and_check_expected_view($) {
my $v = shift;
push @views, $v;
for (my $i = 0; $i <=$#$v; $i++) {
$in_views{$v->[$i]}++;
}
foreach my $port (@$v) {
wait_for_view_change(paxos_log($port), $in_views{$port}, $port, 20);
}
foreach my $port (@$v) {
my $log = paxos_log($port);
check_views( $log, \@views );
}
}
sub start_nodes ($$){
@pid = ();
@logs = ();
@views = ();
#for (my $i = 0; $i <= $#p; $i++) {
# $in_views{$p[$i]} = 0;
#}
#for (my $i = 0; $i <= 70000; $i++) { # TODO HACK
# $in_views{$i} = 0;
#}
@p = ();
my $n = shift;
my $command = shift;
for (my $i = 0; $i < $n; $i++) {
my $goodport = findPortFreeAndNotIn(@p);
print "Port $goodport is free. Start lock server $i ASAP...\n";
$p[$i] = $goodport;
$in_views{$goodport} = 0;
if ($command eq "ls") {
@pid = (@pid, spawn_ls($p[0],$p[$i]));
print "Start lock_server on $p[$i]\n";
} elsif ($command eq "config_server"){
@pid = (@pid, spawn_config($p[0],$p[$i]));
print "Start config on $p[$i]\n";
}
sleep 1;
my @vv = @p[0..$i];
wait_and_check_expected_view(\@vv);
}
}
my %options;
getopts("s:k",\%options);
if (defined($options{s})) {
srand($options{s});
}
if (defined($options{k})) {
$always_kill = 1;
}
@p = (); # global variable for storing port numbers. Expected to be sorted.
my @do_run = ();
my $NUM_TESTS = 17;
# see which tests are set
if( $#ARGV > -1 ) {
foreach my $t (@ARGV) {
if( $t < $NUM_TESTS && $t >= 0 ) {
$do_run[$t] = 1;
}
}
} else {
# turn on all tests
for( my $i = 0; $i < $NUM_TESTS; $i++ ) {
$do_run[$i] = 1;
}
}
if ($do_run[0]) {
print "test0: start 3-process lock server\n";
start_nodes(3,"ls");
cleanup();
sleep 2;
}
if ($do_run[1]) {
print "test1: start 3-process lock server, kill third server\n";
start_nodes(3,"ls");
print "Kill third server (PID: $pid[2]) on port $p[2]\n";
kill "TERM", $pid[2];
sleep 5;
# it should go through 4 views
my @v4 = ($p[0], $p[1]);
wait_and_check_expected_view(\@v4);
cleanup();
sleep 2;
}
if ($do_run[2]) {
print "test2: start 3-process lock server, kill first server\n";
start_nodes(3,"ls");
print "Kill first (PID: $pid[0]) on port $p[0]\n";
kill "TERM", $pid[0];
sleep 5;
# it should go through 4 views
my @v4 = ($p[1], $p[2]);
wait_and_check_expected_view(\@v4);
cleanup();
sleep 2;
}
if ($do_run[3]) {
print "test3: start 3-process lock_server, kill a server, restart a server\n";
start_nodes(3,"ls");
print "Kill server (PID: $pid[2]) on port $p[2]\n";
kill "TERM", $pid[2];
sleep 5;
my @v4 = ($p[0], $p[1]);
wait_and_check_expected_view(\@v4);
print "Restart killed server on port $p[2]\n";
$pid[2] = spawn_ls ($p[0], $p[2]);
sleep 5;
my @v5 = ($p[0], $p[1], $p[2]);
wait_and_check_expected_view(\@v5);
cleanup();
sleep 2;
}
if ($do_run[4]) {
print "test4: 3-process lock_server, kill third server, kill second server, restart third server, kill third server again, restart second server, re-restart third server, check logs\n";
start_nodes(3,"ls");
print "Kill server (PID: $pid[2]) on port $p[2]\n";
kill "TERM", $pid[2];
sleep 5;
my @v4 = ($p[0], $p[1]);
wait_and_check_expected_view(\@v4);
print "Kill server (PID: $pid[1]) on port $p[1]\n";
kill "TERM", $pid[1];
sleep 5;
#no view change can happen because of a lack of majority
print "Restarting server on port $p[2]\n";
$pid[2] = spawn_ls($p[0], $p[2]);
sleep 5;
#no view change can happen because of a lack of majority
foreach my $port (@p[0..2]) {
my $num_v = get_num_views(paxos_log($port), $port);
die "$num_v views in ", paxos_log($port), " : no new views should be formed due to the lack of majority\n" if ($num_v != $in_views{$port});
}
# kill node 3 again,
print "Kill server (PID: $pid[2]) on port $p[2]\n";
kill "TERM", $pid[2];
sleep 5;
print "Restarting server on port $p[1]\n";
$pid[1] = spawn_ls($p[0], $p[1]);
sleep 7;
foreach my $port (@p[0..1]) {
$in_views{$port} = get_num_views( paxos_log($port), $port );
print " Node $port is present in ", $in_views{$port}, " views in ", paxos_log($port), "\n";
}
print "Restarting server on port $p[2]\n";
$pid[2] = spawn_ls($p[0], $p[2]);
my @lastv = ($p[0],$p[1],$p[2]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
# now check the paxos logs and make sure the logs go through the right
# views
foreach my $port (@lastv) {
check_views( paxos_log($port), \@views, \@lastv);
}
cleanup();
}
if ($do_run[5]) {
print "test5: 3-process lock_server, send signal 1 to first server, kill third server, restart third server, check logs\n";
start_nodes(3,"ls");
print "Sending paxos breakpoint 1 to first server on port $p[0]\n";
spawn("./rsm_tester", $p[0]+1, "breakpoint", 3);
sleep 1;
print "Kill third server (PID: $pid[2]) on port $p[2]\n";
kill "TERM", $pid[2];
sleep 5;
foreach my $port (@p[0..2]) {
my $num_v = get_num_views( paxos_log($port), $port );
die "$num_v views in ", paxos_log($port), " : no new views should be formed due to the lack of majority\n" if ($num_v != $in_views{$port});
}
print "Restarting third server on port $p[2]\n";
$pid[2]= spawn_ls($p[0], $p[2]);
my @lastv = ($p[1],$p[2]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
sleep 10;
# now check the paxos logs and make sure the logs go through the right
# views
foreach my $port (@lastv) {
check_views( paxos_log($port), \@views, \@lastv);
}
cleanup();
}
if ($do_run[6]) {
print "test6: 4-process lock_server, send signal 2 to first server, kill fourth server, restart fourth server, check logs\n";
start_nodes(4,"ls");
print "Sending paxos breakpoint 2 to first server on port $p[0]\n";
spawn("./rsm_tester", $p[0]+1, "breakpoint", 4);
sleep 1;
print "Kill fourth server (PID: $pid[3]) on port $p[3]\n";
kill "TERM", $pid[3];
sleep 5;
foreach my $port ($p[1],$p[2]) {
my $num_v = get_num_views( paxos_log($port), $port );
die "$num_v views in ", paxos_log($port), " : no new views should be formed due to the lack of majority\n" if ($num_v != $in_views{$port});
}
sleep 5;
print "Restarting fourth server on port $p[3]\n";
$pid[3] = spawn_ls($p[1], $p[3]);
sleep 5;
my @v5 = ($p[0],$p[1],$p[2]);
foreach my $port (@v5) {
$in_views{$port}++;
}
push @views, \@v5;
sleep 10;
# the 6th view will be (2,3) or (1,2,3,4)
my @v6 = ($p[1],$p[2]);
foreach my $port (@v6) {
$in_views{$port}++;
}
foreach my $port (@v6) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
# final will be (2,3,4)
my @lastv = ($p[1],$p[2],$p[3]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
foreach my $port (@lastv) {
check_views( paxos_log($port), \@views, \@lastv );
}
cleanup();
}
if ($do_run[7]) {
print "test7: 4-process lock_server, send signal 2 to first server, kill fourth server, kill other servers, restart other servers, restart fourth server, check logs\n";
start_nodes(4,"ls");
print "Sending paxos breakpoint 2 to first server on port $p[0]\n";
spawn("./rsm_tester", $p[0]+1, "breakpoint", 4);
sleep 3;
print "Kill fourth server (PID: $pid[3]) on port $p[3]\n";
kill "TERM", $pid[3];
sleep 5;
print "Kill third server (PID: $pid[2]) on port $p[2]\n";
kill "TERM", $pid[2];
print "Kill second server (PID: $pid[1]) on port $p[1]\n";
kill "TERM", $pid[1];
sleep 5;
print "Restarting second server on port $p[1]\n";
$pid[1] = spawn_ls($p[0], $p[1]);
sleep 5;
print "Restarting third server on port $p[2]\n";
$pid[2] = spawn_ls($p[0], $p[2]);
sleep 5;
#no view change is possible by now because there is no majority
foreach my $port ($p[1],$p[2]) {
my $num_v = get_num_views( paxos_log($port), $port );
die "$num_v views in ", paxos_log($port), " : no new views should be formed due to the lack of majority\n" if ($num_v != $in_views{$port});
}
print "Restarting fourth server on port $p[3]\n";
$pid[3] = spawn_ls($p[1], $p[3]);
sleep 5;
my @v5 = ($p[0], $p[1], $p[2]);
push @views, \@v5;
foreach my $port (@v5) {
$in_views{$port}++;
}
sleep 15;
my @lastv = ($p[1],$p[2],$p[3]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
foreach my $port (@lastv) {
check_views( paxos_log($port), \@views, \@lastv);
}
cleanup();
}
if ($do_run[8]) {
print "test8: start 3-process lock service\n";
start_nodes(3,"ls");
print "Start lock_tester $p[0]\n";
$t = spawn("./lock_tester", $p[0]);
print " Wait for lock_tester to finish (waitpid $t)\n";
waitpid_to($t, 600);
if( system( "grep \"passed all tests successfully\" lock_tester-$p[0].log" ) ) {
mydie( "Failed lock tester for test 8" );
}
cleanup();
sleep 2;
}
if ($do_run[9]) {
print "test9: start 3-process rsm, kill second slave while lock_tester is running\n";
start_nodes(3,"ls");
print "Start lock_tester $p[0]\n";
$t = spawn("./lock_tester", $p[0]);
sleep int(rand(10)+1);
print "Kill slave (PID: $pid[2]) on port $p[2]\n";
kill "TERM", $pid[2];
sleep 3;
# it should go through 4 views
my @v4 = ($p[0], $p[1]);
wait_and_check_expected_view(\@v4);
print " Wait for lock_tester to finish (waitpid $t)\n";
waitpid_to($t, 600);
if( system( "grep \"passed all tests successfully\" lock_tester-$p[0].log" ) ) {
mydie( "Failed lock tester for test 9" );
}
cleanup();
sleep 2;
}
if ($do_run[10]) {
print "test10: start 3-process rsm, kill second slave and restarts it later while lock_tester is running\n";
start_nodes(3,"ls");
print "Start lock_tester $p[0]\n";
$t = spawn("./lock_tester", $p[0]);
sleep int(rand(10)+1);
print "Kill slave (PID: $pid[2]) on port $p[2]\n";
kill "TERM", $pid[2];
sleep 3;
# it should go through 4 views
my @v4 = ($p[0], $p[1]);
wait_and_check_expected_view(\@v4);
sleep 3;
print "Restarting killed lock_server on port $p[2]\n";
$pid[2] = spawn_ls($p[0], $p[2]);
my @v5 = ($p[0],$p[1],$p[2]);
wait_and_check_expected_view(\@v5);
print " Wait for lock_tester to finish (waitpid $t)\n";
waitpid_to($t, 600);
if( system( "grep \"passed all tests successfully\" lock_tester-$p[0].log" ) ) {
mydie( "Failed lock tester for test 10" );
}
cleanup();
sleep 2;
}
if ($do_run[11]) {
print "test11: start 3-process rsm, kill primary while lock_tester is running\n";
start_nodes(3,"ls");
print "Start lock_tester $p[0]\n";
$t = spawn("./lock_tester", $p[0]);
sleep int(rand(10)+1);
print "Kill primary (PID: $pid[0]) on port $p[0]\n";
kill "TERM", $pid[0];
sleep 3;
# it should go through 4 views
my @v4 = ($p[1], $p[2]);
wait_and_check_expected_view(\@v4);
print " Wait for lock_tester to finish (waitpid $t)\n";
waitpid_to($t, 600);
if( system( "grep \"passed all tests successfully\" lock_tester-$p[0].log" ) ) {
mydie( "Failed lock tester for test 11" );
}
cleanup();
sleep 2;
}
if ($do_run[12]) {
print "test12: start 3-process rsm, kill master at break1 and restart it while lock_tester is running\n";
start_nodes(3, "ls");
print "Start lock_tester $p[0]\n";
$t = spawn("./lock_tester", $p[0]);
sleep 1;
print "Kill master (PID: $pid[0]) on port $p[0] at breakpoint 1\n";
spawn("./rsm_tester", $p[0]+1, "breakpoint", 1);
sleep 1;
# it should go through 5 views
my @v4 = ($p[1], $p[2]);
wait_and_check_expected_view(\@v4);
print "Restarting killed lock_server on port $p[0]\n";
$pid[0] = spawn_ls($p[1], $p[0]);
sleep 3;
# the last view should include all nodes
my @lastv = ($p[0],$p[1],$p[2]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
foreach my $port (@lastv) {
check_views( paxos_log($port), \@views, \@lastv);
}
print " Wait for lock_tester to finish (waitpid $t)\n";
waitpid_to($t, 600);
if( system( "grep \"passed all tests successfully\" lock_tester-$p[0].log" ) ) {
mydie( "Failed lock tester for test 12" );
}
cleanup();
sleep 2;
}
if ($do_run[13]) {
print "test13: start 3-process rsm, kill slave at break1 and restart it while lock_tester is running\n";
start_nodes(3, "ls");
print "Start lock_tester $p[0]\n";
$t = spawn("./lock_tester", $p[0]);
sleep 1;
print "Kill slave (PID: $pid[2]) on port $p[2] at breakpoint 1\n";
spawn("./rsm_tester", $p[2]+1, "breakpoint", 1);
sleep 1;
# it should go through 4 views
my @v4 = ($p[0], $p[1]);
wait_and_check_expected_view(\@v4);
print "Restarting killed lock_server on port $p[2]\n";
$pid[2] = spawn_ls($p[0], $p[2]);
sleep 3;
# the last view should include all nodes
my @lastv = ($p[0],$p[1],$p[2]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
foreach my $port (@lastv) {
check_views( paxos_log($port), \@views, \@lastv);
}
print " Wait for lock_tester to finish (waitpid $t)\n";
waitpid_to($t, 600);
if( system( "grep \"passed all tests successfully\" lock_tester-$p[0].log" ) ) {
mydie( "Failed lock tester for test 13" );
}
cleanup();
sleep 2;
}
if ($do_run[14]) {
print "test14: start 5-process rsm, kill slave break1, kill slave break2\n";
start_nodes(5, "ls");
print "Start lock_tester $p[0]\n";
$t = spawn("./lock_tester", $p[0]);
sleep 1;
print "Kill slave (PID: $pid[4]) on port $p[4] at breakpoint 1\n";
spawn("./rsm_tester", $p[4]+1, "breakpoint", 1);
print "Kill slave (PID: $pid[3]) on port $p[3] at breakpoint 2\n";
spawn("./rsm_tester", $p[3]+1, "breakpoint", 2);
sleep 1;
# two view changes:
print "first view change wait\n";
my @lastv = ($p[0],$p[1],$p[2],$p[3]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
print "second view change wait\n";
@lastv = ($p[0],$p[1],$p[2]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
print " Wait for lock_tester to finish (waitpid $t)\n";
waitpid_to($t, 600);
if( system( "grep \"passed all tests successfully\" lock_tester-$p[0].log" ) ) {
mydie( "Failed lock tester for test 14" );
}
cleanup();
sleep 2;
}
if ($do_run[15]) {
print "test15: start 5-process rsm, kill slave break1, kill primary break2\n";
start_nodes(5, "ls");
print "Start lock_tester $p[0]\n";
$t = spawn("./lock_tester", $p[0]);
sleep 1;
print "Kill slave (PID: $pid[4]) on port $p[4] at breakpoint 1\n";
spawn("./rsm_tester", $p[4]+1, "breakpoint", 1);
print "Kill primary (PID: $pid[0]) on port $p[0] at breakpoint 2\n";
spawn("./rsm_tester", $p[0]+1, "breakpoint", 2);
sleep 1;
# two view changes:
print "first view change wait\n";
my @lastv = ($p[0],$p[1],$p[2],$p[3]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
print "second view change wait\n";
@lastv = ($p[1],$p[2],$p[3]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
print " Wait for lock_tester to finish (waitpid $t)\n";
waitpid_to($t, 600);
if( system( "grep \"passed all tests successfully\" lock_tester-$p[0].log" ) ) {
mydie( "Failed lock tester for test 15" );
}
cleanup();
sleep 2;
}
if ($do_run[16]) {
print "test16: start 3-process rsm, partition primary, heal it\n";
start_nodes(3, "ls");
print "Start lock_tester $p[0]\n";
$t = spawn("./lock_tester", $p[0]);
sleep 1;
print "Partition primary (PID: $pid[0]) on port $p[0] at breakpoint\n";
spawn("./rsm_tester", $p[0]+1, "partition", 0);
sleep 3;
print "first view change wait\n";
my @lastv = ($p[1],$p[2]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
sleep 1;
print "Heal partition primary (PID: $pid[0]) on port $p[0] at breakpoint\n";
spawn("./rsm_tester", $p[0]+1, "partition", 1);
sleep 1;
# xxx it should test that this is the 5th view!
print "second view change wait\n";
@lastv = ($p[0], $p[1],$p[2]);
foreach my $port (@lastv) {
wait_for_view_change(paxos_log($port), $in_views{$port}+1, $port, 20);
}
print " Wait for lock_tester to finish (waitpid $t)\n";
waitpid_to($t, 600);
if( system( "grep \"passed all tests successfully\" lock_tester-$p[0].log" ) ) {
mydie( "Failed lock tester for test 16" );
}
cleanup();
sleep 2;
}
print "tests done OK\n";