pkg/distributor: fix test by looking for loopback interface (#2645)

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
pull/2655/head
Aurélien Rainone 5 years ago committed by GitHub
parent 85696d00eb
commit 21addf7935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      pkg/distributor/distributor_test.go

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/rand"
"net"
"net/http"
"strconv"
"strings"
@ -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
@ -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
}

Loading…
Cancel
Save