You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the same project as discussed in #30984, I'm using nettest.TestConn to test a custom net.Conn implementation.
Now that I've got the basics covered, I realize it'd be useful to be able to extend the tests to make sure that my CloseRead/CloseWrite methods that are not a mandatory part of net.Conn could also be tested on my type.
I see two options here:
Allow TestConn to perform a couple of type assertion tests to see if methods such as CloseRead and CloseWrite are implemented on the net.Conn type, and then run additional tests if so.
This has the advantage that anyone who consumes this package and passes a net.Conn with these methods will have these tests run. net.TCPConn, net.UnixConn, and my custom vsock.Conn type (as an example) would run these added tests, but net.UDPConn would not.
Perhaps it'd also make a sense to have an optional test for SyscallConn as well, since it is widely implemented.
Export timeoutWrapper and connTester in some form, to enable callers to create their own local tests in a nettest.TestConn-style.
This could be nice to keep the amount of code in this package smaller, but it'd also mean that certain tests such as the CloseRead/CloseWrite would need to be duplicated between different projects.
With this said, I think option 1 is preferable in order to reduce duplication in the community, but I can understand why one wouldn't want to add additional complexity to this package to test methods that are not a required part of net.Conn.
It appears that @mikioh has taken approach 1 with the TestListener API (checking if net.Listener has a SetDeadline method) in https://go-review.googlesource.com/c/net/+/123056, which implies to me that this would be the preferred approach.
mdlayher
changed the title
x/net/nettest: extensibility options for TestConn
x/net/nettest: extend TestConn with optional interface checks
May 10, 2019
EDIT: we'll proceed with Option 1.
For the same project as discussed in #30984, I'm using
nettest.TestConn
to test a customnet.Conn
implementation.Now that I've got the basics covered, I realize it'd be useful to be able to extend the tests to make sure that my
CloseRead
/CloseWrite
methods that are not a mandatory part ofnet.Conn
could also be tested on my type.I see two options here:
TestConn
to perform a couple of type assertion tests to see if methods such asCloseRead
andCloseWrite
are implemented on thenet.Conn
type, and then run additional tests if so.This has the advantage that anyone who consumes this package and passes a
net.Conn
with these methods will have these tests run.net.TCPConn
,net.UnixConn
, and my customvsock.Conn
type (as an example) would run these added tests, butnet.UDPConn
would not.Perhaps it'd also make a sense to have an optional test for
SyscallConn
as well, since it is widely implemented.timeoutWrapper
andconnTester
in some form, to enable callers to create their own local tests in anettest.TestConn
-style.This could be nice to keep the amount of code in this package smaller, but it'd also mean that certain tests such as the
CloseRead
/CloseWrite
would need to be duplicated between different projects.With this said, I think option 1 is preferable in order to reduce duplication in the community, but I can understand why one wouldn't want to add additional complexity to this package to test methods that are not a required part of
net.Conn
./cc @dsnet @mikioh @acln0
The text was updated successfully, but these errors were encountered: