Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testscript: [net] is misleading, and a bit useless for most developers #75

Open
mvdan opened this issue Jul 22, 2019 · 2 comments
Open

Comments

@mvdan
Copy link
Collaborator

mvdan commented Jul 22, 2019

The godoc reads:

  • [net] for whether the external network can be used

I initially thought - great! It must do some quick check to see if there's a network connection, and if the internet can be reached. I wrote many of my test scripts with lines like [!net] skip 'requires network access'.

Imagine my confusion when I peeked at the implementation:

func HasExternalNetwork() bool {
        return !testing.Short() && runtime.GOOS != "nacl" && runtime.GOOS != "js"
}

This makes sense for the Go project's trybots, but not much else. I think the docs should either discourage the use of [net], or implement one that actually does something useful.

I can think of multiple implementations:

  • Try to dial a static IP, defaulting to a common and fast one like 8.8.8.8. A bit slow, but portable and effective. If someone is concerned about "dialing home", they can change the IP, or not use [net].

  • A best-effort check on a per-platform basis. For example, on Linux one can use ip route to see if there's a default network route. There usually is none if there's no network connection. For example, ip route get 8.8.8.8 can tell you if there's a possible route to a public IP:

$ ip route get 8.8.8.8
8.8.8.8 via 192.168.1.1 dev wlp2s0 src 192.168.1.111 uid 1000
    cache

This best-effort method could always return true on platforms that don't yet implement a decent check.

@mvdan
Copy link
Collaborator Author

mvdan commented Jul 22, 2019

I personally think that this should be a best-effort immediate check. The check should be "is the machine connected to the external network", and not "does the internet work right now". If a laptop is connected to the internet but the internet connection is slow or flaky, the test should fail, not get skipped. Otherwise the user could very easily be misled or confused.

I think [net] should only skip tests on machines that are not connected to the internet on purpose. Like an offline test machine, or a laptop on an airplane, and so on.

@mvdan
Copy link
Collaborator Author

mvdan commented Jul 22, 2019

I forgot to mention - testing.Short should make [net] fail immediately, just like the current implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant