Skip to content

Commit

Permalink
Fix TracingDriver, add TracingDriverTest
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Oct 1, 2019
1 parent 1657284 commit 5a294f1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
33 changes: 32 additions & 1 deletion lib/Loop/TracingDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function defer(callable $callback, $data = null): string

$this->creationTraces[$id] = formatStacktrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS));
$this->enabledWatchers[$id] = true;

return $id;
}

Expand All @@ -48,38 +49,47 @@ public function delay(int $delay, callable $callback, $data = null): string

$this->creationTraces[$id] = formatStacktrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS));
$this->enabledWatchers[$id] = true;

return $id;
}

public function repeat(int $interval, callable $callback, $data = null): string
{
$id = $this->driver->repeat($interval, $callback, $data);

$this->creationTraces[$id] = formatStacktrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS));
$this->enabledWatchers[$id] = true;

return $id;
}

public function onReadable($stream, callable $callback, $data = null): string
{
$id = $this->driver->onReadable($stream, $callback, $data);

$this->creationTraces[$id] = formatStacktrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS));
$this->enabledWatchers[$id] = true;

return $id;
}

public function onWritable($stream, callable $callback, $data = null): string
{
$id = $this->driver->onWritable($stream, $callback, $data);

$this->creationTraces[$id] = formatStacktrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS));
$this->enabledWatchers[$id] = true;

return $id;
}

public function onSignal(int $signo, callable $callback, $data = null): string
{
$id = $this->driver->onSignal($signo, $callback, $data);

$this->creationTraces[$id] = formatStacktrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS));
$this->enabledWatchers[$id] = true;

return $id;
}

Expand All @@ -100,6 +110,7 @@ public function cancel(string $watcherId)
{
$this->driver->cancel($watcherId);
$this->creationTraces[$watcherId] = formatStacktrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS));

unset($this->enabledWatchers[$watcherId], $this->unreferencedWatchers[$watcherId]);
}

Expand Down Expand Up @@ -156,6 +167,26 @@ public function dump(): string
return \rtrim($dump);
}

public function getInfo(): array
{
return $this->driver->getInfo();
}

public function __debugInfo()
{
return $this->driver->__debugInfo();
}

public function now(): int
{
return $this->driver->now();
}

protected function error(\Throwable $exception)
{
$this->driver->error($exception);
}

/** @inheritdoc */
protected function activate(array $watchers)
{
Expand All @@ -177,7 +208,7 @@ protected function deactivate(Watcher $watcher)
private function getCreationTrace(string $watcher): string
{
if (!isset($this->creationTraces[$watcher])) {
new InvalidWatcherError($watcher, "An invalid watcher has been used: " . $watcher);
throw new InvalidWatcherError($watcher, "An invalid watcher has been used: " . $watcher);
}

return $this->creationTraces[$watcher];
Expand Down
26 changes: 26 additions & 0 deletions test/Loop/TracingDriverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Amp\Test\Loop;

use Amp\Loop\NativeDriver;
use Amp\Loop\TracingDriver;

class TracingDriverTest extends DriverTest
{
public function getFactory(): callable
{
return static function () {
return new TracingDriver(new NativeDriver);
};
}

/**
* @dataProvider provideRegistrationArgs
* @group memoryleak
*/
public function testNoMemoryLeak($type, $args)
{
// Skip, because the driver intentionally leaks
$this->assertTrue(true);
}
}

0 comments on commit 5a294f1

Please sign in to comment.