From 5939837469b7b828861fadf92091f7e066333021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Thu, 8 Aug 2024 14:23:52 +0200 Subject: [PATCH] Add spec for `Socket#finalize` flushes --- spec/std/socket/socket_spec.cr | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/std/socket/socket_spec.cr b/spec/std/socket/socket_spec.cr index d4e7051d12bd..b36cf1753182 100644 --- a/spec/std/socket/socket_spec.cr +++ b/spec/std/socket/socket_spec.cr @@ -169,4 +169,28 @@ describe Socket, tags: "network" do socket.close_on_exec?.should be_true end {% end %} + + describe "#finalize" do + it "flushes" do + port = unused_local_port + server = Socket.tcp(Socket::Family::INET) + server.bind("127.0.0.1", port) + server.listen + + spawn do + client = server.not_nil!.accept + client << "foo" + client.flush + client << "bar" + client.finalize + end + + socket = Socket.tcp(Socket::Family::INET) + socket.connect(Socket::IPAddress.new("127.0.0.1", port)) + socket.gets.should eq "foobar" + ensure + socket.try &.close + server.try &.close + end + end end