Skip to content

Commit

Permalink
Add push server test case
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Aug 25, 2016
1 parent 5582be5 commit a5fa66d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
28 changes: 20 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:
global:
- DEPENDENCIES=standard
- APC=true
- TRAVIS_TEST_EXCLUDES="--exclude-group slow,jpgraph"
- TRAVIS_TEST_EXCLUDES="--exclude-group slow,jpgraph,pushserver"
matrix:
- DB=mysql
- DB=pgsql
Expand All @@ -30,7 +30,10 @@ matrix:
include:
# httpd-based
- php: 5.4
env: DB=mysql TEST_ADAPTER=HTTP
env: DB=mysql TEST_COMPONENT=HTTPD
# push-server
- php: 5.4
env: DB=mysql TEST_COMPONENT=PUSH_SERVER
# from..to
- php: 5.4
env: DB=mysql DEPENDENCIES=lowest
Expand Down Expand Up @@ -76,7 +79,7 @@ install:
- if [ "$DEPENDENCIES" = "highest" ]; then composer update -n; fi
- if [ "$JSLINT" = true ]; then npm install; fi
- if [ "$SECURITY" = true ]; then wget http://get.sensiolabs.org/security-checker.phar; fi
- if [ "$TEST_ADAPTER" = "HTTP" ]; then composer require volkszaehler/httpd:dev-master jenssegers/proxy:~2.2; fi
- if [ "$TEST_COMPONENT" = "HTTPD" ]; then composer require volkszaehler/httpd:dev-master jenssegers/proxy:~2.2; fi

# add apc cache
- |
Expand All @@ -100,7 +103,7 @@ before_script:
- sed -i "s/'vz'/'$USER'/" etc/volkszaehler.conf.php
- sed -i "s/'demo'/'$PASSWORD'/" etc/volkszaehler.conf.php
- sed -i "s/'volkszaehler'/'$DATABASE'/" etc/volkszaehler.conf.php
- if [ "$DB" = "sqlite" ]; then sed -i "s/\?>/\$config['db']['path']\ =\ VZ_DIR.'\/sqlite.db3'\n?>/" etc/volkszaehler.conf.php; fi
- if [ "$DB" = "sqlite" ]; then sed -i "s/\?>/\$config['db']['path']\ =\ VZ_DIR.'\/sqlite.db3'\;\n?>/" etc/volkszaehler.conf.php; fi
- cat etc/volkszaehler.conf.php

# create database
Expand All @@ -112,15 +115,21 @@ before_script:

# setup local middleware
- |
if [ "$TEST_ADAPTER" = "HTTP" ]; then
sed -i "s/testAdapter\" value=\".*\"/testAdapter\" value=\"$TEST_ADAPTER\"/" phpunit.xml
if [ "$TEST_COMPONENT" = "HTTPD" ]; then
sed -i "s/testAdapter\" value=\".*\"/testAdapter\" value=\"$TEST_COMPONENT\"/" phpunit.xml
vendor/bin/httpd.php start &
HTTPD_PID=$!
echo "Started httpd with pid $HTTPD_PID"
fi
# push server tests
- if [ "$TEST_COMPONENT" = "PUSH_SERVER" ]; then sed -i "s/\?>/\$config['push']['enabled']\ =\ true\;\n?>/" etc/volkszaehler.conf.php; fi
- if [ "$TEST_COMPONENT" = "PUSH_SERVER" ]; then
php misc/tools/push-server.php &
fi

after_script:
- if [ "$TEST_ADAPTER" = "HTTP" ]; then kill -9 $HTTPD_PID; fi
- if [ "$TEST_COMPONENT" = "HTTPD" ]; then kill -9 $HTTPD_PID; fi

script:
# run core tests
Expand All @@ -129,7 +138,7 @@ script:
# run aggregation tests (mysql only)
- if [ "$DB" = "mysql" ]; then sed -i "s/\?>/\$config['aggregation']\ =\ true;\n?>/" etc/volkszaehler.conf.php; fi
- |
if [ "$DB" = "mysql" -a "$TEST_ADAPTER" = "HTTP" ]; then
if [ "$DB" = "mysql" -a "$TEST_COMPONENT" = "HTTPD" ]; then
kill -9 $HTTPD_PID
sleep 10
vendor/bin/httpd.php start &
Expand All @@ -141,6 +150,9 @@ script:
# run aggregation tool itself (mysql only)
- if [ "$DB" = "mysql" ]; then php misc/tools/aggregate.php run -m delta -l hour; fi

# push server tests
- if [ "$TEST_COMPONENT" = "PUSH_SERVER" ]; then phpunit --group pushserver; fi

# jslint javascript sources
- if [ "$JSLINT" = true ]; then gulp jshint; fi

Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<exclude>
<group>slow</group>
<group>jpgraph</group>
<group>pushserver</group>
</exclude>
</groups>

Expand Down
50 changes: 50 additions & 0 deletions test/PushServerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Meter tests
*
* @package Test
* @author Andreas Götz <[email protected]>
*/

namespace Tests;

use Volkszaehler\Util;

class PushServerTest extends Data
{
// channel properties
static $resolution = 100;

/**
* Create channel
*/
static function setupBeforeClass() {
parent::setupBeforeClass();
self::$uuid = self::createChannel('Counter', 'electric meter', self::$resolution);
}

/**
* @group pushserver
*/
function testPushMessage() {
$this->assertTrue(Util\Configuration::read('push.enabled'), 'Push server disabled');

$exitCode = null;
$port = Util\Configuration::read('push.server');
$curl = "curl %s -s -m 3 -X POST -d '{\"data\":[{\"uuid\":\"%s\",\"tuples\":[[1,1,1]]}]}' localhost:%d 2>&1";

// run and test for failure
$cmd = sprintf($curl, '-f', self::$uuid, $port);
passthru($cmd, $exitCode);

// run to get output
if ($exitCode !== 0) {
$cmd = sprintf($curl, '-i', self::$uuid, $port);
passthru($cmd);
}

$this->assertTrue($exitCode === 0, sprintf('Curl failed with exit code %d', $exitCode));
}
}

?>

0 comments on commit a5fa66d

Please sign in to comment.