Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions tests/Unit/Server/Session/FileSessionStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,12 @@ public function testConcurrentWritesNeverPublishAPartialPayload(): void
// The writers finish in whatever order they like.
ksort($exitCodes);

$this->assertSame([0, 0, 0], $exitCodes, 'The concurrent writers did not all run to completion.');
$errors = '';
foreach (array_keys($writers) as $i) {
$errors .= file_get_contents($this->directory.\DIRECTORY_SEPARATOR.'writer-'.$i.'.err');
}

$this->assertSame([0, 0, 0], $exitCodes, 'The concurrent writers did not all run to completion: '.$errors);

foreach (array_keys($writers) as $i) {
$this->assertSame('', file_get_contents($this->directory.\DIRECTORY_SEPARATOR.'writer-'.$i.'.err'));
Expand All @@ -406,12 +411,20 @@ private function spawnWriter(UuidV4 $id, int $index)

require $argv[1];

$store = new Mcp\Server\Session\FileSessionStore($argv[2]);
// The store logs why a write failed, which ends up in this writer's error file.
$logger = new class extends Psr\Log\AbstractLogger {
public function log($level, $message, array $context = []): void
{
fwrite(\STDERR, $level.': '.$message.' '.json_encode($context).\PHP_EOL);
}
};
$store = new Mcp\Server\Session\FileSessionStore($argv[2], logger: $logger);
$id = Symfony\Component\Uid\Uuid::fromString($argv[3]);
$payload = json_encode(['queue' => array_fill(0, 200, str_repeat('x', 200))]);

for ($i = 0; $i < 200; ++$i) {
if (!$store->write($id, $payload)) {
fwrite(\STDERR, sprintf('Write %d of 200 failed.', $i + 1).\PHP_EOL);
exit(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public function testReadingTheStreamWritesTheFrames(): void
$elapsed = microtime(true) - $start;

$this->assertSame(['data: {"method":"first"}'."\n\n", ': keep-alive'."\n\n", 'data: {"id":1}'."\n\n"], $flushed, 'Each frame is flushed on its own.');
$this->assertGreaterThanOrEqual(0.25, $elapsed, 'The idle turn waits before the next poll.');
// The turn sleeps 250 ms, which Windows can end slightly early.
$this->assertGreaterThanOrEqual(0.2, $elapsed, 'The idle turn waits before the next poll.');
$this->assertLessThan(1.0, $elapsed, 'The idle turn waits once.');
}

Expand Down
Loading