Skip to content
This repository was archived by the owner on Oct 22, 2019. It is now read-only.

Commit e3d2de8

Browse files
author
Ilya Margolin
committed
Add an integration test for PushGateway
- runs BlackBox tests with docker-compose - adds a phpunit container (needed to avoid dependency cycle between php-fpm and nginx) - enables apcu on cli
1 parent 1cf9107 commit e3d2de8

File tree

6 files changed

+58
-3
lines changed

6 files changed

+58
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ docker-compose up
9797
Pick the adapter you want to test.
9898

9999
```
100-
ADAPTER=redis vendor/bin/phpunit tests/Test/BlackBoxTest.php
101-
ADAPTER=apc vendor/bin/phpunit tests/Test/BlackBoxTest.php
100+
docker-compose run phpunit env ADAPTER=apc vendor/bin/phpunit tests/Test/
101+
docker-compose run phpunit env ADAPTER=redis vendor/bin/phpunit tests/Test/
102102
```

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,27 @@ php-fpm:
1111
- .:/var/www/html
1212
links:
1313
- redis
14+
- pushgateway
1415
environment:
1516
- REDIS_HOST=redis
1617

1718
redis:
1819
image: redis
1920
ports:
2021
- 6379:6379
22+
23+
pushgateway:
24+
image: prom/pushgateway
25+
ports:
26+
- 9091:9091
27+
28+
phpunit:
29+
build: php-fpm/
30+
volumes:
31+
- .:/var/www/html
32+
links:
33+
- redis
34+
- pushgateway
35+
- nginx
36+
environment:
37+
- REDIS_HOST=redis

php-fpm/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ RUN pecl install redis-2.2.8 && docker-php-ext-enable redis
44
RUN pecl install apcu-4.0.11 && docker-php-ext-enable apcu
55

66
COPY www.conf /usr/local/etc/php-fpm.d/
7+
COPY docker-php-ext-apcu-cli.ini /usr/local/etc/php/conf.d/

php-fpm/docker-php-ext-apcu-cli.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
apc.enable_cli = On
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
namespace Test;
3+
4+
use GuzzleHttp\Client;
5+
use PHPUnit_Framework_TestCase;
6+
7+
use Prometheus\CollectorRegistry;
8+
use Prometheus\PushGateway;
9+
use Prometheus\Storage\APC;
10+
11+
class BlackBoxPushGatewayTest extends PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @test
15+
*/
16+
public function pushGatewayShouldWork()
17+
{
18+
$adapter = new APC();
19+
$registry = new CollectorRegistry($adapter);
20+
21+
$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
22+
$counter->incBy(6, ['blue']);
23+
24+
$pushGateway = new PushGateway('pushgateway:9091');
25+
$pushGateway->push($registry, 'my_job', array('instance' => 'foo'));
26+
27+
$httpClient = new Client();
28+
$metrics = $httpClient->get("http://pushgateway:9091/metrics")->getBody()->getContents();
29+
$this->assertContains(
30+
'# HELP test_some_counter it increases
31+
# TYPE test_some_counter counter
32+
test_some_counter{instance="foo",job="my_job",type="blue"} 6',
33+
$metrics
34+
);
35+
}
36+
}

tests/Test/BlackBoxTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BlackBoxTest extends PHPUnit_Framework_TestCase
2020
public function setUp()
2121
{
2222
$this->adapter = getenv('ADAPTER');
23-
$this->client = new Client(['base_uri' => 'http://192.168.59.100:8080/']);
23+
$this->client = new Client(['base_uri' => 'http://nginx:80/']);
2424
$this->client->get('/examples/flush_adapter.php?adapter=' . $this->adapter);
2525
}
2626

0 commit comments

Comments
 (0)