Skip to content

Commit c8b5825

Browse files
authored
Merge pull request #675: support xdebug in tests
2 parents f683231 + 9f76c6e commit c8b5825

File tree

9 files changed

+55
-30
lines changed

9 files changed

+55
-30
lines changed
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Temporal\Tests\Acceptance\App\Input;
5+
namespace Temporal\Testing;
66

77
final class Command
88
{
@@ -18,12 +18,19 @@ final class Command
1818
/** @var non-empty-string|null */
1919
public ?string $tlsCert = null;
2020

21+
private array $xdebug;
22+
2123
public static function fromEnv(): self
2224
{
2325
$self = new self();
2426

2527
$self->namespace = \getenv('TEMPORAL_NAMESPACE') ?: 'default';
2628
$self->address = \getenv('TEMPORAL_ADDRESS') ?: 'localhost:7233';
29+
$self->xdebug = [
30+
'xdebug.mode' => \ini_get('xdebug.mode'),
31+
'xdebug.start_with_request' => \ini_get('xdebug.start_with_request'),
32+
'xdebug.start_upon_error' => \ini_get('xdebug.start_upon_error'),
33+
];
2734
// $self->tlsCert =
2835
// $self->tlsKey =
2936

@@ -66,7 +73,7 @@ public static function fromCommandLine(array $argv): self
6673
/**
6774
* @return list<non-empty-string> CLI arguments that can be parsed by `fromCommandLine`
6875
*/
69-
public function toCommandLineArguments(): array
76+
public function getCommandLineArguments(): array
7077
{
7178
$result = [];
7279
$this->namespace === null or $result[] = "namespace=$this->namespace";
@@ -76,4 +83,13 @@ public function toCommandLineArguments(): array
7683

7784
return $result;
7885
}
86+
87+
public function getPhpBinaryArguments(): array
88+
{
89+
$result = [];
90+
foreach ($this->xdebug as $key => $value) {
91+
$result[] = "-d$key=$value";
92+
}
93+
return $result;
94+
}
7995
}

testing/src/Environment.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ public function startTemporalServer(
102102
$this->temporalServerProcess->setTimeout($commandTimeout);
103103
$this->temporalServerProcess->start();
104104

105-
$limit = 1_000_000;
106-
while (!$this->temporalServerProcess->isRunning() && $limit > 0) {
107-
\usleep($limit -= 1000);
105+
$deadline = \microtime(true) + 1.2;
106+
while (!$this->temporalServerProcess->isRunning() && \microtime(true) < $deadline) {
107+
\usleep(10_000);
108108
}
109109

110110
if (!$this->temporalServerProcess->isRunning()) {
@@ -132,10 +132,7 @@ public function startTemporalTestServer(int $commandTimeout = 10): void
132132
$this->temporalTestServerProcess->setTimeout($commandTimeout);
133133
$this->temporalTestServerProcess->start();
134134

135-
$limit = 1_000_000;
136-
while (!$this->temporalTestServerProcess->isRunning() && $limit > 0) {
137-
\usleep($limit -= 1000);
138-
}
135+
\sleep(1);
139136

140137
if (!$this->temporalTestServerProcess->isRunning()) {
141138
$this->output->writeln('<error>error</error>');

tests/Acceptance/App/Runtime/RRStarter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ public function start(): void
3939
"temporal.address={$this->runtime->address}",
4040
'-o',
4141
'server.command=' . \implode(',', [
42-
'php',
42+
PHP_BINARY,
43+
...$run->getPhpBinaryArguments(),
4344
$this->runtime->rrConfigDir . DIRECTORY_SEPARATOR . 'worker.php',
44-
...$run->toCommandLineArguments(),
45+
...$run->getCommandLineArguments(),
4546
]),
4647
];
4748
$run->tlsKey === null or $rrCommand = [...$rrCommand, '-o', "tls.key={$run->tlsKey}"];

tests/Acceptance/App/Runtime/State.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Temporal\Tests\Acceptance\App\Runtime;
66

7-
use Temporal\Tests\Acceptance\App\Input\Command;
87
use Temporal\DataConverter\PayloadConverterInterface;
8+
use Temporal\Testing\Command;
99

1010
final class State
1111
{

tests/Acceptance/App/RuntimeBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PHPUnit\Framework\Attributes\Test;
88
use Temporal\Activity\ActivityInterface;
99
use Temporal\DataConverter\PayloadConverterInterface;
10-
use Temporal\Tests\Acceptance\App\Input\Command;
10+
use Temporal\Testing\Command;
1111
use Temporal\Tests\Acceptance\App\Input\Feature;
1212
use Temporal\Tests\Acceptance\App\Runtime\State;
1313
use Temporal\Worker\FeatureFlags;

tests/Acceptance/bootstrap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
use Temporal\Client\WorkflowStubInterface;
1919
use Temporal\DataConverter\DataConverter;
2020
use Temporal\DataConverter\DataConverterInterface;
21+
use Temporal\Testing\Command;
2122
use Temporal\Tests\Acceptance\App\Feature\WorkflowStubInjector;
22-
use Temporal\Tests\Acceptance\App\Input\Command;
2323
use Temporal\Tests\Acceptance\App\Runtime\ContainerFacade;
2424
use Temporal\Tests\Acceptance\App\Runtime\RRStarter;
2525
use Temporal\Tests\Acceptance\App\Runtime\State;
2626
use Temporal\Tests\Acceptance\App\Runtime\TemporalStarter;
2727
use Temporal\Tests\Acceptance\App\RuntimeBuilder;
2828
use Temporal\Tests\Acceptance\App\Support;
2929

30-
chdir(__DIR__ . '/../..');
30+
\chdir(__DIR__ . '/../..');
3131
require './vendor/autoload.php';
3232

3333
RuntimeBuilder::init();
@@ -91,8 +91,8 @@
9191
$container->bindSingleton(ScheduleClientInterface::class, $scheduleClient);
9292
$container->bindInjector(WorkflowStubInterface::class, WorkflowStubInjector::class);
9393
$container->bindSingleton(DataConverterInterface::class, $converter);
94-
$container->bind(RPCInterface::class, static fn() => RPC::create(getenv('RR_RPC_ADDRESS') ?: 'tcp://127.0.0.1:6001'));
94+
$container->bind(RPCInterface::class, static fn() => RPC::create(\getenv('RR_RPC_ADDRESS') ?: 'tcp://127.0.0.1:6001'));
9595
$container->bind(
9696
StorageInterface::class,
97-
fn(#[Proxy] ContainerInterface $c): StorageInterface => $c->get(Factory::class)->select('harness'),
97+
static fn(#[Proxy] ContainerInterface $c): StorageInterface => $c->get(Factory::class)->select('harness'),
9898
);

tests/Acceptance/worker.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
declare(strict_types=1);
44

5-
use Temporal\Internal\Support\StackRenderer;
6-
use Temporal\Tests\Acceptance\App\Input\Command;
7-
use Temporal\Tests\Acceptance\App\Runtime\Feature;
8-
use Temporal\Tests\Acceptance\App\Runtime\State;
9-
use Temporal\Tests\Acceptance\App\RuntimeBuilder;
105
use Psr\Container\ContainerInterface;
116
use Spiral\Core\Attribute\Proxy;
127
use Spiral\Goridge\RPC\RPC;
@@ -26,6 +21,11 @@
2621
use Temporal\DataConverter\NullConverter;
2722
use Temporal\DataConverter\ProtoConverter;
2823
use Temporal\DataConverter\ProtoJsonConverter;
24+
use Temporal\Internal\Support\StackRenderer;
25+
use Temporal\Testing\Command;
26+
use Temporal\Tests\Acceptance\App\Runtime\Feature;
27+
use Temporal\Tests\Acceptance\App\Runtime\State;
28+
use Temporal\Tests\Acceptance\App\RuntimeBuilder;
2929
use Temporal\Worker\WorkerFactoryInterface;
3030
use Temporal\Worker\WorkerInterface;
3131
use Temporal\WorkerFactory;

tests/Functional/.rr.silent.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ rpc:
55

66
server:
77
command: "php worker.php"
8-
env:
9-
XDEBUG_SESSION: 1
108

119
# Workflow and activity mesh service
1210
temporal:

tests/Functional/bootstrap.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,35 @@
22

33
declare(strict_types=1);
44

5+
use Temporal\Testing\Command;
56
use Temporal\Testing\Environment;
67
use Temporal\Tests\SearchAttributeTestInvoker;
78
use Temporal\Worker\FeatureFlags;
89

9-
chdir(__DIR__ . '/../..');
10+
\chdir(__DIR__ . '/../..');
1011
require_once __DIR__ . '/../../vendor/autoload.php';
1112

1213
$sysInfo = \Temporal\Testing\SystemInfo::detect();
1314

15+
$command = Command::fromEnv();
1416
$environment = Environment::create();
1517
$environment->startTemporalTestServer();
16-
(new SearchAttributeTestInvoker)();
17-
$environment->startRoadRunner(
18-
rrCommand: sprintf('%s serve -c .rr.silent.yaml -w tests/Functional', $sysInfo->rrExecutable),
19-
);
20-
register_shutdown_function(fn() => $environment->stop());
18+
(new SearchAttributeTestInvoker())();
19+
$environment->startRoadRunner(\implode(' ', [
20+
$sysInfo->rrExecutable,
21+
'serve',
22+
'-c', '.rr.silent.yaml',
23+
'-w', 'tests/Functional',
24+
'-o',
25+
'server.command=' . \implode(',', [
26+
PHP_BINARY,
27+
...$command->getPhpBinaryArguments(),
28+
'worker.php',
29+
...$command->getCommandLineArguments(),
30+
]),
31+
]));
32+
33+
\register_shutdown_function(static fn() => $environment->stop());
2134

2235
// Default feature flags
2336
FeatureFlags::$warnOnWorkflowUnfinishedHandlers = false;

0 commit comments

Comments
 (0)