Skip to content

Commit

Permalink
suppression méthode uniquement utilisée dans les tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Jul 25, 2024
1 parent 5a00a08 commit 4b21321
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
21 changes: 0 additions & 21 deletions src/Server/Process/Started.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
Either,
SideEffect,
Set,
Predicate\Instance,
};

/**
Expand Down Expand Up @@ -119,26 +118,6 @@ public function pid(): Pid
return $this->pid;
}

/**
* @return Either<ExitCode|'signaled'|'timed-out', SideEffect>
*/
public function wait(): Either
{
// we don't need to keep the output read while writing to the input
// stream as this data will never be exposed to caller, so by discarding
// this data we prevent ourself from reaching a possible "out of memory"
// error
/** @var Either<ExitCode|'signaled'|'timed-out', SideEffect> */
return $this
->output()
->last()
->keep(Instance::of(Either::class))
->match(
static fn($return) => $return,
static fn() => throw new RuntimeException('Unable to retrieve process result'),
);
}

/**
* @return Sequence<Chunk|Either<ExitCode|'signaled'|'timed-out', SideEffect>>
*/
Expand Down
52 changes: 36 additions & 16 deletions tests/Server/Process/UnixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,15 @@ public function testTimeoutWaitSlowProcess()
$started = \microtime(true);

$this->assertGreaterThanOrEqual(2, $process->pid()->toInt());
$e = $process->wait()->match(
static fn() => null,
static fn($e) => $e,
);
$e = $process
->output()
->last()
->either()
->flatMap(static fn($result) => $result)
->match(
static fn() => null,
static fn($e) => $e,
);
$this->assertSame('timed-out', $e);
// 3 because of the grace period
$this->assertEqualsWithDelta(3, \microtime(true) - $started, 0.5);
Expand All @@ -186,10 +191,15 @@ public function testWaitSuccess()
Command::foreground('echo')->withArgument('hello'),
);

$value = $cat()->wait()->match(
static fn($value) => $value,
static fn() => null,
);
$value = $cat()
->output()
->last()
->either()
->flatMap(static fn($result) => $result)
->match(
static fn($value) => $value,
static fn() => null,
);

$this->assertInstanceOf(SideEffect::class, $value);
}
Expand All @@ -206,10 +216,15 @@ public function testWaitFail()
->withEnvironment('PATH', $_SERVER['PATH']),
);

$value = $cat()->wait()->match(
static fn() => null,
static fn($e) => $e,
);
$value = $cat()
->output()
->last()
->either()
->flatMap(static fn($result) => $result)
->match(
static fn() => null,
static fn($e) => $e,
);

$this->assertInstanceOf(ExitCode::class, $value);
$this->assertSame(1, $value->toInt());
Expand Down Expand Up @@ -257,10 +272,15 @@ public function testOverwrite()
->overwrite(Path::of('test.log')),
);

$value = $cat()->wait()->match(
static fn($value) => $value,
static fn() => null,
);
$value = $cat()
->output()
->last()
->either()
->flatMap(static fn($result) => $result)
->match(
static fn($value) => $value,
static fn() => null,
);

$this->assertInstanceOf(SideEffect::class, $value);
$this->assertSame(
Expand Down

0 comments on commit 4b21321

Please sign in to comment.