Enable goroutine leak checks for more tests.

This commit is contained in:
Joachim Bauch 2024-04-23 10:53:55 +02:00
parent 9adb762ccf
commit b77525603c
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 156 additions and 148 deletions

View file

@ -47,6 +47,7 @@ func TestFileWatcher_NotExist(t *testing.T) {
}
func TestFileWatcher_File(t *testing.T) {
ensureNoGoroutinesLeak(t, func(t *testing.T) {
tmpdir := t.TempDir()
filename := path.Join(tmpdir, "test.txt")
if err := os.WriteFile(filename, []byte("Hello world!"), 0644); err != nil {
@ -89,6 +90,7 @@ func TestFileWatcher_File(t *testing.T) {
t.Error("should not have received another event")
case <-ctxTimeout.Done():
}
})
}
func TestFileWatcher_Rename(t *testing.T) {

View file

@ -112,6 +112,7 @@ func waitForEvent(ctx context.Context, t *testing.T, ch <-chan struct{}) {
}
func Test_GrpcClients_EtcdInitial(t *testing.T) {
ensureNoGoroutinesLeak(t, func(t *testing.T) {
_, addr1 := NewGrpcServerForTest(t)
_, addr2 := NewGrpcServerForTest(t)
@ -130,6 +131,7 @@ func Test_GrpcClients_EtcdInitial(t *testing.T) {
if clients := client.GetClients(); len(clients) != 2 {
t.Errorf("Expected two clients, got %+v", clients)
}
})
}
func Test_GrpcClients_EtcdUpdate(t *testing.T) {
@ -231,6 +233,7 @@ func Test_GrpcClients_EtcdIgnoreSelf(t *testing.T) {
}
func Test_GrpcClients_DnsDiscovery(t *testing.T) {
ensureNoGoroutinesLeak(t, func(t *testing.T) {
lookup := newMockDnsLookupForTest(t)
target := "testgrpc:12345"
ip1 := net.ParseIP("192.168.0.1")
@ -282,6 +285,7 @@ func Test_GrpcClients_DnsDiscovery(t *testing.T) {
} else if !clients[0].ip.Equal(ip2) {
t.Errorf("Expected IP %s, got %s", ip2, clients[0].ip)
}
})
}
func Test_GrpcClients_DnsDiscoveryInitialFailed(t *testing.T) {
@ -320,6 +324,7 @@ func Test_GrpcClients_DnsDiscoveryInitialFailed(t *testing.T) {
}
func Test_GrpcClients_Encryption(t *testing.T) {
ensureNoGoroutinesLeak(t, func(t *testing.T) {
serverKey, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
t.Fatal(err)
@ -371,4 +376,5 @@ func Test_GrpcClients_Encryption(t *testing.T) {
t.Fatal(err)
}
}
})
}