|
| 1 | +use Carp; |
| 2 | +use POSIX; |
1 | 3 | use strict; |
| 4 | +use Test::More; |
| 5 | +use TestLib; |
| 6 | +use Time::HiResqw(usleep); |
2 | 7 | use warnings; |
3 | | -use Carp; |
| 8 | + |
4 | 9 | use PostgresNode; |
5 | 10 | use Cluster; |
6 | | -use TestLib; |
7 | | -use Test::More; |
| 11 | + |
| 12 | +use Test::Moretests=> Cluster::is_ee() ? 6 : 5; |
8 | 13 |
|
9 | 14 | my$cluster = new Cluster(3); |
10 | 15 | $cluster->init(); |
|
42 | 47 | $hash2 =$cluster->safe_psql(2,$hash_query); |
43 | 48 | note("$hash0,$hash1,$hash2"); |
44 | 49 | is( (($hash0eq$hash1)and ($hash1eq$hash2)) , 1, |
45 | | -"Check that hash is the same after query"); |
| 50 | +"Check that hash is the same after query"); |
46 | 51 | } |
47 | 52 |
|
48 | 53 | $cluster->safe_psql(0,q{ |
|
72 | 77 | $hash2 =$cluster->safe_psql(2,$hash_query); |
73 | 78 | note("$hash0,$hash1,$hash2"); |
74 | 79 | is( (($hash0eq$hash1)and ($hash1eq$hash2)) , 1, |
75 | | -"Check that hash is the same after query"); |
| 80 | +"Check that hash is the same after query"); |
76 | 81 |
|
77 | 82 | # ############################################################################## |
78 | 83 | # |
|
93 | 98 |
|
94 | 99 | # Simulate payload |
95 | 100 | $cluster->pgbench(0, ('-i','-n',-s=>'1') ); |
96 | | -my$pgb1 =$cluster->pgbench_async(0, ('-n',-T=>'15', -j=>'5',-c=>'5') ); |
97 | | -sleep(5); |
| 101 | +note( strftime('%Y-%m-%d %H:%M:%S',localtime) .": starting async pgbench" ); |
| 102 | +my$pgb1 =$cluster->pgbench_async(0, ('-n',-T=>'25', -j=>'1',-c=>'5')); |
98 | 103 |
|
99 | 104 | my$pid0; |
100 | 105 | my$attempts = 0; |
| 106 | + |
| 107 | +note( strftime('%Y-%m-%d %H:%M:%S',localtime) .": starting polling of backend pid" ); |
101 | 108 | while (1) |
102 | 109 | { |
103 | 110 | $pid0 =$cluster->safe_psql(0,"SELECT pid FROM pg_stat_activity |
104 | 111 | WHEREbackend_type LIKE 'client backend' |
105 | 112 | AND query LIKE 'UPDATE%' LIMIT 1;"); |
106 | 113 |
|
107 | 114 | # bf says we might be really unlucky to find no backend doing update |
108 | | -if ($pid0ne"") |
| 115 | +# It does not make much sense to try longer than pgbench run lasts, |
| 116 | +# since we need an active backend to kill. So let it be 25 seconds |
| 117 | +# both for pgbench_async() and this pg_stat_activity polling. |
| 118 | +if ( ($pid0ne"") ||$attempts >= 25*10 ) |
109 | 119 | { |
110 | 120 | last; |
111 | 121 | } |
| 122 | + |
112 | 123 | # Wait 0.1 second before retrying. |
113 | 124 | usleep(100_000); |
114 | 125 | $attempts++; |
115 | | -if ($attempts >= 180*10) |
116 | | -{ |
117 | | -croak'failed to fetch backend pid'; |
118 | | -} |
119 | 126 | } |
| 127 | +note( strftime('%Y-%m-%d %H:%M:%S',localtime) .": finished polling of backend pid" ); |
| 128 | +is( ($pid0ne""), 1, |
| 129 | +"found an active backend doing UPDATE" ); |
120 | 130 |
|
121 | 131 | # Simulate hard crash |
122 | 132 | note("Simulate hard crash of a backend by SIGKILL to$pid0"); |
|