-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding tests for tracer provider behaviour a recent bug highlighted that if there is no reference to a tracer provider, then the shared state will shutdown, even if that shared state is being used by active tracers. Adding a phpdoc comment explaining this behavior, and some tests to demonstrate it * moving tests into integration * removing accidental covers annotation
- Loading branch information
Showing
3 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Tests\Integration\SDK; | ||
|
||
use OpenTelemetry\SDK\Trace\SpanProcessorInterface; | ||
use OpenTelemetry\SDK\Trace\TracerProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Prophet; | ||
|
||
/** | ||
* @coversNothing | ||
*/ | ||
class TracerProviderTest extends TestCase | ||
{ | ||
/** | ||
* @doesNotPerformAssertions | ||
*/ | ||
public function test_tracer_shuts_down_immediately_when_out_of_scope(): void | ||
{ | ||
$prophet = new Prophet(); | ||
$spanProcessor = $prophet->prophesize(SpanProcessorInterface::class); | ||
// @phpstan-ignore-next-line | ||
$spanProcessor->shutdown()->shouldBeCalledTimes(1); | ||
|
||
/* Because no reference is kept to the TracerProvider, it will immediately __destruct and shutdown, | ||
which will also shut down span processors in shared state. */ | ||
$tracer = (new TracerProvider($spanProcessor->reveal()))->getTracer('test'); | ||
|
||
$spanProcessor->checkProphecyMethodsPredictions(); | ||
} | ||
|
||
/** | ||
* @doesNotPerformAssertions | ||
*/ | ||
public function test_tracer_remains_in_scope(): void | ||
{ | ||
$prophet = new Prophet(); | ||
$spanProcessor = $prophet->prophesize(SpanProcessorInterface::class); | ||
// @phpstan-ignore-next-line | ||
$spanProcessor->shutdown()->shouldBeCalledTimes(0); | ||
|
||
$tracerProvider = new TracerProvider($spanProcessor->reveal()); | ||
$tracer = $tracerProvider->getTracer('test'); | ||
|
||
$spanProcessor->checkProphecyMethodsPredictions(); | ||
} | ||
} |