Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Oct 15, 2024
1 parent 91001d9 commit 9db74d5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
16 changes: 9 additions & 7 deletions src/DuskServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function getStash(?string $key = null)
public function start(): void
{
$this->stop();
$this->clearOutput();
$this->startServer();

// We register the below, so if php is exited early, the child
Expand All @@ -136,11 +137,9 @@ public function start(): void
*/
public function stop(): void
{
if (! isset($this->process)) {
return;
if (isset($this->process)) {
$this->process->stop(5);
}

$this->process->stop();
}

/**
Expand Down Expand Up @@ -184,11 +183,10 @@ protected function startServer(): void
$this->process = new Process(
command: $this->prepareCommand(),
cwd: join_paths($this->basePath(), 'public'),
env: array_merge(defined_environment_variables(), array_filter([
env: array_merge(defined_environment_variables(), [
'APP_BASE_PATH' => $this->basePath(),
'APP_URL' => $this->baseUrl(),
'PHP_CLI_SERVER_WORKERS' => Env::get('PHP_CLI_SERVER_WORKERS'),
])),
]),
timeout: $this->timeout
);

Expand All @@ -206,6 +204,10 @@ protected function startServer(): void
*/
protected function guardServerStarting(): void
{
if (Env::has('PHP_CLI_SERVER_WORKERS')) {
return;
}

/** @var resource|null $socket */
$socket = rescue(function () {
$errorNumber = 0;
Expand Down
6 changes: 3 additions & 3 deletions tests/Concerns/InteractsWithServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected function waitForServerToStart()
sleep(1);
$i++;

if ($i >= 5) {
if ($i >= 10) {
throw new Exception('Waited too long for server to start.');
}
}
Expand All @@ -28,15 +28,15 @@ protected function waitForServerToStop()
sleep(1);
$i++;

if ($i >= 5) {
if ($i >= 10) {
throw new Exception('Waited too long for server to stop.');
}
}
}

protected function isServerUp()
{
if ($socket = @fsockopen('127.0.0.1', 8001, $errorNumber, $errorString, $timeout = 1)) {
if ($socket = @fsockopen('127.0.0.1', 8002, $errorNumber, $errorString, $timeout = 1)) {
fclose($socket);

return true;
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Concerns/CanServeSiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function it_starts_and_stops_a_server()
{
$dummy = new CanServeSiteDummy;

$dummy::serve('127.0.0.1', 8001);
$dummy::serve('127.0.0.1', 8002);

$this->assertFalse($dummy->getServer()->getProcess()->isTerminated());

Expand All @@ -38,12 +38,12 @@ public function it_stops_an_existing_server_and_starts_a_new_one_with_consecutiv
{
$dummy = new CanServeSiteDummy;

$dummy::serve('127.0.0.1', 8001);
$dummy::serve('127.0.0.1', 8002);

$duskServerOne = $dummy->getServer();
// we don't bother waiting since that is tested in 'it_starts_and_stops_a_server'

$dummy::serve('127.0.0.1', 8001);
$dummy::serve('127.0.0.1', 8002);

$duskServerTwo = $dummy->getServer();

Expand Down Expand Up @@ -90,7 +90,7 @@ public static function applicationBaseUrl()
*/
public static function getBaseServePort()
{
return 8001;
return 8002;
}

/**
Expand Down

0 comments on commit 9db74d5

Please sign in to comment.