Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The docs example test is left waiting indefinitely #23

Open
programarivm opened this issue Oct 6, 2023 · 3 comments
Open

The docs example test is left waiting indefinitely #23

programarivm opened this issue Oct 6, 2023 · 3 comments
Labels

Comments

@programarivm
Copy link

👋 Hi there,

At ChesslaBlab we're writing functional tests for the PHP Chess Server.

See:

At this moment I'm trying to run the docs example as it is shown in the two images below.

tab_01
Figure 1. php cli/testing.php

tab_02
Figure 2. vendor/bin/phpunit tests/functional/

However, the test is left waiting indefinitely.

<?php

namespace ChessServer\Tests\Functional;

use Amp\ByteStream;
use Amp\PHPUnit\AsyncTestCase;
use Amp\Socket;

class StartCommandTest extends AsyncTestCase
{
    public function test(): void
    {
        $socket = Socket\connect('tcp://127.0.0.1:8080');
        
        $socket->write('/start classical fen');

        $expected = '{"\/start":{"variant":"classical","mode":"fen","fen":"rnbqkbnr\/pppppppp\/8\/8\/8\/8\/PPPPPPPP\/RNBQKBNR w KQkq -"}}';

        $this->assertSame($expected, ByteStream\buffer($socket));
    }
}

Also this is the cli/testing.php script running the TCP socket server on port 8080 shown in Figure 1.

<?php

namespace ChessServer\Cli;

use ChessServer\Socket\TcpSocket;
use Dotenv\Dotenv;

require __DIR__ . '/../vendor/autoload.php';

$dotenv = Dotenv::createImmutable(__DIR__.'/../');
$dotenv->load();

$server = new TcpSocket($_ENV['TCP_PORT']);

Any help would be greatly appreciated.

Thank you,

@kelunik
Copy link
Member

kelunik commented Oct 8, 2023

Hi @programarivm, you're buffering the socket contents until the socket closes, but the socket is likely not closed in that test, so the test hangs.

@trowski
Copy link
Member

trowski commented Oct 8, 2023

Hi @programarivm!

Amp\ByteStream\buffer() waits until the stream has closed to return the buffered content. Are you expecting $socket to have closed after the response is received? If not, rather than buffer() you'll want to consider reading in loop until the expected payload is received, using Amp\ByteStream\BufferedReader, or if the JSON is line-delimited, you may be able to use Amp\ByteStream\parseLineDelimitedJson().

If the above isn't the issue, I can pull the repos and investigate further.

@programarivm
Copy link
Author

Thank you @kelunik and @trowski for the help.

Not too sure about this one yet. No worries, I suppose for the time being the Selenium automated tests will be kind of equivalent to the so-called functional tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants