Skip to content

Commit

Permalink
Merge pull request #132 from ligne/94251bffce8026a60af9801b38b67b3b48…
Browse files Browse the repository at this point in the history
…0e48e8

Fix race condition in IPv6 socket tests and make them less likely to fail when running tests in parallel
  • Loading branch information
leto committed May 23, 2011
2 parents c5d1909 + 94251bf commit c435b74
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions t/pmc/socket_ipv6.t
Expand Up @@ -39,11 +39,15 @@ IPv6-related tests for the Socket PMC.
.sub test_bind
.local pmc sock, addrinfo, addr, it
.local string str
.local int result, count
.local string expected_host, expected_port, expected_str
.local int count, port

sock = new 'Socket'
sock.'socket'(.PIO_PF_INET6, .PIO_SOCK_STREAM, .PIO_PROTO_TCP)
addrinfo = sock.'getaddrinfo'('::1', 1234, .PIO_PROTO_TCP, .PIO_PF_INET6, 1)
port = 1234
push_eh error_6
retry_6:
addrinfo = sock.'getaddrinfo'('::1', port, .PIO_PROTO_TCP, .PIO_PF_INET6, 1)

# output addresses for debugging
it = iter addrinfo
Expand All @@ -66,18 +70,49 @@ IPv6-related tests for the Socket PMC.
if it goto loop

sock.'bind'(addrinfo)

goto started_6

error_6:
inc port
if port < 1244 goto retry_6
pop_eh
.local pmc exception
.get_results(exception)
throw exception

started_6:
pop_eh
str = sock.'local_address'()
is(str, "::1:1234", "local address of bound socket is ::1")
expected_port = port # need to coerce into a string
expected_str = "::1:" . expected_port
is(str, expected_str, "local address of bound socket is ::1")

sock.'close'()

# start again with an IPv4 address
retry_4:
push_eh error_4

sock.'socket'(.PIO_PF_INET, .PIO_SOCK_STREAM, .PIO_PROTO_TCP)
addrinfo = sock.'getaddrinfo'('127.0.0.1', 1234, .PIO_PROTO_TCP, .PIO_PF_INET, 1)
addrinfo = sock.'getaddrinfo'('127.0.0.1', port, .PIO_PROTO_TCP, .PIO_PF_INET, 1)
sock.'bind'(addrinfo)

goto started_4

error_4:
inc port
if port < 1244 goto retry_4
pop_eh
.local pmc exception
.get_results(exception)
throw exception

started_4:
pop_eh
str = sock.'local_address'()
is(str, "127.0.0.1:1234", "local address of bound socket is 127.0.0.1")
expected_port = port # need to coerce into a string
expected_str = "127.0.0.1:" . expected_port
is(str, expected_str, "local address of bound socket is 127.0.0.1")

sock.'close'()
.end

Expand Down

0 comments on commit c435b74

Please sign in to comment.