Skip to content

Commit

Permalink
Add an integration test for PushGateway
Browse files Browse the repository at this point in the history
 - runs BlackBox tests with docker-compose
 - adds a phpunit container (needed to avoid dependency cycle between
   php-fpm and nginx)
 - enables apcu on cli
  • Loading branch information
Ilya Margolin committed Sep 21, 2016
1 parent 1cf9107 commit e3d2de8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ docker-compose up
Pick the adapter you want to test.

```
ADAPTER=redis vendor/bin/phpunit tests/Test/BlackBoxTest.php
ADAPTER=apc vendor/bin/phpunit tests/Test/BlackBoxTest.php
docker-compose run phpunit env ADAPTER=apc vendor/bin/phpunit tests/Test/
docker-compose run phpunit env ADAPTER=redis vendor/bin/phpunit tests/Test/
```
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,27 @@ php-fpm:
- .:/var/www/html
links:
- redis
- pushgateway
environment:
- REDIS_HOST=redis

redis:
image: redis
ports:
- 6379:6379

pushgateway:
image: prom/pushgateway
ports:
- 9091:9091

phpunit:
build: php-fpm/
volumes:
- .:/var/www/html
links:
- redis
- pushgateway
- nginx
environment:
- REDIS_HOST=redis
1 change: 1 addition & 0 deletions php-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ RUN pecl install redis-2.2.8 && docker-php-ext-enable redis
RUN pecl install apcu-4.0.11 && docker-php-ext-enable apcu

COPY www.conf /usr/local/etc/php-fpm.d/
COPY docker-php-ext-apcu-cli.ini /usr/local/etc/php/conf.d/
1 change: 1 addition & 0 deletions php-fpm/docker-php-ext-apcu-cli.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apc.enable_cli = On
36 changes: 36 additions & 0 deletions tests/Test/BlackBoxPushGatewayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace Test;

use GuzzleHttp\Client;
use PHPUnit_Framework_TestCase;

use Prometheus\CollectorRegistry;
use Prometheus\PushGateway;
use Prometheus\Storage\APC;

class BlackBoxPushGatewayTest extends PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function pushGatewayShouldWork()
{
$adapter = new APC();
$registry = new CollectorRegistry($adapter);

$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
$counter->incBy(6, ['blue']);

$pushGateway = new PushGateway('pushgateway:9091');
$pushGateway->push($registry, 'my_job', array('instance' => 'foo'));

$httpClient = new Client();
$metrics = $httpClient->get("http://pushgateway:9091/metrics")->getBody()->getContents();
$this->assertContains(
'# HELP test_some_counter it increases
# TYPE test_some_counter counter
test_some_counter{instance="foo",job="my_job",type="blue"} 6',
$metrics
);
}
}
2 changes: 1 addition & 1 deletion tests/Test/BlackBoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BlackBoxTest extends PHPUnit_Framework_TestCase
public function setUp()
{
$this->adapter = getenv('ADAPTER');
$this->client = new Client(['base_uri' => 'http://192.168.59.100:8080/']);
$this->client = new Client(['base_uri' => 'http://nginx:80/']);
$this->client->get('/examples/flush_adapter.php?adapter=' . $this->adapter);
}

Expand Down

0 comments on commit e3d2de8

Please sign in to comment.