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
|
# Copyright (C) 2017 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
package QtQA::Proc::Reliable::TESTDATA;
use strict;
use warnings;
=head1 NAME
QtQA::Proc::Reliable::TESTDATA - testdata for system tests of QtQA::Proc::Reliable
=head1 DESCRIPTION
This module is not intended for use by the end-user of QtQA::Proc::Reliable.
It is merely a holding area for a suite of testdata to be used in a few autotests
relating to QtQA::Proc::Reliable.
=cut
use Tie::IxHash;
use Readonly;
use base 'Exporter';
our @EXPORT_OK = qw( %TESTDATA );
# Helper regex portions for below testdata
Readonly my %RE => (
# Matches the text which states we're about to retry a command (not including the reason)
retry => qr{ \QQtQA::TestScript: It will be retried because\E }xms,
# Matches the reason why a command was restarted.
# These are set by the specific QtQA::Proc::Reliable strategies and are cumbersome
# to test, so we simply allow for any properly formatted text.
retry_reason => qr{
(?:
[^\n] # reason fits on a single line ...
| #
\nQtQA::TestScript: # ... or it takes multiple lines, all of them prefixed
)*
}xms,
# Matches the prefix on the line where the attempted command is printed
command => qr{
\QQtQA::TestScript: \E\$command
}xms,
# Matches the prefix for "the (n'th) attempt at running this command ..."
# Usage example: $RE{ attempt }{ second }
attempt => {
map {
$_ => qr{ \QQtQA::TestScript: The $_ attempt at running this command:\E }xms
}
qw(
first
second
third
fourth
fifth
sixth
) # add any more as needed
},
# Matches the text generated by failing with an exit code
# Usage example: $RE{ failed_with_exitcode }{ 12 }
failed_with_exitcode => {
map {
$_ => qr{ \QQtQA::TestScript: ... failed with exit code $_.\E }xms
}
(1..255)
},
);
# This is tied to retain order, as we want the tests to be run in order from least
# to most complex.
#
# Note, can't be Readonly without causing Params::Validate to segfault :(
tie our %TESTDATA => 'Tie::IxHash',
# simple passing command to ensure correct operation in the normal case
'git control' => {
command => [ 'git', 'clone', 'git://example.com/repo.git' ],
mock_command => {
sequence => [
{ exitcode => 0, stdout => "Hi\n" },
],
},
expected_raw_stdout => "Hi\n",
},
# recoverable git problem
'git remote end hung up' => {
command => [ 'git', 'clone', 'git://example.com/repo.git' ],
mock_command => {
sequence => [
{ exitcode => 12, stderr => "fatal: The remote end hung up unexpectedly\n" },
{ exitcode => 12, stderr => "fatal: The remote end hung up unexpectedly\n" },
{ exitcode => 0 },
],
},
expected_retries => 2,
expected_exe_stderr => qr"
\A
\Qfatal: The remote end hung up unexpectedly\E \n
$RE{ attempt }{ first } \n
$RE{ command } \Q = ['git','clone','git://example.com/repo.git'];\E \n
$RE{ failed_with_exitcode }{ 12 } \n
$RE{ retry } $RE{ retry_reason } \n
\Qfatal: The remote end hung up unexpectedly\E \n
$RE{ attempt }{ second } \n
$RE{ command } \Q = ['git','clone','git://example.com/repo.git'];\E \n
$RE{ failed_with_exitcode }{ 12 } \n
$RE{ retry } $RE{ retry_reason } \n
\z
"xms,
expected_raw_stderr => "fatal: The remote end hung up unexpectedly\n" x 2,
},
# error message but 0 exit code; make sure we don't retry
'git remote end hung up with 0 exit code' => {
command => [ 'git', 'clone', 'git://example.com/repo.git' ],
mock_command => {
sequence => [
{ exitcode => 0, stderr => "fatal: The remote end hung up unexpectedly\n" },
],
},
expected_retries => 0,
expected_raw_stderr => "fatal: The remote end hung up unexpectedly\n",
expected_exe_stderr => "fatal: The remote end hung up unexpectedly\n",
},
# unrecoverable git problem with no retries
'git unrecoverable simple' => {
command => [ 'git', 'clone', 'git://example.com/repo.git' ],
mock_command => {
sequence => [
{ exitcode => 12, stdout => "Cloning...\n", stderr => "fatal: Foo bar the baz\n" },
],
},
expected_raw_stderr => "fatal: Foo bar the baz\n",
expected_raw_stdout => "Cloning...\n",
expected_status => (12 << 8),
},
# unrecoverable git problem with some retries
'git unrecoverable with retry' => {
command => [ 'git', 'clone', 'git://example.com/repo.git' ],
mock_command => {
sequence => [
{ exitcode => 1, stderr => "fatal: The remote end hung up unexpectedly\n" },
{ exitcode => 2, stderr => "fatal: The remote end hung up unexpectedly\n" },
{ exitcode => 58, stderr => "fatal: Foo bar the baz\n" },
],
},
expected_retries => 2,
expected_exe_stderr => qr"
\A
\Qfatal: The remote end hung up unexpectedly\E \n
$RE{ attempt }{ first } \n
$RE{ command } \Q = ['git','clone','git://example.com/repo.git'];\E \n
$RE{ failed_with_exitcode }{ 1 } \n
$RE{ retry } $RE{ retry_reason } \n
\Qfatal: The remote end hung up unexpectedly\E \n
$RE{ attempt }{ second } \n
$RE{ command } \Q = ['git','clone','git://example.com/repo.git'];\E \n
$RE{ failed_with_exitcode }{ 2 } \n
$RE{ retry } $RE{ retry_reason } \n
\Qfatal: Foo bar the baz\E \n
\z
"xms,
expected_raw_stderr => ("fatal: The remote end hung up unexpectedly\n" x 2)
."fatal: Foo bar the baz\n",
expected_status => (58 << 8),
},
# git DNS failure - git:// protocol
'git DNS failure git://' => {
command => [ 'git', 'clone', 'git://example.com/repo.git' ],
mock_command => {
sequence => [
{ exitcode => 128, stderr => "fatal: Unable to look up example.com (port 9418) (Name or service not known)\n" },
{ exitcode => 0 },
],
},
expected_retries => 1,
expected_exe_stderr => qr"
\A
\Qfatal: Unable to look up example.com (port 9418) (Name or service not known)\E \n
$RE{ attempt }{ first } \n
$RE{ command } \Q = ['git','clone','git://example.com/repo.git'];\E \n
$RE{ failed_with_exitcode }{ 128 } \n
$RE{ retry } $RE{ retry_reason } \n
\z
"xms,
expected_raw_stderr => "fatal: Unable to look up example.com (port 9418) (Name or service not known)\n",
},
# git DNS failure - ssh:// protocol
# This test basically confirms that the Git strategy is subclassing the ssh strategy as
# expected. Other ssh:// protocol git issues aren't tested further.
'git DNS failure ssh://' => {
command => [ 'git', 'clone', 'ssh://example.com/repo.git' ],
mock_command => {
sequence => [
{ exitcode => 128, stderr => "ssh: Could not resolve hostname example.com: Name or service not known\n" },
{ exitcode => 0 },
],
},
expected_retries => 1,
expected_exe_stderr => qr"
\A
\Qssh: Could not resolve hostname example.com: Name or service not known\E \n
$RE{ attempt }{ first } \n
$RE{ command } \Q = ['git','clone','ssh://example.com/repo.git'];\E \n
$RE{ failed_with_exitcode }{ 128 } \n
$RE{ retry } $RE{ retry_reason } \n
\z
"xms,
expected_raw_stderr => "ssh: Could not resolve hostname example.com: Name or service not known\n",
},
# various scp problems
'scp network issues ultimately fatal' => {
command => [ 'scp', 'example.com:~/file1', '.' ],
mock_command => {
sequence => [
{ exitcode => 1, stderr => "ssh: Could not resolve hostname example.com: Name or service not known\n" },
{ exitcode => 2, stderr => "ssh: connect to host example.com: No route to host\n" },
{ exitcode => 3, stderr => "ssh: Connect to host example.com: Network is unreachable\n" },
{ exitcode => 4, stderr => "ssh: connect to host example.com port 1234: Connection timed out\n" },
{ exitcode => 5, stderr => "ssh: connect to host example.com port 22: Connection refused\n" },
# check that stdout does _not_ cause the command to be retried
{ exitcode => 6, stdout => "ssh: connect to host example.com port 23: Connection refused\n" },
],
},
expected_retries => 5,
expected_exe_stderr => qr"
\A
\Qssh: Could not resolve hostname example.com: Name or service not known\E \n
$RE{ attempt }{ first } \n
$RE{ command } \Q = ['scp','example.com:~/file1','.'];\E \n
$RE{ failed_with_exitcode }{ 1 } \n
$RE{ retry } $RE{ retry_reason } \n
\Qssh: connect to host example.com: No route to host\E \n
$RE{ attempt }{ second } \n
$RE{ command } \Q = ['scp','example.com:~/file1','.'];\E \n
$RE{ failed_with_exitcode }{ 2 } \n
$RE{ retry } $RE{ retry_reason } \n
\Qssh: Connect to host example.com: Network is unreachable\E \n
$RE{ attempt }{ third } \n
$RE{ command } \Q = ['scp','example.com:~/file1','.'];\E \n
$RE{ failed_with_exitcode }{ 3 } \n
$RE{ retry } $RE{ retry_reason } \n
\Qssh: connect to host example.com port 1234: Connection timed out\E \n
$RE{ attempt }{ fourth } \n
$RE{ command } \Q = ['scp','example.com:~/file1','.'];\E \n
$RE{ failed_with_exitcode }{ 4 } \n
$RE{ retry } $RE{ retry_reason } \n
\Qssh: connect to host example.com port 22: Connection refused\E \n
$RE{ attempt }{ fifth } \n
$RE{ command } \Q = ['scp','example.com:~/file1','.'];\E \n
$RE{ failed_with_exitcode }{ 5 } \n
$RE{ retry } $RE{ retry_reason } \n
\z
"xms,
expected_raw_stderr =>
"ssh: Could not resolve hostname example.com: Name or service not known\n"
."ssh: connect to host example.com: No route to host\n"
."ssh: Connect to host example.com: Network is unreachable\n"
."ssh: connect to host example.com port 1234: Connection timed out\n"
."ssh: connect to host example.com port 22: Connection refused\n"
,
expected_raw_stdout => "ssh: connect to host example.com port 23: Connection refused\n",
expected_status => (6 << 8),
},
# simple check with explicitly loading a strategy
'non-auto ssh failure' => {
command => [ 'frobnitz' ],
reliable => [ 'ssh' ],
mock_command => {
sequence => [
# check that the requested `reliable' loaded ssh strategy ...
{ exitcode => 128, stderr => "ssh: Could not resolve hostname example.com: Name or service not known\n" },
# ...and did _not_ load `git' strategy
{ exitcode => 128, stderr => "fatal: Unable to look up example.com (port 9418) (Name or service not known)\n" },
],
},
expected_retries => 1,
expected_exe_stderr => qr"
\A
\Qssh: Could not resolve hostname example.com: Name or service not known\E \n
$RE{ attempt }{ first } \n
$RE{ command } \Q = ['frobnitz'];\E \n
$RE{ failed_with_exitcode }{ 128 } \n
$RE{ retry } $RE{ retry_reason } \n
\Qfatal: Unable to look up example.com (port 9418) (Name or service not known)\E \n
\z
"xms,
expected_raw_stderr =>
"ssh: Could not resolve hostname example.com: Name or service not known\n"
."fatal: Unable to look up example.com (port 9418) (Name or service not known)\n"
,
expected_status => (128 << 8),
},
;
1;
|