Skip to content

Commit 7eaaacf

Browse files
authored
Document --FLAKY-- section of PHPTs (GH-43)
The given example might not be the best one, since it actually wouldn't need the `--FLAKY--` section, but it's the only one we currently have. We also document the "flaky" convention for SKIPIF sections,
1 parent 518ee5c commit 7eaaacf

File tree

3 files changed

+142
-1
lines changed

3 files changed

+142
-1
lines changed

phpt_details.php

+36-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<a href="#file_section">--FILE--</a> | <a href="#fileeof_section">--FILEEOF--</a> | <a href="#file_external_section">--FILE_EXTERNAL--</a> | <a href="#redirecttest_section">--REDIRECTTEST--</a><br/>
3434
[<a href="#cgi_section">--CGI--</a>]<br/>
3535
[<a href="#xfail_section">--XFAIL--</a>]<br/>
36+
[<a href="#flaky_section">--FLAKY--</a>]<br/>
3637
[<a href="#expectheaders_section">--EXPECTHEADERS</a>--]<br/>
3738
<a href="#expect_section">--EXPECT--</a> | <a href="#expectf_section">--EXPECTF--</a> | <a href="#expectregex_section">--EXPECTREGEX--</a>
3839
| <a href="#expect_external_section">--EXPECT_EXTERNAL--</a> | <a href="#expectf_external_section">--EXPECTF_EXTERNAL--</a> | <a href="#expectregex_external_section">--EXPECTREGEX_EXTERNAL--</a>
@@ -116,7 +117,10 @@
116117
<p><b>Format:</b><br/>
117118
PHP code enclosed by PHP tags. If the output of this scripts starts with "skip",
118119
the test is skipped. If the output starts with "xfail", the test is marked as
119-
expected failure. The "xfail" convention is supported as of PHP 7.2.0.</p>
120+
<a href="#xfail_section">expected failure</a>. If the output starts with "flaky",
121+
the test is marked as <a href="#flaky_section">flaky test</a>.
122+
The "xfail" convention is supported as of PHP 7.2.0.
123+
The "flaky" convention is supported as of PHP 8.2.25 and PHP 8.3.13, respectively.</p>
120124
<p><b>Example 1 (snippet):</b><br/>
121125
<pre>--SKIPIF--
122126
&lt;?php if (!extension_loaded("filter")) die("Skipped: filter extension required."); ?&gt;</pre>
@@ -132,6 +136,15 @@
132136
&lt;?php if (getenv('SKIP_ASAN')) die('xfail Startup failure leak'); ?&gt;</pre>
133137
</p>
134138
<p><b>Example 3 (full):</b> <a href="sample_tests/xfailif.php">xfailif.phpt</a></p>
139+
<p><b>Example 4 (snippet):</b><br/>
140+
<pre>--SKIPIF--
141+
&lt;?php
142+
if (getenv("GITHUB_ACTIONS") &amp;&amp; PHP_OS_FAMILY === "Darwin") {
143+
die("flaky Occasionally segfaults on macOS for unknown reasons");
144+
}
145+
&gt;></pre>
146+
</p>
147+
<p><b>Example 4 (full):</b> <a href="sample_tests/flakyif.php">flakyif.phpt</a></p>
135148
</dd>
136149

137150
<dt id="conflicts_section">--CONFLICTS--</dt>
@@ -666,6 +679,28 @@
666679
<p><b>Example 1 (full):</b> <a href="sample_tests/sample017.php">sample017.phpt</a></p>
667680
</dd>
668681

682+
<dt id="flaky_section">--FLAKY--</dt>
683+
<dd>
684+
<p><b>Description:</b><br/>
685+
This section identifies this test as one that occassionally fails. If the test
686+
actually fails, it will be retried one more time, and that result will be reported.
687+
The section should include a brief description of why the test is flaky. Reasons for
688+
this include tests that rely on relatively precise timing, or
689+
temporary disc states. Available as of PHP 8.1.22 and 8.2.9, respectively.</p>
690+
<p>Please do NOT include a --FLAKY-- section without providing a text description for
691+
the reason it is being used.</p>
692+
<p><b>Required:</b><br/>
693+
No.</p>
694+
<p><b>Test Script Support:</b><br/>
695+
run-tests.php</p>
696+
<p><b>Format:</b><br/>
697+
A short plain text description of why this test is flaky.</p>
698+
<p><b>Example 1 (snippet):</b><br/>
699+
<pre>--FLAKY--
700+
This test frequently fails in CI</pre></p>
701+
<p><b>Example 1 (full):</b> <a href="sample_tests/flaky.php">flaky.phpt</a></p>
702+
</dd>
703+
669704
<dt id="expectheaders_section">--EXPECTHEADERS--</dt>
670705
<dd>
671706
<p><b>Description:</b><br/>

sample_tests/flaky.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
include("../include/functions.php");
3+
4+
$TITLE = "Sample Test [PHP-QAT: Quality Assurance Team]";
5+
$SITE_UPDATE = date("D M d H:i:s Y T", filectime(__FILE__));
6+
7+
common_header();
8+
?>
9+
10+
<div style="padding: 10px">
11+
<h1>Sample Test: sample001.phpt</h1>
12+
<p>Back to &quot;<a href="../phpt_details.php">PHPT Test File Layout</a>&quot;</p>
13+
<pre>--TEST--
14+
Test hrtime() aligns with microtime()
15+
--FLAKY--
16+
This test frequently fails in CI
17+
--FILE--
18+
&lt;?php
19+
20+
$m0 = microtime(true);
21+
$h0 = hrtime(true);
22+
for ($i = 0; $i &lt; 1024*1024; $i++);
23+
$h1 = hrtime(true);
24+
$m1 = microtime(true);
25+
26+
$d0 = ($m1 - $m0)*1000000000.0;
27+
$d1 = $h1 - $h0;
28+
29+
/* Relative uncertainty. */
30+
$d = abs($d0 - $d1)/$d1;
31+
32+
if ($d &gt; 0.05) {
33+
print "FAIL, $d";
34+
} else {
35+
print "OK, $d";
36+
}
37+
38+
?&gt;
39+
--EXPECTF--
40+
OK, %f
41+
</pre>
42+
<p>Back to &quot;<a href="../phpt_details.php">PHPT Test File Layout</a>&quot;</p>
43+
</div>
44+
45+
<?php
46+
common_footer();
47+
?>

sample_tests/flakyif.php

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
include("../include/functions.php");
3+
4+
$TITLE = "Sample Test [PHP-QAT: Quality Assurance Team]";
5+
$SITE_UPDATE = date("D M d H:i:s Y T", filectime(__FILE__));
6+
7+
common_header();
8+
?>
9+
10+
<div style="padding: 10px">
11+
<h1>Sample Test: sample001.phpt</h1>
12+
<p>Back to &quot;<a href="../phpt_details.php">PHPT Test File Layout</a>&quot;</p>
13+
<pre>--TEST--
14+
Phar::chmod
15+
--EXTENSIONS--
16+
phar
17+
--INI--
18+
phar.readonly=1
19+
phar.require_hash=0
20+
--SKIPIF--
21+
&lt;?php
22+
if (getenv("GITHUB_ACTIONS") &amp;&amp; PHP_OS_FAMILY === "Darwin") {
23+
die("flaky Occasionally segfaults on macOS for unknown reasons");
24+
}
25+
?&gt;
26+
--FILE--
27+
&lt;?php
28+
$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.1.phar.php';
29+
$pname = 'phar://hio';
30+
$file = '&lt;?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?&gt;';
31+
32+
$files = array();
33+
$files['a.php'] = '&lt;?php echo "This is a\n"; include "'.$pname.'/b.php"; ?&gt;';
34+
include 'files/phar_test.inc';
35+
try {
36+
$a = new Phar($fname);
37+
var_dump($a['a.php']-&gt;isExecutable());
38+
$a['a.php']-&gt;chmod(0777);
39+
var_dump($a['a.php']-&gt;isExecutable());
40+
$a['a.php']-&gt;chmod(0666);
41+
var_dump($a['a.php']-&gt;isExecutable());
42+
} catch (Exception $e) {
43+
echo $e-&gt;getMessage() . "\n";
44+
}
45+
?&gt;
46+
--CLEAN--
47+
&lt;?php
48+
unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php');
49+
?&gt;
50+
--EXPECTF--
51+
bool(false)
52+
Cannot modify permissions for file "a.php" in phar "%s033a.1.phar.php", write operations are prohibited
53+
</pre>
54+
<p>Back to &quot;<a href="../phpt_details.php">PHPT Test File Layout</a>&quot;</p>
55+
</div>
56+
57+
<?php
58+
common_footer();
59+
?>

0 commit comments

Comments
 (0)