Skip to content

Commit

Permalink
feat: remove test on stream connection closed as handling differs bet…
Browse files Browse the repository at this point in the history
…ween implementation
  • Loading branch information
valentin-claras committed Sep 2, 2021
1 parent 516c0e5 commit db42b73
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 66 deletions.
2 changes: 2 additions & 0 deletions src/EventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ public function deferred(): Deferred;

/**
* Returns a promise that will be resolved with the input stream when it becomes readable.
* ⚠️ Error handling (stream connection closed for example) might differ between implementations.
*
* @param resource $stream
*/
public function readable($stream): Promise;

/**
* Returns a promise that will be resolved with the input stream when it becomes writable.
* ⚠️ Error handling (stream connection closed for example) might differ between implementations.
*
* @param resource $stream
*/
Expand Down
16 changes: 0 additions & 16 deletions tests/Adapter/Amp/EventLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,4 @@ public function testStreamShouldReadFromWritable(string $expectedSequence = ''):
// Because Amp resolve promises in a slightly different order.
parent::testStreamShouldReadFromWritable('W0R0W12345R12R34W6R56R');
}

public function testStreamShouldNotBeWritableIfClosed(): void
{
assert_options(ASSERT_EXCEPTION, 1);
$this->expectException(\Throwable::class);

parent::testStreamShouldNotBeWritableIfClosed();
}

public function testStreamShouldNotBeReadableIfClosed(): void
{
assert_options(ASSERT_EXCEPTION, 1);
$this->expectException(\Throwable::class);

parent::testStreamShouldNotBeReadableIfClosed();
}
}
50 changes: 0 additions & 50 deletions tests/EventLoopTest/StreamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,54 +80,4 @@ public function testStreamShouldBeWritableIfOpened(): void
$stream = $eventLoop->wait($eventLoop->writable($streamIn));
$this->assertSame($streamIn, $stream);
}

public function testStreamShouldNotBeWritableIfClosed(): void
{
$eventLoop = $this->createEventLoop();
[$streamIn, $streamOut] = $this->createStreamPair();

$waitSomeTicks = function () use ($eventLoop) {
yield $eventLoop->idle();
yield $eventLoop->idle();
yield $eventLoop->idle();

return 'Aborted';
};

// If stream is closed, the promise will never be resolved
fclose($streamIn);
$result = $eventLoop->wait(
$eventLoop->promiseRace(
$eventLoop->async($waitSomeTicks()),
$eventLoop->writable($streamIn)
)
);

$this->assertSame('Aborted', $result);
}

public function testStreamShouldNotBeReadableIfClosed(): void
{
$eventLoop = $this->createEventLoop();
[$streamIn, $streamOut] = $this->createStreamPair();

$waitSomeTicks = function () use ($eventLoop) {
yield $eventLoop->idle();
yield $eventLoop->idle();
yield $eventLoop->idle();

return 'Aborted';
};

// If stream is closed, the promise will never be resolved
fclose($streamOut);
$result = $eventLoop->wait(
$eventLoop->promiseRace(
$eventLoop->async($waitSomeTicks()),
$eventLoop->readable($streamOut)
)
);

$this->assertSame('Aborted', $result);
}
}

0 comments on commit db42b73

Please sign in to comment.