Skip to content

Commit

Permalink
vlib: fix tcp_test.v
Browse files Browse the repository at this point in the history
The listen_tcp method should not accept .unix af.
Test that it indeed fails when invoked.
  • Loading branch information
hholst80 committed Jan 4, 2024
1 parent 7d29afe commit de5f494
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions vlib/net/tcp_test.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// vtest flaky: true
// vtest retry: 8
import net
import os

const test_port = 45123

Expand All @@ -25,14 +22,11 @@ fn one_shot_echo_server(mut l net.TcpListener, ch_started chan int) ! {
mut new_conn := l.accept() or { return error('could not accept') }
eprintln(' > new_conn: ${new_conn}')
handle_conn(mut new_conn)
new_conn.close() or {}
new_conn.close() or { panic(err) }
}

fn echo(address string) ! {
mut c := net.dial_tcp(address)!
defer {
c.close() or {}
}

println('local: ' + c.addr()!.str())
println(' peer: ' + c.peer_addr()!.str())
Expand All @@ -46,6 +40,7 @@ fn echo(address string) ! {
assert buf[i] == data[i]
}
println('Got "${buf.bytestr()}"')
c.close()!
}

fn test_tcp_ip6() {
Expand All @@ -55,7 +50,7 @@ fn test_tcp_ip6() {
dump(l)
start_echo_server(mut l)
echo(address) or { panic(err) }
l.close() or {}
l.close() or { panic(err) }
// ensure there is at least one new socket created before the next test
l = net.listen_tcp(.ip6, ':${test_port + 1}') or { panic(err) }
}
Expand All @@ -73,26 +68,16 @@ fn test_tcp_ip() {
dump(l)
start_echo_server(mut l)
echo(address) or { panic(err) }
l.close() or {}
l.close() or { panic(err) }
}

fn test_tcp_unix() {
eprintln('\n>>> ${@FN}')
// TODO(emily):
// whilst windows supposedly supports unix sockets
// this doesnt work (wsaeopnotsupp at the call to bind())
$if !windows {
address := os.real_path('tcp-test.sock')
// address := 'tcp-test.sock'
println('${address}')

mut l := net.listen_tcp(.unix, address) or { panic(err) }
start_echo_server(mut l)
echo(address) or { panic(err) }
l.close() or {}
address := 'tcp-test.sock'
eprintln('${address}')

os.rm(address) or { panic('failed to remove socket file') }
}
mut l := net.listen_tcp(.unix, address) or { return }
assert false
}

fn testsuite_end() {
Expand All @@ -103,6 +88,6 @@ fn test_bind() {
$if !network ? {
return
}
mut conn := net.dial_tcp_with_bind('vlang.io:80', '127.0.0.1:0')!
conn.close()!
mut conn := net.dial_tcp_with_bind('vlang.io:80', '127.0.0.1:0') or { panic(err) }
conn.close() or { panic(err) }
}

0 comments on commit de5f494

Please sign in to comment.