Skip to content

Commit ef54930

Browse files
committed
net: simplify sync.Once calls in tests
Change-Id: I0c2e1a4a8261887a696e585dda46e72d691191e0 Reviewed-on: https://go-review.googlesource.com/10070 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent e5febf9 commit ef54930

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

src/net/dnsclient_unix_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -227,23 +227,23 @@ func TestReloadResolvConfChange(t *testing.T) {
227227
}
228228

229229
func BenchmarkGoLookupIP(b *testing.B) {
230-
testHookUninstaller.Do(func() { uninstallTestHooks() })
230+
testHookUninstaller.Do(uninstallTestHooks)
231231

232232
for i := 0; i < b.N; i++ {
233233
goLookupIP("www.example.com")
234234
}
235235
}
236236

237237
func BenchmarkGoLookupIPNoSuchHost(b *testing.B) {
238-
testHookUninstaller.Do(func() { uninstallTestHooks() })
238+
testHookUninstaller.Do(uninstallTestHooks)
239239

240240
for i := 0; i < b.N; i++ {
241241
goLookupIP("some.nonexistent")
242242
}
243243
}
244244

245245
func BenchmarkGoLookupIPWithBrokenNameServer(b *testing.B) {
246-
testHookUninstaller.Do(func() { uninstallTestHooks() })
246+
testHookUninstaller.Do(uninstallTestHooks)
247247

248248
onceLoadConfig.Do(loadDefaultConfig)
249249

src/net/dnsname_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestDNSName(t *testing.T) {
6868
}
6969

7070
func BenchmarkDNSName(b *testing.B) {
71-
testHookUninstaller.Do(func() { uninstallTestHooks() })
71+
testHookUninstaller.Do(uninstallTestHooks)
7272

7373
benchmarks := append(dnsNameTests, []dnsNameTest{
7474
{strings.Repeat("a", 63), true},

src/net/interface_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func testMulticastAddrs(t *testing.T, ifmat []Addr) (nmaf4, nmaf6 int) {
229229
}
230230

231231
func BenchmarkInterfaces(b *testing.B) {
232-
testHookUninstaller.Do(func() { uninstallTestHooks() })
232+
testHookUninstaller.Do(uninstallTestHooks)
233233

234234
for i := 0; i < b.N; i++ {
235235
if _, err := Interfaces(); err != nil {
@@ -239,7 +239,7 @@ func BenchmarkInterfaces(b *testing.B) {
239239
}
240240

241241
func BenchmarkInterfaceByIndex(b *testing.B) {
242-
testHookUninstaller.Do(func() { uninstallTestHooks() })
242+
testHookUninstaller.Do(uninstallTestHooks)
243243

244244
ifi := loopbackInterface()
245245
if ifi == nil {
@@ -253,7 +253,7 @@ func BenchmarkInterfaceByIndex(b *testing.B) {
253253
}
254254

255255
func BenchmarkInterfaceByName(b *testing.B) {
256-
testHookUninstaller.Do(func() { uninstallTestHooks() })
256+
testHookUninstaller.Do(uninstallTestHooks)
257257

258258
ifi := loopbackInterface()
259259
if ifi == nil {
@@ -267,7 +267,7 @@ func BenchmarkInterfaceByName(b *testing.B) {
267267
}
268268

269269
func BenchmarkInterfaceAddrs(b *testing.B) {
270-
testHookUninstaller.Do(func() { uninstallTestHooks() })
270+
testHookUninstaller.Do(uninstallTestHooks)
271271

272272
for i := 0; i < b.N; i++ {
273273
if _, err := InterfaceAddrs(); err != nil {
@@ -277,7 +277,7 @@ func BenchmarkInterfaceAddrs(b *testing.B) {
277277
}
278278

279279
func BenchmarkInterfacesAndAddrs(b *testing.B) {
280-
testHookUninstaller.Do(func() { uninstallTestHooks() })
280+
testHookUninstaller.Do(uninstallTestHooks)
281281

282282
ifi := loopbackInterface()
283283
if ifi == nil {
@@ -291,7 +291,7 @@ func BenchmarkInterfacesAndAddrs(b *testing.B) {
291291
}
292292

293293
func BenchmarkInterfacesAndMulticastAddrs(b *testing.B) {
294-
testHookUninstaller.Do(func() { uninstallTestHooks() })
294+
testHookUninstaller.Do(uninstallTestHooks)
295295

296296
ifi := loopbackInterface()
297297
if ifi == nil {

src/net/ip_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestParseIP(t *testing.T) {
5353
}
5454

5555
func BenchmarkParseIP(b *testing.B) {
56-
testHookUninstaller.Do(func() { uninstallTestHooks() })
56+
testHookUninstaller.Do(uninstallTestHooks)
5757

5858
for i := 0; i < b.N; i++ {
5959
for _, tt := range parseIPTests {
@@ -110,7 +110,7 @@ func TestIPString(t *testing.T) {
110110
}
111111

112112
func BenchmarkIPString(b *testing.B) {
113-
testHookUninstaller.Do(func() { uninstallTestHooks() })
113+
testHookUninstaller.Do(uninstallTestHooks)
114114

115115
for i := 0; i < b.N; i++ {
116116
for _, tt := range ipStringTests {
@@ -162,7 +162,7 @@ func TestIPMaskString(t *testing.T) {
162162
}
163163

164164
func BenchmarkIPMaskString(b *testing.B) {
165-
testHookUninstaller.Do(func() { uninstallTestHooks() })
165+
testHookUninstaller.Do(uninstallTestHooks)
166166

167167
for i := 0; i < b.N; i++ {
168168
for _, tt := range ipMaskStringTests {

src/net/main_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestMain(m *testing.M) {
4343

4444
st := m.Run()
4545

46-
testHookUninstaller.Do(func() { uninstallTestHooks() })
46+
testHookUninstaller.Do(uninstallTestHooks)
4747
if !testing.Short() {
4848
printLeakedGoroutines()
4949
printLeakedSockets()

src/net/tcp_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func BenchmarkTCP6PersistentTimeout(b *testing.B) {
5858
}
5959

6060
func benchmarkTCP(b *testing.B, persistent, timeout bool, laddr string) {
61-
testHookUninstaller.Do(func() { uninstallTestHooks() })
61+
testHookUninstaller.Do(uninstallTestHooks)
6262

6363
const msgLen = 512
6464
conns := b.N
@@ -168,7 +168,7 @@ func BenchmarkTCP6ConcurrentReadWrite(b *testing.B) {
168168
}
169169

170170
func benchmarkTCPConcurrentReadWrite(b *testing.B, laddr string) {
171-
testHookUninstaller.Do(func() { uninstallTestHooks() })
171+
testHookUninstaller.Do(uninstallTestHooks)
172172

173173
// The benchmark creates GOMAXPROCS client/server pairs.
174174
// Each pair creates 4 goroutines: client reader/writer and server reader/writer.

0 commit comments

Comments
 (0)