MCPcopy
hub / github.com/golang/groupcache / TestHTTPPool

Function TestHTTPPool

http_test.go:41–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39)
40
41func TestHTTPPool(t *testing.T) {
42 if *peerChild {
43 beChildForTestHTTPPool()
44 os.Exit(0)
45 }
46
47 const (
48 nChild = 4
49 nGets = 100
50 )
51
52 var childAddr []string
53 for i := 0; i < nChild; i++ {
54 childAddr = append(childAddr, pickFreeAddr(t))
55 }
56
57 var cmds []*exec.Cmd
58 var wg sync.WaitGroup
59 for i := 0; i < nChild; i++ {
60 cmd := exec.Command(os.Args[0],
61 "--test.run=TestHTTPPool",
62 "--test_peer_child",
63 "--test_peer_addrs="+strings.Join(childAddr, ","),
64 "--test_peer_index="+strconv.Itoa(i),
65 )
66 cmds = append(cmds, cmd)
67 wg.Add(1)
68 if err := cmd.Start(); err != nil {
69 t.Fatal("failed to start child process: ", err)
70 }
71 go awaitAddrReady(t, childAddr[i], &wg)
72 }
73 defer func() {
74 for i := 0; i < nChild; i++ {
75 if cmds[i].Process != nil {
76 cmds[i].Process.Kill()
77 }
78 }
79 }()
80 wg.Wait()
81
82 // Use a dummy self address so that we don't handle gets in-process.
83 p := NewHTTPPool("should-be-ignored")
84 p.Set(addrToURL(childAddr)...)
85
86 // Dummy getter function. Gets should go to children only.
87 // The only time this process will handle a get is when the
88 // children can't be contacted for some reason.
89 getter := GetterFunc(func(ctx context.Context, key string, dest Sink) error {
90 return errors.New("parent getter called; something's wrong")
91 })
92 g := NewGroup("httpPoolTest", 1<<20, getter)
93
94 for _, key := range testKeys(nGets) {
95 var value string
96 if err := g.Get(context.TODO(), key, StringSink(&value)); err != nil {
97 t.Fatal(err)
98 }

Callers

nothing calls this directly

Calls 12

SetMethod · 0.95
GetMethod · 0.95
beChildForTestHTTPPoolFunction · 0.85
pickFreeAddrFunction · 0.85
awaitAddrReadyFunction · 0.85
NewHTTPPoolFunction · 0.85
addrToURLFunction · 0.85
GetterFuncFuncType · 0.85
NewGroupFunction · 0.85
testKeysFunction · 0.85
StringSinkFunction · 0.85
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…