Update gomemcache in third_party.

Change-Id: Ide78f9528c1327fd91a681595429eb0ebdffacf0
This commit is contained in:
Brad Fitzpatrick 2011-07-03 16:13:44 -07:00
parent 3e792ae70b
commit f91404ecfc
2 changed files with 43 additions and 7 deletions

View File

@ -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)

View File

@ -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()