From f91404ecfc79b5c7d1689cfd1fcad73ea710d4c1 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 3 Jul 2011 16:13:44 -0700 Subject: [PATCH] Update gomemcache in third_party. Change-Id: Ide78f9528c1327fd91a681595429eb0ebdffacf0 --- .../bradfitz/gomemcache/memcache_test.go | 33 +++++++++++++++++-- .../bradfitz/gomemcache/selector.go | 17 +++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/lib/go/camli/third_party/github.com/bradfitz/gomemcache/memcache_test.go b/lib/go/camli/third_party/github.com/bradfitz/gomemcache/memcache_test.go index 668059f02..512cf7b67 100644 --- a/lib/go/camli/third_party/github.com/bradfitz/gomemcache/memcache_test.go +++ b/lib/go/camli/third_party/github.com/bradfitz/gomemcache/memcache_test.go @@ -18,10 +18,13 @@ limitations under the License. package memcache import ( + "exec" + "fmt" "net" "os" "strings" "testing" + "time" ) const testServer = "localhost:11211" @@ -37,18 +40,42 @@ func setup(t *testing.T) bool { return true } -func TestMemcache(t *testing.T) { +func TestLocalhost(t *testing.T) { if !setup(t) { return } + testWithClient(t, New(testServer)) +} + +// Run the memcached binary as a child process and connect to its unix socket. +func TestUnixSocket(t *testing.T) { + sock := fmt.Sprintf("/tmp/test-gomemcache-%d.sock", os.Getpid()) + cmd := exec.Command("memcached", "-s", sock) + if err := cmd.Start(); err != nil { + t.Logf("skipping test; couldn't find memcached") + return + } + defer cmd.Wait() + defer cmd.Process.Kill() + + // Wait a bit for the socket to appear. + for i := 0; i < 10; i++ { + if _, err := os.Stat(sock); err == nil { + break + } + time.Sleep(25e6 * int64(i)) + } + + testWithClient(t, New(sock)) +} + +func testWithClient(t *testing.T, c *Client) { checkErr := func(err os.Error, format string, args ...interface{}) { if err != nil { t.Fatalf(format, args...) } } - c := New(testServer) - mustSet := func(it *Item) { if err := c.Set(it); err != nil { t.Fatalf("failed to Set %#v: %v", *it, err) diff --git a/lib/go/camli/third_party/github.com/bradfitz/gomemcache/selector.go b/lib/go/camli/third_party/github.com/bradfitz/gomemcache/selector.go index 9ee4c6b9d..eafcf3791 100644 --- a/lib/go/camli/third_party/github.com/bradfitz/gomemcache/selector.go +++ b/lib/go/camli/third_party/github.com/bradfitz/gomemcache/selector.go @@ -20,6 +20,7 @@ import ( "hash/crc32" "os" "net" + "strings" "sync" ) @@ -51,11 +52,19 @@ type ServerList struct { func (ss *ServerList) SetServers(servers ...string) os.Error { naddr := make([]net.Addr, len(servers)) for i, server := range servers { - tcpaddr, err := net.ResolveTCPAddr("tcp", server) - if err != nil { - return err + if strings.Contains(server, "/") { + addr, err := net.ResolveUnixAddr("unix", server) + if err != nil { + return err + } + naddr[i] = addr + } else { + tcpaddr, err := net.ResolveTCPAddr("tcp", server) + if err != nil { + return err + } + naddr[i] = tcpaddr } - naddr[i] = tcpaddr } ss.lk.Lock()