Skip to content

Commit

Permalink
Add support for running all tests on travis.
Browse files Browse the repository at this point in the history
Move travis before_script to a script in extras.
Add apache and mysql confs to extras.
Modify test harnesses to be travis aware.
  (Make sure and send some output, sleep occasionally)
Switch migration urls to non-redirecting www.
Occasionally output while in Travis mode to prevent travis stopping.
Added a mode to just test install to allow the build matrix to only test
   the install in one build, not all.

references #1328
  • Loading branch information
cdmoyer authored and ginatrapani committed Feb 28, 2014
1 parent 027f7d0 commit 5e5649b
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 63 deletions.
25 changes: 16 additions & 9 deletions .travis.yml
@@ -1,17 +1,24 @@
language: php

php:
- 5.5
- 5.4
- 5.3
- 5.2

before_script:
- mysql -e 'create database thinkup'
- cp extras/dev/config/config.inc.php webapp/config.inc.php
- cp extras/dev/config/config.tests.inc.php tests/config.tests.inc.php
- chmod -R 777 webapp/data
- mkdir webapp/data/logs/
- touch webapp/data/logs/stream.log
- touch webapp/data/logs/crawler.log
env:
- JUST_INSTALL=1
- SKIP_UPGRADE_TESTS=1

matrix:
exclude:
- php: 5.5
env: JUST_INSTALL=1
- php: 5.3
env: JUST_INSTALL=1
- php: 5.2
env: JUST_INSTALL=1

before_script: extras/dev/travis/before.sh

script: php tests/all_unit_tests.php
script: php tests/all_tests.php
2 changes: 1 addition & 1 deletion extras/dev/config/config.inc.php
Expand Up @@ -70,7 +70,7 @@

// Set this to true if you want your PDO object's database connection's charset to be explicitly set to utf8.
// If false (or unset), the database connection's charset will not be explicitly set.
$THINKUP_CFG['set_pdo_charset'] = false;
$THINKUP_CFG['set_pdo_charset'] = true;

//TESTS OVERRIDE: Run against the tests database and use unpackaged developer /thinkup/webapp/ folder structure
if ((isset($_COOKIE['TU_MODE']) && $_COOKIE['TU_MODE']=='TESTS') && !isset($_SESSION["RD_MODE"])
Expand Down
37 changes: 37 additions & 0 deletions extras/dev/travis/before.sh
@@ -0,0 +1,37 @@
#!/bin/sh

sudo cp extras/dev/travis/my-override.cnf /etc/mysql/conf.d/
sudo service mysql restart
mysql -e 'create database thinkup'
cp extras/dev/config/config.inc.php webapp/config.inc.php
cp extras/dev/config/config.tests.inc.php tests/config.tests.inc.php
mkdir webapp/data/sessions/
chmod -R 777 webapp/data
chmod -f -R 777 build
mkdir webapp/data/logs/

touch webapp/data/logs/stream.log
touch webapp/data/logs/crawler.log
sudo apt-get install apache2 libapache2-mod-fastcgi
export PHPV=$(phpenv version-name)
echo "Running PHP = $PHPV"
echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$PHPV/etc/php.ini
if [ "$PHPV" = "5.2" ]; then
echo "I'm in here."
sudo sh -c "echo 'error_reporting = 22527' >> ~/.phpenv/versions/$PHPV/etc/php.ini"
sudo sh -c "echo 'session.save_path = "$(pwd)/webapp/data/sessions"' >> ~/.phpenv/versions/$PHPV/etc/php.ini"
sudo a2enmod rewrite actions alias
sudo cp -f extras/dev/travis/travis-ci-apache-php52 /etc/apache2/sites-available/default
sudo sed -e "s?%PHPPATH%?/home/travis/.phpenv/versions/5.2/bin?g" --in-place /etc/apache2/sites-available/default
else
sudo cp ~/.phpenv/versions/$PHPV/etc/php-fpm.conf.default ~/.phpenv/versions/$PHPV/etc/php-fpm.conf
sudo sh -c "echo 'php_value[error_reporting] = 22527' >> ~/.phpenv/versions/$PHPV/etc/php-fpm.conf"
sudo sh -c "echo 'php_value[session.save_path] = "$(pwd)/webapp/data/sessions"' >> ~/.phpenv/versions/$PHPV/etc/php-fpm.conf"
echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$PHPV/etc/php.ini
~/.phpenv/versions/$PHPV/sbin/php-fpm
sudo a2enmod rewrite actions fastcgi alias
sudo cp -f extras/dev/travis/travis-ci-apache /etc/apache2/sites-available/default
fi

sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)/webapp?g" --in-place /etc/apache2/sites-available/default
sudo service apache2 restart
6 changes: 6 additions & 0 deletions extras/dev/travis/my-override.cnf
@@ -0,0 +1,6 @@
[mysqld]
collation-server = utf8_general_ci
collation_server = utf8_general_ci
init_connect='SET collation_connection = utf8_general_ci'
wait_timeout = 28800
interactive_timeout = 28800
18 changes: 18 additions & 0 deletions extras/dev/travis/travis-ci-apache
@@ -0,0 +1,18 @@
<VirtualHost *:80>
DocumentRoot %TRAVIS_BUILD_DIR%

