Skip to content

Commit

Permalink
pkg/distributor: fix test by looking for loopback interface (#2645)
Browse files Browse the repository at this point in the history
TestDistributor_PushIngestionRateLimiter failed if the system had no
interface name in "eth0", "en0" or "lo0".

Fix that by looking at the name of the loopback interface in the list
of the system's network interfaces, then using that name in the test.

Fixes #2356
  • Loading branch information
arl authored Sep 21, 2020
1 parent 85696d0 commit 21addf7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/rand"
"net"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -193,6 +194,23 @@ func TestDistributor_PushIngestionRateLimiter(t *testing.T) {
}
}

// loopbackInterfaceName search for the name of a loopback interface in the list
// of the system's network interfaces.
func loopbackInterfaceName() (string, error) {
is, err := net.Interfaces()
if err != nil {
return "", fmt.Errorf("can't retrieve loopback interface name: %s", err)
}

for _, i := range is {
if i.Flags&net.FlagLoopback != 0 {
return i.Name, nil
}
}

return "", fmt.Errorf("can't retrieve loopback interface name")
}

func prepare(t *testing.T, limits *validation.Limits, kvStore kv.Client) *Distributor {
var (
distributorConfig Config
Expand All @@ -218,10 +236,13 @@ func prepare(t *testing.T, limits *validation.Limits, kvStore kv.Client) *Distri
})
}

loopbackName, err := loopbackInterfaceName()
require.NoError(t, err)

distributorConfig.DistributorRing.HeartbeatPeriod = 100 * time.Millisecond
distributorConfig.DistributorRing.InstanceID = strconv.Itoa(rand.Int())
distributorConfig.DistributorRing.KVStore.Mock = kvStore
distributorConfig.DistributorRing.InstanceInterfaceNames = []string{"eth0", "en0", "lo0"}
distributorConfig.DistributorRing.InstanceInterfaceNames = []string{loopbackName}
distributorConfig.factory = func(addr string) (ring_client.PoolClient, error) {
return ingesters[addr], nil
}
Expand Down

0 comments on commit 21addf7

Please sign in to comment.