Merge pull request #175 from weaveworks/rename-resolver

Rename Resolver to staticResolver
This commit is contained in:
Tom Wilkie
2015-06-04 11:41:38 +01:00
3 changed files with 12 additions and 13 deletions

View File

@@ -67,7 +67,7 @@ func main() {
c := xfer.NewCollector(*batch)
defer c.Stop()
r := NewResolver(probes, c.Add)
r := newStaticResolver(probes, c.Add)
defer r.Stop()
lifo := NewReportLIFO(c, *window)

View File

@@ -15,9 +15,7 @@ var (
lookupIP = net.LookupIP
)
// Resolver periodically tries to resolve the IP addresses for a given
// set of hostnames.
type Resolver struct {
type staticResolver struct {
quit chan struct{}
add func(string)
peers []peer
@@ -33,8 +31,8 @@ type peer struct {
// resolved IPs. It explictiy supports hostnames which
// resolve to multiple IPs; it will repeatedly call
// add with the same IP, expecting the target to dedupe.
func NewResolver(peers []string, add func(string)) Resolver {
r := Resolver{
func newStaticResolver(peers []string, add func(string)) staticResolver {
r := staticResolver{
quit: make(chan struct{}),
add: add,
peers: prepareNames(peers),
@@ -67,20 +65,21 @@ func prepareNames(strs []string) []peer {
return results
}
func (r Resolver) loop() {
func (r staticResolver) loop() {
r.resolveHosts()
t := tick(time.Minute)
for {
select {
case <-t:
r.resolveHosts()
case <-r.quit:
return
}
}
}
func (r Resolver) resolveHosts() {
func (r staticResolver) resolveHosts() {
for _, peer := range r.peers {
var addrs []net.IP
if addr := net.ParseIP(peer.hostname); addr != nil {
@@ -103,7 +102,6 @@ func (r Resolver) resolveHosts() {
}
}
// Stop this Resolver.
func (r Resolver) Stop() {
func (r staticResolver) Stop() {
close(r.quit)
}

View File

@@ -32,17 +32,18 @@ func TestResolver(t *testing.T) {
ip2 := "192.168.0.10"
adds := make(chan string)
add := func(s string) { adds <- s }
r := NewResolver([]string{"symbolic.name" + port, "namewithnoport", ip1 + port, ip2}, add)
r := newStaticResolver([]string{"symbolic.name" + port, "namewithnoport", ip1 + port, ip2}, add)
assertAdd := func(want string) {
_, _, line, _ := runtime.Caller(1)
select {
case have := <-adds:
if want != have {
_, _, line, _ := runtime.Caller(1)
t.Errorf("line %d: want %q, have %q", line, want, have)
}
case <-time.After(time.Millisecond):
t.Fatal("didn't get add in time")
t.Fatalf("line %d: didn't get add in time", line)
}
}