<Directory "%TRAVIS_BUILD_DIR%">
Options FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>

# Wire up Apache to use Travis CI's php-fpm.
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
</IfModule>
</VirtualHost>
15 changes: 15 additions & 0 deletions extras/dev/travis/travis-ci-apache-php52
@@ -0,0 +1,15 @@
<VirtualHost *:80>
DocumentRoot %TRAVIS_BUILD_DIR%

<Directory "%TRAVIS_BUILD_DIR%">
Options FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>

ScriptAlias /local-bin %PHPPATH%
AddType application/x-httpd-php .php
AddHandler application/x-httpd-php5 php
Action application/x-httpd-php5 /local-bin/php-cgi
</VirtualHost>
6 changes: 3 additions & 3 deletions extras/scripts/generate-distribution
Expand Up @@ -9,7 +9,7 @@ if [ ! -d "$build" ]; then
fi

# Copy the webapp folder to build
cp -R webapp build/.
cp -R webapp build/. 2>/dev/null

# Rename it thinkup
mv build/webapp build/thinkup
Expand All @@ -23,7 +23,7 @@ rm -rf build/thinkup/plugins/*/tests/
rm -rf build/thinkup/_lib/extlib/simpletest/
rm -rf build/thinkup/test_installer/
rm -rf build/thinkup/data/*
rm build/thinkup/data/.ht*
rm -f build/thinkup/data/.ht*
cp -R webapp/data/README.md build/thinkup/data/.
rm -rf build/thinkup/config.inc.php
rm -rf build/thinkup/install/sql/build-db_mysql.sql
Expand All @@ -41,4 +41,4 @@ rm -rf build/thinkup/plugins/insightsgenerator/insights/hellothinkupinsight.php
cd build/
zip -r thinkup.zip thinkup
zip -d thinkup.zip __MACOSX* *.DS_Store *.ecoder_permissions_check.txt
rm -rf thinkup
rm -rf thinkup
5 changes: 4 additions & 1 deletion tests/WebTestOfInstallation.php
Expand Up @@ -174,6 +174,7 @@ public function testSuccessfulInstallationInNonWritableFolder() {

//sleep(1000);
//Start installation process
@exec('chmod -R 555 webapp/test_installer/thinkup/data;');
$this->get($this->url.'/test_installer/thinkup/');
$this->assertTitle("ThinkUp");

Expand Down Expand Up @@ -203,6 +204,7 @@ public function testSuccessfulInstallationInNonWritableFolder() {
$this->setField('db_passwd', $THINKUP_CFG['db_password']);
$this->setField('db_socket', $THINKUP_CFG['db_socket']);
$this->setField('db_prefix', $THINKUP_CFG['table_prefix']);
@exec('chmod 555 webapp/test_installer/thinkup;');
$this->clickSubmitByName('Submit');

$this->assertNoText('ThinkUp has been installed successfully. Check your email account; an account activation '.
Expand All @@ -213,6 +215,7 @@ public function testSuccessfulInstallationInNonWritableFolder() {
$this->assertTrue(!file_exists($THINKUP_CFG['source_root_path'].
'/webapp/test_installer/thinkup/config.inc.php'));

@exec('chmod 777 webapp/test_installer/thinkup;');
@exec('touch webapp/test_installer/thinkup/config.inc.php;'.
'chmod 777 webapp/test_installer/thinkup/config.inc.php');

Expand Down Expand Up @@ -320,4 +323,4 @@ public function testFieldLevelMessagesForInvalidInputs() {
// $this->get($this->url.'/test_installer/thinkup/install/index.php?step=2');
// $this->assertFieldById('timezone', '');
// }
}
}
45 changes: 40 additions & 5 deletions tests/WebTestOfUpgradeDatabase.php
Expand Up @@ -155,6 +155,7 @@ private function setUpApp($version, $MIGRATIONS) {
// run updates and migrations
require dirname(__FILE__) . '/migration-assertions.php';
$this->debug("Setting up base install for upgrade: $version");
$this->travisHeartbeat();
$zip_url = $MIGRATIONS[$version]['zip_url'];

require THINKUP_WEBAPP_PATH.'config.inc.php';
Expand All @@ -175,11 +176,13 @@ private function setUpApp($version, $MIGRATIONS) {
chdir(dirname(__FILE__) . '/../');
exec('cd webapp/test_installer/;chmod -R 777 thinkup/_lib/view/compiled_view;');
}
$this->travisSleepTest();

//Config file doesn't exist
$this->assertFalse(file_exists($THINKUP_CFG['source_root_path'].
'webapp/test_installer/thinkup/config.inc.php'));


//Set test mode
$this->get($this->url.'/test_installer/thinkup/install/setmode.php?m=tests');
//Include config again to get test db credentials
Expand Down Expand Up @@ -300,13 +303,15 @@ private function runMigrations($TMIGRATIONS, $base_version, $fail = false) {
require THINKUP_WEBAPP_PATH.'config.inc.php';
foreach($TMIGRATIONS as $version => $migration_data) {
$this->debug("Running migration test for version: $version");
$this->travisHeartbeat();
$url = $migration_data['zip_url'];
$zipfile = $this->getInstall($url, $version, $this->installs_dir);
$this->debug("unzipping $zipfile");
chdir(dirname(__FILE__) . '/../');
//Extract into test_installer directory and set necessary folder permissions
exec('cp ' . $zipfile . ' webapp/test_installer/.;cd webapp/test_installer/;'.
'rm -rf thinkup/_lib;rm -rf thinkup/plugins;unzip -o ' . $zipfile.';');
$this->travisSleepTest();
if (!file_exists($this->install_dir.'/thinkup/data/compiled_view')) {
if (!file_exists($this->install_dir.'/thinkup/data')) {
exec('mkdir thinkup/data;');
Expand Down Expand Up @@ -345,7 +350,9 @@ private function runMigrations($TMIGRATIONS, $base_version, $fail = false) {
'INSERT INTO tu_follows_b10 (SELECT', $msql);
file_put_contents($migration_10, $msql);
}
//sleep(1000);
if (getenv('TRAVIS')=='true') {
sleep(30);
}
$this->get($this->url.'/test_installer/thinkup/');
$this->assertText("ThinkUp's database needs an upgrade");
// token could be in 1 of 2 places, depending on what version is running
Expand Down Expand Up @@ -387,8 +394,8 @@ private function runMigrations($TMIGRATIONS, $base_version, $fail = false) {
}
$this->assertText('{ "processed":true,');
$content = $this->getBrowser()->getContent();
if ( !preg_match('/"processed":true/', $content)) {
error_log($content);
if (!preg_match('/"processed":true/', $content)) {
$this->debug('ERROR: '.$content);
return;
}
if (isset($json_array[$cnt]) && $json_array[$cnt]->version == $json_migration->version) {
Expand All @@ -411,8 +418,8 @@ private function runMigrations($TMIGRATIONS, $base_version, $fail = false) {
$this->assertEqual(preg_match($assertion_sql['match'], $data[ $assertion_sql['column'] ]),
1, $assertion_sql['match'] . ' should match ' . $data[ $assertion_sql['column'] ]);
if ( ! preg_match($assertion_sql['match'], $data[ $assertion_sql['column'] ])) {
error_log("TEST FAIL DEBUGGING:");
error_log('Query for assertion ' . $assertion_sql['query'] . " with match "
$this->debug("TEST FAIL DEBUGGING:");
$this->debug('Query for assertion ' . $assertion_sql['query'] . " with match "
. $assertion_sql['match'] . " failed");
}
}
Expand Down Expand Up @@ -480,4 +487,32 @@ private function getInstall($url, $version, $path) {
}
return $zipfile;
}

/**
* Travis will give up if tests go 10 minutes without any output.
* This will randomly spit out a .... to keep travis heappy.
*/
private function travisHeartbeat() {
// We've got to output something occasionally or travis thinks we died.
if (getenv('TRAVIS')=='true') {
print $str."\n";
}
}

/**
* Latency in travis means we occasionally need to sleep a bit
* and make sure that the new setup is ready before proceeding.
*/
private function travisSleepTest() {
if (getenv('TRAVIS')=='true') {
$tries = 0;
do {
$this->debug('Sleeping for Travis latency: ' . (10*$tries). ' seconds.');
sleep(10 * $tries++);
$this->get($this->url.'/test_installer/thinkup/');
$content = $this->getBrowser()->getContent();
if ($tries > 3) break;
} while (preg_match('/Fatal error: (Class|Call to und)/', $content));
}
}
}
2 changes: 1 addition & 1 deletion tests/all_install_tests.php
Expand Up @@ -52,4 +52,4 @@
if (isset($RUNNING_ALL_TESTS) && $RUNNING_ALL_TESTS) {
$TOTAL_PASSES = $TOTAL_PASSES + $tr->getPassCount();
$TOTAL_FAILURES = $TOTAL_FAILURES + $tr->getFailCount();
}
}
20 changes: 16 additions & 4 deletions tests/all_tests.php
Expand Up @@ -39,6 +39,7 @@
SKIP_UPGRADE_TESTS=1 Skip upgrade tests, ie, do a short run
TEST_TIMING=1 Output test run timing information
RD_MODE=1 Use database stored on RAM disk (for speed improvements)
JUST_INSTALL=1 Only run install tests
Arguments:
-help, -h Show this help message
Expand All @@ -48,20 +49,30 @@
return;
}

$JUST_INSTALL = getenv('JUST_INSTALL') == 1;

$RUNNING_ALL_TESTS = true;
$TOTAL_PASSES = 0;
$TOTAL_FAILURES = 0;
$start_time = microtime(true);

require_once THINKUP_ROOT_PATH.'tests/all_model_tests.php';
if (!$JUST_INSTALL) {
require_once THINKUP_ROOT_PATH.'tests/all_model_tests.php';
}

require_once THINKUP_ROOT_PATH.'tests/all_plugin_tests.php';
if (!$JUST_INSTALL) {
require_once THINKUP_ROOT_PATH.'tests/all_plugin_tests.php';
}

require_once THINKUP_ROOT_PATH.'tests/all_integration_tests.php';
if (!$JUST_INSTALL) {
require_once THINKUP_ROOT_PATH.'tests/all_integration_tests.php';
}

require_once THINKUP_ROOT_PATH.'tests/all_install_tests.php';

require_once THINKUP_ROOT_PATH.'tests/all_controller_tests.php';
if (!$JUST_INSTALL) {
require_once THINKUP_ROOT_PATH.'tests/all_controller_tests.php';
}

$end_time = microtime(true);
$total_time = ($end_time - $start_time) / 60;
Expand All @@ -77,3 +88,4 @@
" words of application documentation
";
if ($TOTAL_FAILURES > 0) exit(1);
12 changes: 12 additions & 0 deletions tests/classes/class.ThinkUpBasicUnitTestCase.php
Expand Up @@ -36,6 +36,18 @@ class ThinkUpBasicUnitTestCase extends UnitTestCase {
*/
const CSRF_TOKEN = 'test_csrf_token_123';

/**
* Constructor
* Occasionally spit out a . if we are running in travis so that travis doesn't give up on us.
*/
public function __construct() {
parent::__construct();
if (getenv('TRAVIS') == 'true') {
if (mt_rand(1,20) == 1) print ".";
sleep(3);
}
}

/**
* Initialize Config and Webapp objects, clear $_SESSION, $_POST, $_GET, $_REQUEST
*/
Expand Down

0 comments on commit 5e5649b

Please sign in to comment.