Skip to content

Commit

Permalink
receiver/zookeeper: Attempt to make test stable (open-telemetry#3274)
Browse files Browse the repository at this point in the history
Attempt to make test stable by waiting till the listener is setup.

**Link to tracking Issue:** open-telemetry#3034
  • Loading branch information
asuresh4 committed Apr 30, 2021
1 parent 566b60d commit 9fbbda4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions receiver/zookeeperreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func TestZookeeperMetricsScraperScrape(t *testing.T) {
metricsV3414 = append(metricsV3414, commonMetrics...)
metricsV3414 = append(metricsV3414, metadata.Metrics.ZookeeperFsyncThresholdExceeds.New())

localAddr := testutil.GetAvailableLocalAddress(t)
tests := []struct {
name string
expectedMetrics []pdata.Metric
Expand Down Expand Up @@ -192,10 +191,12 @@ func TestZookeeperMetricsScraperScrape(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
localAddr := testutil.GetAvailableLocalAddress(t)
if !tt.mockZKConnectionErr {
go mockZKServer(t, localAddr, tt.mockedZKOutputSourceFilename)
ms := mockedServer{ready: make(chan bool, 1)}
go ms.mockZKServer(t, localAddr, tt.mockedZKOutputSourceFilename)
<-ms.ready
}
time.Sleep(100 * time.Millisecond)

cfg := &Config{
TCPAddr: confignet.TCPAddr{
Expand Down Expand Up @@ -281,11 +282,17 @@ func assertDescriptorEqual(t *testing.T, expected pdata.Metric, actual pdata.Met
require.Equal(t, expected.DataType(), actual.DataType())
}

func mockZKServer(t *testing.T, endpoint string, filename string) {
type mockedServer struct {
ready chan bool
}

func (ms *mockedServer) mockZKServer(t *testing.T, endpoint string, filename string) {
listener, err := net.Listen("tcp", endpoint)
require.NoError(t, err)
defer listener.Close()

ms.ready <- true

conn, err := listener.Accept()
require.NoError(t, err)

Expand Down

0 comments on commit 9fbbda4

Please sign in to comment.