(t *testing.T)
| 39 | ) |
| 40 | |
| 41 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…