Fixed sudo issue in connpool tests

This commit is contained in:
David Puglielli 2017-06-21 14:59:53 -07:00
parent 16b53660b4
commit 8eb519c079
3 changed files with 46 additions and 10 deletions

View file

@ -1,6 +1,10 @@
sudo: required
os: linux
dist: trusty
group: edge
services:
- docker

View file

@ -7,6 +7,15 @@ This test also requires root privileges to modify odbcinst.ini file on Linux.
<?php if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') die("Skipped: Test for Linux and Mac"); ?>
--FILE--
<?php
// On Bamboo we must use sudo to fiddle with odbcinst.ini
// On travis-ci we can't use sudo
$sudo = '';
$user = posix_getpwuid(posix_geteuid());
if (strtolower($user['name']) == 'bamboo')
{
$sudo = 'sudo ';
}
$lines_to_add="CPTimeout=5\n[ODBC]\nPooling=Yes\n";
//get odbcinst.ini location
@ -14,14 +23,14 @@ $lines = explode("\n", shell_exec("odbcinst -j"));
$odbcinst_ini = explode(" ", $lines[1])[1];
//back up the odbcinst.ini file
shell_exec("sudo cp $odbcinst_ini $odbcinst_ini.bak");
shell_exec($sudo."cp $odbcinst_ini $odbcinst_ini.bak");
//enable pooling by modifying the odbcinst.ini file
$current = file_get_contents($odbcinst_ini);
$current.=$lines_to_add;
shell_exec("cp $odbcinst_ini .");
file_put_contents("odbcinst.ini", $current);
shell_exec("sudo cp odbcinst.ini $odbcinst_ini");
shell_exec($sudo."cp odbcinst.ini $odbcinst_ini");
//Creating a new php process, because for changes in odbcinst.ini file to affect pooling, drivers must be reloaded.
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/isPooled.php"));
@ -30,16 +39,23 @@ print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/isPooled.php"));
$current = file_get_contents($odbcinst_ini);
$current = str_replace($lines_to_add,'',$current);
file_put_contents("odbcinst.ini", $current);
shell_exec("sudo cp odbcinst.ini $odbcinst_ini");
shell_exec($sudo."cp odbcinst.ini $odbcinst_ini");
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/isPooled.php"));
?>
--CLEAN--
<?php
$sudo = '';
$user = posix_getpwuid(posix_geteuid());
if (strtolower($user['name']) == 'bamboo')
{
$sudo = 'sudo ';
}
$lines = explode("\n", shell_exec("odbcinst -j"));
$odbcinst_ini = explode(" ", $lines[1])[1];
shell_exec("sudo cp $odbcinst_ini.bak $odbcinst_ini");
shell_exec("sudo rm $odbcinst_ini.bak");
shell_exec($sudo."cp $odbcinst_ini.bak $odbcinst_ini");
shell_exec($sudo."rm $odbcinst_ini.bak");
?>
--EXPECT--
Pooled

View file

@ -7,6 +7,15 @@ This test also requires root privileges to modify odbcinst.ini file on Linux.
<?php if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') die("Skipped: Test for Linux and Mac"); ?>
--FILE--
<?php
// On Bamboo we must use sudo to fiddle with odbcinst.ini
// On travis-ci we can't use sudo
$sudo = '';
$user = posix_getpwuid(posix_geteuid());
if (strtolower($user['name']) == 'bamboo')
{
$sudo = 'sudo ';
}
$lines_to_add="CPTimeout=5\n[ODBC]\nPooling=Yes\n";
//get odbcinst.ini location
@ -14,14 +23,14 @@ $lines = explode("\n", shell_exec("odbcinst -j"));
$odbcinst_ini = explode(" ", $lines[1])[1];
//back up the odbcinst.ini file
shell_exec("sudo cp $odbcinst_ini $odbcinst_ini.bak");
shell_exec($sudo."cp $odbcinst_ini $odbcinst_ini.bak");
//enable pooling by modifying the odbcinst.ini file
$current = file_get_contents($odbcinst_ini);
$current.=$lines_to_add;
shell_exec("cp $odbcinst_ini .");
file_put_contents("odbcinst.ini", $current);
shell_exec("sudo cp odbcinst.ini $odbcinst_ini");
shell_exec($sudo."cp odbcinst.ini $odbcinst_ini");
//Creating a new php process, because for changes in odbcinst.ini file to affect pooling, drivers must be reloaded.
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/isPooled.php"));
@ -30,16 +39,23 @@ print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/isPooled.php"));
$current = file_get_contents($odbcinst_ini);
$current = str_replace($lines_to_add,'',$current);
file_put_contents("odbcinst.ini", $current);
shell_exec("sudo cp odbcinst.ini $odbcinst_ini");
shell_exec($sudo."cp odbcinst.ini $odbcinst_ini");
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/isPooled.php"));
?>
--CLEAN--
<?php
$sudo = '';
$user = posix_getpwuid(posix_geteuid());
if (strtolower($user['name']) == 'bamboo')
{
$sudo = 'sudo ';
}
$lines = explode("\n", shell_exec("odbcinst -j"));
$odbcinst_ini = explode(" ", $lines[1])[1];
shell_exec("sudo cp $odbcinst_ini.bak $odbcinst_ini");
shell_exec("sudo rm $odbcinst_ini.bak");
shell_exec($sudo."cp $odbcinst_ini.bak $odbcinst_ini");
shell_exec($sudo."rm $odbcinst_ini.bak");
?>
--EXPECT--
Pooled