Skip to content

Commit

Permalink
Fix: SocketSpecHelper.supports_ipv6?
Browse files Browse the repository at this point in the history
The initializer block is now captured, and we can't return from a
captured block. This outlines that the previous commit is a BREAKING
CHANGE!

The `class_getter?` version used skip over the intent to cache the
result in `@@supports_ipv6` (it returned from the generated function,
not from the block), so whenever IPv6 was supported every test was
creating yet-another TCPServer (oops).
  • Loading branch information
ysbaddaden committed Jan 13, 2025
1 parent 608df71 commit 808f104
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions spec/std/socket/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ require "spec"
require "socket"

module SocketSpecHelper
class_getter?(supports_ipv6 : Bool) do
TCPServer.open("::1", 0) { return true }
false
rescue Socket::Error
false
@@supports_ipv6 : Bool?

def self.supports_ipv6? : Bool
unless (value = @@supports_ipv6).nil?
return value
end
begin
TCPServer.open("::1", 0) { return @@supports_ipv6 = true }
@@supports_ipv6 = false
rescue Socket::Error
@@supports_ipv6 = false
end
end
end

Expand Down

0 comments on commit 808f104

Please sign in to comment.