You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
3.5 KiB

  1. #!/usr/bin/perl
  2. # -*- cperl -*-
  3. # Copyright (c) 2007, 2008 MySQL AB
  4. # Use is subject to license terms.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; version 2 of the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. use strict;
  19. use FindBin;
  20. use My::SafeProcess;
  21. #
  22. # Test longterm running of SafeProcess
  23. #
  24. my $perl_path= $^X;
  25. my $verbose= 0;
  26. my $loops= 100;
  27. print "kill one and wait for one\n";
  28. for (1...$loops){
  29. use File::Temp qw / tempdir /;
  30. my $dir = tempdir( CLEANUP => 1 );
  31. my @procs;
  32. for (1..10){
  33. my $args= [ "$FindBin::Bin/dummyd.pl", "--vardir=$dir" ];
  34. my $proc= My::SafeProcess->new
  35. (
  36. path => $perl_path,
  37. args => \$args,
  38. verbose => $verbose,
  39. );
  40. push(@procs, $proc);
  41. }
  42. foreach my $proc (@procs) {
  43. $proc->kill();
  44. # dummyd will always be killed and thus
  45. # exit_status should have been set to 1
  46. die "oops, exit_status: ", $proc->exit_status()
  47. unless $proc->exit_status() == 1;
  48. }
  49. print "=" x 60, "\n";
  50. }
  51. print "With 1 second sleep in dummyd\n";
  52. for (1...$loops){
  53. use File::Temp qw / tempdir /;
  54. my $dir = tempdir( CLEANUP => 1 );
  55. my @procs;
  56. for (1..10){
  57. my $args= [ "$FindBin::Bin/dummyd.pl",
  58. "--vardir=$dir",
  59. "--sleep=1" ];
  60. my $proc= My::SafeProcess->new
  61. (
  62. path => $perl_path,
  63. args => \$args,
  64. verbose => $verbose,
  65. );
  66. push(@procs, $proc);
  67. }
  68. foreach my $proc (@procs) {
  69. $proc->kill();
  70. }
  71. print "=" x 60, "\n";
  72. }
  73. print "kill all and wait for one\n";
  74. for (1...$loops){
  75. use File::Temp qw / tempdir /;
  76. my $dir = tempdir( CLEANUP => 1 );
  77. my @procs;
  78. for (1..10){
  79. my $args= [ "$FindBin::Bin/dummyd.pl", "--vardir=$dir" ];
  80. my $proc= My::SafeProcess->new
  81. (
  82. path => $perl_path,
  83. args => \$args,
  84. verbose => $verbose,
  85. );
  86. push(@procs, $proc);
  87. }
  88. foreach my $proc (@procs) {
  89. $proc->start_kill();
  90. }
  91. foreach my $proc (@procs) {
  92. $proc->wait_one();
  93. }
  94. print "=" x 60, "\n";
  95. }
  96. print "kill all using shutdown without callback\n";
  97. for (1...$loops){
  98. use File::Temp qw / tempdir /;
  99. my $dir = tempdir( CLEANUP => 1 );
  100. my @procs;
  101. for (1..10){
  102. my $args= [ "$FindBin::Bin/dummyd.pl", "--vardir=$dir" ];
  103. my $proc= My::SafeProcess->new
  104. (
  105. path => $perl_path,
  106. args => \$args,
  107. verbose => $verbose,
  108. );
  109. push(@procs, $proc);
  110. }
  111. My::SafeProcess::shutdown(2, @procs);
  112. print "=" x 60, "\n";
  113. }
  114. print "kill all using shutdown\n";
  115. for (1...$loops){
  116. use File::Temp qw / tempdir /;
  117. my $dir = tempdir( CLEANUP => 1 );
  118. my @procs;
  119. for (1..10){
  120. my $args= [ "$FindBin::Bin/dummyd.pl", "--vardir=$dir" ];
  121. my $proc= My::SafeProcess->new
  122. (
  123. path => $perl_path,
  124. args => \$args,
  125. verbose => $verbose,
  126. shutdown => sub { }, # Does nothing
  127. );
  128. push(@procs, $proc);
  129. }
  130. My::SafeProcess::shutdown(2, @procs);
  131. print "=" x 60, "\n";
  132. }
  133. exit(0);