Skip to content

Commit

Permalink
[chore][receiver/nsxt] Enable goleak check (open-telemetry#32197)
Browse files Browse the repository at this point in the history
Enable `goleak` checks for the NSX-T receiver to help ensure no
goroutines are being leaked. This is a test only change, some tests were
missing close calls to servers.

**Link to tracking Issue:** open-telemetry#30438
  • Loading branch information
crobert-1 authored and rimitchell committed May 8, 2024
1 parent a6f2378 commit ebe14f2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
30 changes: 30 additions & 0 deletions receiver/nsxtreceiver/client_test.go
Expand Up @@ -36,6 +36,8 @@ func TestNewClientFailureToParse(t *testing.T) {

func TestTransportNodes(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: nsxMock.URL,
Expand All @@ -49,6 +51,8 @@ func TestTransportNodes(t *testing.T) {

func TestClusterNodes(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: nsxMock.URL,
Expand All @@ -62,6 +66,8 @@ func TestClusterNodes(t *testing.T) {

func TestClusterNodeInterface(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: nsxMock.URL,
Expand All @@ -75,6 +81,8 @@ func TestClusterNodeInterface(t *testing.T) {

func TestTransportNodeInterface(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: nsxMock.URL,
Expand All @@ -88,6 +96,8 @@ func TestTransportNodeInterface(t *testing.T) {

func TestTransportNodeStatus(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: nsxMock.URL,
Expand All @@ -101,6 +111,8 @@ func TestTransportNodeStatus(t *testing.T) {

func TestClusterNodeStatus(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: nsxMock.URL,
Expand All @@ -114,6 +126,8 @@ func TestClusterNodeStatus(t *testing.T) {

func TestTransportNodeInterfaceStatus(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: nsxMock.URL,
Expand All @@ -127,6 +141,8 @@ func TestTransportNodeInterfaceStatus(t *testing.T) {

func TestManagerNodeInterfaceStatus(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: nsxMock.URL,
Expand All @@ -140,6 +156,8 @@ func TestManagerNodeInterfaceStatus(t *testing.T) {

func TestDoRequestBadUrl(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: nsxMock.URL,
Expand All @@ -153,6 +171,8 @@ func TestDoRequestBadUrl(t *testing.T) {

func TestPermissionDenied_ClusterNodes(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
Password: badPassword,
ClientConfig: confighttp.ClientConfig{
Expand All @@ -167,6 +187,8 @@ func TestPermissionDenied_ClusterNodes(t *testing.T) {

func TestPermissionDenied_Interfaces(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
Password: badPassword,
ClientConfig: confighttp.ClientConfig{
Expand All @@ -181,6 +203,8 @@ func TestPermissionDenied_Interfaces(t *testing.T) {

func TestPermissionDenied_InterfaceStatus(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
Password: badPassword,
ClientConfig: confighttp.ClientConfig{
Expand All @@ -195,6 +219,8 @@ func TestPermissionDenied_InterfaceStatus(t *testing.T) {

func TestPermissionDenied_NodeStatus(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
Password: badPassword,
ClientConfig: confighttp.ClientConfig{
Expand All @@ -209,6 +235,8 @@ func TestPermissionDenied_NodeStatus(t *testing.T) {

func TestPermissionDenied_TransportNodes(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
Password: badPassword,
ClientConfig: confighttp.ClientConfig{
Expand All @@ -223,6 +251,8 @@ func TestPermissionDenied_TransportNodes(t *testing.T) {

func TestInternalServerError(t *testing.T) {
nsxMock := mockServer(t)
defer nsxMock.Close()

client, err := newClient(&Config{
Username: user500,
ClientConfig: confighttp.ClientConfig{
Expand Down
14 changes: 14 additions & 0 deletions receiver/nsxtreceiver/package_test.go
@@ -0,0 +1,14 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package nsxtreceiver

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
2 changes: 2 additions & 0 deletions receiver/nsxtreceiver/scraper_test.go
Expand Up @@ -103,6 +103,8 @@ func TestScrapeClusterNodeErrors(t *testing.T) {

func TestStartClientAlreadySet(t *testing.T) {
mockClient := mockServer(t)
defer mockClient.Close()

scraper := newScraper(
&Config{
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Expand Down

0 comments on commit ebe14f2

Please sign in to comment.