Skip to content

Instantly share code, notes, and snippets.

/ioloop_t.diff Secret

Created December 17, 2014 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/60bc9f5e09b344b1b7ee to your computer and use it in GitHub Desktop.
Save anonymous/60bc9f5e09b344b1b7ee to your computer and use it in GitHub Desktop.
diff --git a/t/mojo/ioloop.t b/t/mojo/ioloop.t
index 58a1f76..df4013d 100644
--- a/t/mojo/ioloop.t
+++ b/t/mojo/ioloop.t
@@ -198,6 +198,36 @@ $id = Mojo::IOLoop->client(
$delay->wait;
is $removed, 1, 'connection has been removed';
+# Interrupted writes
+$buffer = '';
+$delay = Mojo::IOLoop->delay;
+$end = $delay->begin;
+$id = Mojo::IOLoop->server(
+(address => '127.0.0.1') => sub {
+ my ($loop, $stream) = @_;
+ $stream->on(close => $end);
+ $stream->on(read => sub { $buffer .= pop });
+ my $cb;
+ $cb = sub { shift->write('ping' => $cb) };
+ $stream->$cb;
+}
+);
+$port = Mojo::IOLoop->acceptor($id)->port;
+$end2 = $delay->begin;
+$id = Mojo::IOLoop->client(
+(port => $port) => sub {
+ my ($loop, $err, $stream) = @_;
+ $stream->once(
+ read => sub {
+ shift->write('pong' => sub { shift->close });
+ }
+ );
+ $stream->on(close => $end2);
+}
+);
+$delay->wait;
+is $buffer, 'pong', 'right result';
+
# Stream throttling
my ($client, $server, $client_after, $server_before, $server_after);
$id = Mojo::IOLoop->server(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment