Skip to content

Commit 2dd0865

Browse files
committed
Share failed service probes across tests
1 parent 35bce66 commit 2dd0865

50 files changed

Lines changed: 482 additions & 374 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ext/ldap/tests/skipifbindfailure.inc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
<?php
22
require_once 'connect.inc';
3+
require_once dirname(__DIR__, 3) . '/tests/probe_cache.inc';
34

45
if ($skip_on_bind_failure) {
6+
$configuration = [$uri, $user, $passwd, $protocol_version];
57

6-
$link = ldap_connect($uri);
7-
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
8-
if (!@ldap_bind($link, $user, $passwd))
9-
die(sprintf("skip Can't bind to LDAP Server - [%d] %s", ldap_errno($link), ldap_error($link)));
8+
$reason = ProbeCache::getFailure('ldap.bind', $configuration, static function () use ($uri, $user, $passwd, $protocol_version): ?string {
9+
$link = ldap_connect($uri);
10+
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
11+
if (!@ldap_bind($link, $user, $passwd)) {
12+
return sprintf("Can't bind to LDAP Server - [%d] %s", ldap_errno($link), ldap_error($link));
13+
}
14+
15+
ldap_unbind($link);
16+
return null;
17+
});
1018

11-
ldap_unbind($link);
19+
if (is_string($reason)) {
20+
die("skip $reason");
21+
}
1222
}
1323

1424
if (isset($require_vendor)) {
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
<?php
22
require_once 'connect.inc';
3-
$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
4-
if (!is_object($link))
5-
die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
6-
mysqli_close($link);
3+
require_once dirname(__DIR__, 3) . '/tests/probe_cache.inc';
4+
5+
$configuration = [$host, $port, $user, $passwd, $db, $socket, get_environment_connection_flags()];
6+
7+
$reason = ProbeCache::getFailure('mysqli', $configuration, static function () use ($host, $user, $passwd, $db, $port, $socket): ?string {
8+
$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
9+
if (!is_object($link)) {
10+
return sprintf("Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error());
11+
}
12+
13+
mysqli_close($link);
14+
return null;
15+
});
16+
17+
if (is_string($reason)) {
18+
die("skip $reason");
19+
}
720
?>

ext/mysqli/tests/test_setup/test_helpers.inc

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
require_once dirname(__DIR__, 4) . '/tests/probe_cache.inc';
4+
35
function get_default_host(): string {
46
static $host = null;
57
if ($host === null) {
@@ -110,24 +112,41 @@ function default_mysqli_connect(): \mysqli{
110112
function mysqli_check_skip_test(): void {
111113
mysqli_connect_or_skip();
112114
}
113-
function mysqli_connect_or_skip() {
114-
try {
115-
return default_mysqli_connect();
116-
} catch (\mysqli_sql_exception) {
117-
die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
115+
116+
function mysqli_connect_or_skip(): mysqli {
117+
$connection = null;
118+
$configuration = [
119+
get_default_host(),
120+
get_default_port(),
121+
get_default_user(),
122+
get_default_password(),
123+
get_default_database(),
124+
get_default_socket(),
125+
get_environment_connection_flags(),
126+
];
127+
128+
$reason = ProbeCache::getFailure('mysqli', $configuration, static function () use (&$connection): ?string {
129+
try {
130+
$connection = default_mysqli_connect();
131+
return null;
132+
} catch (mysqli_sql_exception $e) {
133+
return sprintf("Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error());
134+
}
135+
});
136+
137+
if (is_string($reason)) {
138+
die("skip $reason");
118139
}
140+
141+
return $connection;
119142
}
120143
function have_innodb(mysqli $link): bool {
121144
$res = $link->query("SELECT SUPPORT FROM INFORMATION_SCHEMA.ENGINES WHERE ENGINE = 'InnoDB'");
122145
$supported = $res->fetch_column();
123146
return $supported === 'YES' || $supported === 'DEFAULT';
124147
}
125148
function mysqli_check_innodb_support_skip_test(): void {
126-
try {
127-
$link = default_mysqli_connect();
128-
} catch (\mysqli_sql_exception) {
129-
die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
130-
}
149+
$link = mysqli_connect_or_skip();
131150
if (! have_innodb($link)) {
132151
die(sprintf("skip Needs InnoDB support"));
133152
}

ext/odbc/tests/skipif.inc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
<?php
22

33
include 'config.inc';
4+
require_once dirname(__DIR__, 3) . '/tests/probe_cache.inc';
45

5-
$conn = @odbc_connect($dsn, $user, $pass);
6-
if (!$conn) {
7-
die('skip could not connect');
6+
$conn = null;
7+
$reason = ProbeCache::getFailure('odbc', [$dsn, $user, $pass], static function () use ($dsn, $user, $pass, &$conn): ?string {
8+
$conn = @odbc_connect($dsn, $user, $pass);
9+
if (!$conn) {
10+
return 'could not connect';
11+
}
12+
13+
return null;
14+
});
15+
16+
if (is_string($reason)) {
17+
die("skip $reason");
818
}

ext/pdo/tests/bug_73234.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (str_starts_with(getenv('PDOTEST_DSN'), "firebird")) die('xfail firebird driv
1010
require_once $dir . 'pdo_test.inc';
1111
PDOTest::skip();
1212

13-
$db = PDOTest::factoryForSkip();
13+
$db = PDOTest::factory();
1414
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci') {
1515
die("xfail PDO::PARAM_NULL is not honored by OCI driver, related with bug #81586");
1616
}

ext/pdo/tests/bug_79106.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $dir = getenv('REDIR_TEST_DIR');
88
if (!$dir) die('skip no driver');
99
require_once $dir . 'pdo_test.inc';
1010
try {
11-
$db = PDOTest::factoryForSkip();
11+
$db = PDOTest::factory();
1212
} catch (PDOException $e) {
1313
die('skip ' . $e->getMessage());
1414
}

ext/pdo/tests/bug_79106_collision.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $dir = getenv('REDIR_TEST_DIR');
88
if (!$dir) die('skip no driver');
99
require_once $dir . 'pdo_test.inc';
1010
try {
11-
$db = PDOTest::factoryForSkip();
11+
$db = PDOTest::factory();
1212
} catch (PDOException $e) {
1313
die('skip ' . $e->getMessage());
1414
}

ext/pdo/tests/debug_emulated_prepares.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (false == $dir) die('skip no driver');
99
require_once $dir . 'pdo_test.inc';
1010
PDOTest::skip();
1111

12-
$db = PDOTest::factoryForSkip();
12+
$db = PDOTest::factory();
1313
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') die('skip pgsql has its own test for this feature');
1414
if (!@$db->getAttribute(PDO::ATTR_EMULATE_PREPARES) && !@$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true)) die('skip driver cannot emulate prepared statements');
1515
?>

ext/pdo/tests/gh8626.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (false == $dir) die('skip no driver');
99
require_once $dir . 'pdo_test.inc';
1010
PDOTest::skip();
1111

12-
$db = PDOTest::factoryForSkip();
12+
$db = PDOTest::factory();
1313
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci') {
1414
die("xfail OCI driver errorInfo is inconsistent with other PDO drivers");
1515
}

ext/pdo/tests/pdo_017.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (false == $dir) die('skip no driver');
99
require_once $dir . 'pdo_test.inc';
1010
PDOTest::skip();
1111

12-
$db = PDOTest::factoryForSkip();
12+
$db = PDOTest::factory();
1313
try {
1414
$db->beginTransaction();
1515
$db->rollback();

0 commit comments

Comments
 (0)