mirror of
https://github.com/golang/go
synced 2024-11-18 15:24:41 -07:00
net: simplify sync.Once calls in tests
Change-Id: I0c2e1a4a8261887a696e585dda46e72d691191e0 Reviewed-on: https://go-review.googlesource.com/10070 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
e5febf957f
commit
ef54930ebb
@ -227,7 +227,7 @@ func TestReloadResolvConfChange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkGoLookupIP(b *testing.B) {
|
func BenchmarkGoLookupIP(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
goLookupIP("www.example.com")
|
goLookupIP("www.example.com")
|
||||||
@ -235,7 +235,7 @@ func BenchmarkGoLookupIP(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkGoLookupIPNoSuchHost(b *testing.B) {
|
func BenchmarkGoLookupIPNoSuchHost(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
goLookupIP("some.nonexistent")
|
goLookupIP("some.nonexistent")
|
||||||
@ -243,7 +243,7 @@ func BenchmarkGoLookupIPNoSuchHost(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkGoLookupIPWithBrokenNameServer(b *testing.B) {
|
func BenchmarkGoLookupIPWithBrokenNameServer(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
onceLoadConfig.Do(loadDefaultConfig)
|
onceLoadConfig.Do(loadDefaultConfig)
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ func TestDNSName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkDNSName(b *testing.B) {
|
func BenchmarkDNSName(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
benchmarks := append(dnsNameTests, []dnsNameTest{
|
benchmarks := append(dnsNameTests, []dnsNameTest{
|
||||||
{strings.Repeat("a", 63), true},
|
{strings.Repeat("a", 63), true},
|
||||||
|
@ -229,7 +229,7 @@ func testMulticastAddrs(t *testing.T, ifmat []Addr) (nmaf4, nmaf6 int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInterfaces(b *testing.B) {
|
func BenchmarkInterfaces(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if _, err := Interfaces(); err != nil {
|
if _, err := Interfaces(); err != nil {
|
||||||
@ -239,7 +239,7 @@ func BenchmarkInterfaces(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInterfaceByIndex(b *testing.B) {
|
func BenchmarkInterfaceByIndex(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
ifi := loopbackInterface()
|
ifi := loopbackInterface()
|
||||||
if ifi == nil {
|
if ifi == nil {
|
||||||
@ -253,7 +253,7 @@ func BenchmarkInterfaceByIndex(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInterfaceByName(b *testing.B) {
|
func BenchmarkInterfaceByName(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
ifi := loopbackInterface()
|
ifi := loopbackInterface()
|
||||||
if ifi == nil {
|
if ifi == nil {
|
||||||
@ -267,7 +267,7 @@ func BenchmarkInterfaceByName(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInterfaceAddrs(b *testing.B) {
|
func BenchmarkInterfaceAddrs(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if _, err := InterfaceAddrs(); err != nil {
|
if _, err := InterfaceAddrs(); err != nil {
|
||||||
@ -277,7 +277,7 @@ func BenchmarkInterfaceAddrs(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInterfacesAndAddrs(b *testing.B) {
|
func BenchmarkInterfacesAndAddrs(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
ifi := loopbackInterface()
|
ifi := loopbackInterface()
|
||||||
if ifi == nil {
|
if ifi == nil {
|
||||||
@ -291,7 +291,7 @@ func BenchmarkInterfacesAndAddrs(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInterfacesAndMulticastAddrs(b *testing.B) {
|
func BenchmarkInterfacesAndMulticastAddrs(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
ifi := loopbackInterface()
|
ifi := loopbackInterface()
|
||||||
if ifi == nil {
|
if ifi == nil {
|
||||||
|
@ -53,7 +53,7 @@ func TestParseIP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkParseIP(b *testing.B) {
|
func BenchmarkParseIP(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
for _, tt := range parseIPTests {
|
for _, tt := range parseIPTests {
|
||||||
@ -110,7 +110,7 @@ func TestIPString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkIPString(b *testing.B) {
|
func BenchmarkIPString(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
for _, tt := range ipStringTests {
|
for _, tt := range ipStringTests {
|
||||||
@ -162,7 +162,7 @@ func TestIPMaskString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkIPMaskString(b *testing.B) {
|
func BenchmarkIPMaskString(b *testing.B) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
for _, tt := range ipMaskStringTests {
|
for _, tt := range ipMaskStringTests {
|
||||||
|
@ -43,7 +43,7 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
st := m.Run()
|
st := m.Run()
|
||||||
|
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
if !testing.Short() {
|
if !testing.Short() {
|
||||||
printLeakedGoroutines()
|
printLeakedGoroutines()
|
||||||
printLeakedSockets()
|
printLeakedSockets()
|
||||||
|
@ -58,7 +58,7 @@ func BenchmarkTCP6PersistentTimeout(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkTCP(b *testing.B, persistent, timeout bool, laddr string) {
|
func benchmarkTCP(b *testing.B, persistent, timeout bool, laddr string) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
const msgLen = 512
|
const msgLen = 512
|
||||||
conns := b.N
|
conns := b.N
|
||||||
@ -168,7 +168,7 @@ func BenchmarkTCP6ConcurrentReadWrite(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkTCPConcurrentReadWrite(b *testing.B, laddr string) {
|
func benchmarkTCPConcurrentReadWrite(b *testing.B, laddr string) {
|
||||||
testHookUninstaller.Do(func() { uninstallTestHooks() })
|
testHookUninstaller.Do(uninstallTestHooks)
|
||||||
|
|
||||||
// The benchmark creates GOMAXPROCS client/server pairs.
|
// The benchmark creates GOMAXPROCS client/server pairs.
|
||||||
// Each pair creates 4 goroutines: client reader/writer and server reader/writer.
|
// Each pair creates 4 goroutines: client reader/writer and server reader/writer.
|
||||||
|
Loading…
Reference in New Issue
Block a user