Jiri Simsa | d7616c9 | 2015-03-24 23:44:30 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Vanadium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Suharsh Sivakumar | cbfe474 | 2015-03-11 14:54:22 -0700 | [diff] [blame] | 5 | package test |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 6 | |
| 7 | import ( |
| 8 | "fmt" |
Matt Rosencrantz | 2b675f9 | 2015-03-05 12:52:50 -0800 | [diff] [blame] | 9 | "io" |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 10 | "os" |
| 11 | "reflect" |
| 12 | "sort" |
| 13 | "strings" |
| 14 | "testing" |
| 15 | "time" |
| 16 | |
Matt Rosencrantz | 2b675f9 | 2015-03-05 12:52:50 -0800 | [diff] [blame] | 17 | "v.io/v23" |
Jiri Simsa | 6ac9522 | 2015-02-23 16:11:49 -0800 | [diff] [blame] | 18 | "v.io/v23/context" |
Jiri Simsa | 6ac9522 | 2015-02-23 16:11:49 -0800 | [diff] [blame] | 19 | "v.io/v23/naming" |
David Why Use Two When One Will Do Presotto | d424c21 | 2015-02-25 11:05:26 -0800 | [diff] [blame] | 20 | "v.io/v23/naming/ns" |
Jiri Simsa | 6ac9522 | 2015-02-23 16:11:49 -0800 | [diff] [blame] | 21 | "v.io/v23/options" |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 22 | "v.io/v23/rpc" |
Jiri Simsa | 6ac9522 | 2015-02-23 16:11:49 -0800 | [diff] [blame] | 23 | "v.io/v23/security" |
| 24 | "v.io/v23/verror" |
| 25 | "v.io/v23/vtrace" |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 26 | |
Jiri Simsa | ffceefa | 2015-02-28 11:03:34 -0800 | [diff] [blame] | 27 | "v.io/x/ref/lib/flags" |
Jiri Simsa | ffceefa | 2015-02-28 11:03:34 -0800 | [diff] [blame] | 28 | _ "v.io/x/ref/profiles" |
Matt Rosencrantz | 86ba1a1 | 2015-03-09 13:19:02 -0700 | [diff] [blame] | 29 | "v.io/x/ref/profiles/internal/lib/publisher" |
Matt Rosencrantz | dbc1be2 | 2015-02-28 15:15:49 -0800 | [diff] [blame] | 30 | inaming "v.io/x/ref/profiles/internal/naming" |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 31 | irpc "v.io/x/ref/profiles/internal/rpc" |
| 32 | imanager "v.io/x/ref/profiles/internal/rpc/stream/manager" |
| 33 | "v.io/x/ref/profiles/internal/rpc/stream/proxy" |
Matt Rosencrantz | dbc1be2 | 2015-02-28 15:15:49 -0800 | [diff] [blame] | 34 | tnaming "v.io/x/ref/profiles/internal/testing/mocks/naming" |
| 35 | ivtrace "v.io/x/ref/profiles/internal/vtrace" |
Cosmos Nicolaou | 1381f8a | 2015-03-13 09:40:34 -0700 | [diff] [blame] | 36 | "v.io/x/ref/test/modules" |
Asim Shankar | 4a69828 | 2015-03-21 21:59:18 -0700 | [diff] [blame] | 37 | "v.io/x/ref/test/testutil" |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 38 | ) |
| 39 | |
Asim Shankar | 7171a25 | 2015-03-07 14:41:40 -0800 | [diff] [blame] | 40 | func testContext() (*context.T, func()) { |
| 41 | ctx, shutdown := v23.Init() |
| 42 | ctx, _ = context.WithTimeout(ctx, 20*time.Second) |
| 43 | var err error |
| 44 | if ctx, err = ivtrace.Init(ctx, flags.VtraceFlags{}); err != nil { |
| 45 | panic(err) |
| 46 | } |
| 47 | ctx, _ = vtrace.SetNewTrace(ctx) |
| 48 | return ctx, shutdown |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Matt Rosencrantz | 2b675f9 | 2015-03-05 12:52:50 -0800 | [diff] [blame] | 51 | func proxyServer(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error { |
| 52 | ctx, shutdown := v23.Init() |
| 53 | defer shutdown() |
| 54 | |
| 55 | expected := len(args) |
| 56 | listenSpec := v23.GetListenSpec(ctx) |
| 57 | protocol := listenSpec.Addrs[0].Protocol |
| 58 | addr := listenSpec.Addrs[0].Address |
| 59 | proxyShutdown, proxyEp, err := proxy.New(ctx, protocol, addr, "") |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | defer proxyShutdown() |
| 64 | |
| 65 | fmt.Fprintf(stdout, "PID=%d\n", os.Getpid()) |
| 66 | if expected > 0 { |
| 67 | pub := publisher.New(ctx, v23.GetNamespace(ctx), time.Minute) |
| 68 | defer pub.WaitForStop() |
| 69 | defer pub.Stop() |
Robin Thellend | 89e9523 | 2015-03-24 13:48:48 -0700 | [diff] [blame] | 70 | pub.AddServer(proxyEp.String()) |
Matt Rosencrantz | 2b675f9 | 2015-03-05 12:52:50 -0800 | [diff] [blame] | 71 | for _, name := range args { |
| 72 | if len(name) == 0 { |
| 73 | return fmt.Errorf("empty name specified on the command line") |
| 74 | } |
Robin Thellend | 89e9523 | 2015-03-24 13:48:48 -0700 | [diff] [blame] | 75 | pub.AddName(name, false, false) |
Matt Rosencrantz | 2b675f9 | 2015-03-05 12:52:50 -0800 | [diff] [blame] | 76 | } |
| 77 | // Wait for all the entries to be published. |
| 78 | for { |
| 79 | pubState := pub.Status() |
| 80 | if expected == len(pubState) { |
| 81 | break |
| 82 | } |
| 83 | fmt.Fprintf(stderr, "%s\n", pub.DebugString()) |
| 84 | delay := time.Second |
| 85 | fmt.Fprintf(stderr, "Sleeping: %s\n", delay) |
| 86 | time.Sleep(delay) |
| 87 | } |
| 88 | } |
| 89 | fmt.Fprintf(stdout, "PROXY_NAME=%s\n", proxyEp.Name()) |
| 90 | modules.WaitForEOF(stdin) |
| 91 | fmt.Fprintf(stdout, "DONE\n") |
| 92 | return nil |
| 93 | } |
| 94 | |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 95 | type testServer struct{} |
| 96 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 97 | func (*testServer) Echo(call rpc.ServerCall, arg string) (string, error) { |
Matt Rosencrantz | 311378b | 2015-03-25 15:26:12 -0700 | [diff] [blame] | 98 | return fmt.Sprintf("method:%q,suffix:%q,arg:%q", "Echo", call.Suffix(), arg), nil |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | type testServerAuthorizer struct{} |
| 102 | |
Matt Rosencrantz | 250558f | 2015-03-17 11:37:31 -0700 | [diff] [blame] | 103 | func (testServerAuthorizer) Authorize(*context.T) error { |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 104 | return nil |
| 105 | } |
| 106 | |
| 107 | type testServerDisp struct{ server interface{} } |
| 108 | |
| 109 | func (t testServerDisp) Lookup(suffix string) (interface{}, security.Authorizer, error) { |
| 110 | return t.server, testServerAuthorizer{}, nil |
| 111 | } |
| 112 | |
| 113 | type proxyHandle struct { |
David Why Use Two When One Will Do Presotto | d424c21 | 2015-02-25 11:05:26 -0800 | [diff] [blame] | 114 | ns ns.Namespace |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 115 | sh *modules.Shell |
| 116 | proxy modules.Handle |
| 117 | name string |
| 118 | } |
| 119 | |
| 120 | func (h *proxyHandle) Start(t *testing.T, ctx *context.T, args ...string) error { |
Cosmos Nicolaou | 9e90984 | 2015-03-17 11:58:59 -0700 | [diff] [blame] | 121 | sh, err := modules.NewShell(nil, nil, testing.Verbose(), t) |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 122 | if err != nil { |
| 123 | t.Fatalf("unexpected error: %s", err) |
| 124 | } |
| 125 | h.sh = sh |
Matt Rosencrantz | 2b675f9 | 2015-03-05 12:52:50 -0800 | [diff] [blame] | 126 | p, err := sh.Start("proxyServer", nil, args...) |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 127 | if err != nil { |
| 128 | t.Fatalf("unexpected error: %s", err) |
| 129 | } |
| 130 | h.proxy = p |
Cosmos Nicolaou | 9e90984 | 2015-03-17 11:58:59 -0700 | [diff] [blame] | 131 | p.ReadLine() |
| 132 | h.name = p.ExpectVar("PROXY_NAME") |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 133 | if len(h.name) == 0 { |
| 134 | t.Fatalf("failed to get PROXY_NAME from proxyd") |
| 135 | } |
| 136 | return h.ns.Mount(ctx, "proxy", h.name, time.Hour) |
| 137 | } |
| 138 | |
| 139 | func (h *proxyHandle) Stop(ctx *context.T) error { |
| 140 | defer h.sh.Cleanup(os.Stderr, os.Stderr) |
| 141 | if err := h.proxy.Shutdown(os.Stderr, os.Stderr); err != nil { |
| 142 | return err |
| 143 | } |
| 144 | if len(h.name) == 0 { |
| 145 | return nil |
| 146 | } |
| 147 | return h.ns.Unmount(ctx, "proxy", h.name) |
| 148 | } |
| 149 | |
| 150 | func TestProxyOnly(t *testing.T) { |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 151 | listenSpec := rpc.ListenSpec{Proxy: "proxy"} |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 152 | testProxy(t, listenSpec) |
| 153 | } |
| 154 | |
| 155 | func TestProxy(t *testing.T) { |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 156 | proxyListenSpec := rpc.ListenSpec{Addrs: rpc.ListenAddrs{{"tcp", "127.0.0.1:0"}}} |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 157 | proxyListenSpec.Proxy = "proxy" |
| 158 | testProxy(t, proxyListenSpec) |
| 159 | } |
| 160 | |
| 161 | func TestWSProxy(t *testing.T) { |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 162 | proxyListenSpec := rpc.ListenSpec{Addrs: rpc.ListenAddrs{{"tcp", "127.0.0.1:0"}}} |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 163 | proxyListenSpec.Proxy = "proxy" |
| 164 | // The proxy uses websockets only, but the server is using tcp. |
Asim Shankar | f32d24d | 2015-04-01 16:34:26 -0700 | [diff] [blame] | 165 | testProxy(t, proxyListenSpec, "--v23.tcp.protocol=ws") |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 168 | func testProxy(t *testing.T, spec rpc.ListenSpec, args ...string) { |
Asim Shankar | 7171a25 | 2015-03-07 14:41:40 -0800 | [diff] [blame] | 169 | ctx, shutdown := testContext() |
| 170 | defer shutdown() |
Ankur | 50a5f39 | 2015-02-27 18:46:30 -0800 | [diff] [blame] | 171 | var ( |
Asim Shankar | 4a69828 | 2015-03-21 21:59:18 -0700 | [diff] [blame] | 172 | pserver = testutil.NewPrincipal("server") |
| 173 | pclient = testutil.NewPrincipal("client") |
Ankur | 50a5f39 | 2015-02-27 18:46:30 -0800 | [diff] [blame] | 174 | serverKey = pserver.PublicKey() |
| 175 | // We use different stream managers for the client and server |
| 176 | // to prevent VIF re-use (in other words, we want to test VIF |
| 177 | // creation from both the client and server end). |
| 178 | smserver = imanager.InternalNew(naming.FixedRoutingID(0x555555555)) |
| 179 | smclient = imanager.InternalNew(naming.FixedRoutingID(0x444444444)) |
| 180 | ns = tnaming.NewSimpleNamespace() |
| 181 | ) |
| 182 | defer smserver.Shutdown() |
| 183 | defer smclient.Shutdown() |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 184 | client, err := irpc.InternalNewClient(smserver, ns) |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 185 | if err != nil { |
| 186 | t.Fatal(err) |
| 187 | } |
| 188 | defer client.Close() |
Asim Shankar | 7171a25 | 2015-03-07 14:41:40 -0800 | [diff] [blame] | 189 | serverCtx, _ := v23.SetPrincipal(ctx, pserver) |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 190 | server, err := irpc.InternalNewServer(serverCtx, smserver, ns, nil, pserver) |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 191 | if err != nil { |
| 192 | t.Fatal(err) |
| 193 | } |
| 194 | defer server.Stop() |
| 195 | |
Asim Shankar | 263c73b | 2015-03-19 18:31:26 -0700 | [diff] [blame] | 196 | // The client must recognize the server's blessings, otherwise it won't |
| 197 | // communicate with it. |
| 198 | pclient.AddToRoots(pserver.BlessingStore().Default()) |
| 199 | |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 200 | // If no address is specified then we'll only 'listen' via |
| 201 | // the proxy. |
| 202 | hasLocalListener := len(spec.Addrs) > 0 && len(spec.Addrs[0].Address) != 0 |
| 203 | |
| 204 | name := "mountpoint/server/suffix" |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 205 | makeCall := func(opts ...rpc.CallOpt) (string, error) { |
Asim Shankar | 263c73b | 2015-03-19 18:31:26 -0700 | [diff] [blame] | 206 | clientCtx, _ := v23.SetPrincipal(ctx, pclient) |
| 207 | clientCtx, _ = context.WithDeadline(clientCtx, time.Now().Add(5*time.Second)) |
| 208 | call, err := client.StartCall(clientCtx, name, "Echo", []interface{}{"batman"}, opts...) |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 209 | if err != nil { |
| 210 | // proxy is down, we should return here/.... prepend |
| 211 | // the error with a well known string so that we can test for that. |
| 212 | return "", fmt.Errorf("RESOLVE: %s", err) |
| 213 | } |
| 214 | var result string |
| 215 | if err = call.Finish(&result); err != nil { |
| 216 | return "", err |
| 217 | } |
| 218 | return result, nil |
| 219 | } |
| 220 | proxy := &proxyHandle{ns: ns} |
| 221 | if err := proxy.Start(t, ctx, args...); err != nil { |
| 222 | t.Fatal(err) |
| 223 | } |
| 224 | defer proxy.Stop(ctx) |
| 225 | addrs := verifyMount(t, ctx, ns, spec.Proxy) |
| 226 | if len(addrs) != 1 { |
| 227 | t.Fatalf("failed to lookup proxy") |
| 228 | } |
| 229 | |
| 230 | eps, err := server.Listen(spec) |
| 231 | if err != nil { |
| 232 | t.Fatal(err) |
| 233 | } |
| 234 | if err := server.ServeDispatcher("mountpoint/server", testServerDisp{&testServer{}}); err != nil { |
| 235 | t.Fatal(err) |
| 236 | } |
| 237 | |
| 238 | // Proxy connections are started asynchronously, so we need to wait.. |
| 239 | waitForMountTable := func(ch chan int, expect int) { |
| 240 | then := time.Now().Add(time.Minute) |
| 241 | for { |
| 242 | me, err := ns.Resolve(ctx, name) |
| 243 | if err == nil && len(me.Servers) == expect { |
| 244 | ch <- 1 |
| 245 | return |
| 246 | } |
| 247 | if time.Now().After(then) { |
| 248 | t.Fatalf("timed out") |
| 249 | } |
| 250 | time.Sleep(100 * time.Millisecond) |
| 251 | } |
| 252 | } |
| 253 | waitForServerStatus := func(ch chan int, proxy string) { |
| 254 | then := time.Now().Add(time.Minute) |
| 255 | for { |
| 256 | status := server.Status() |
| 257 | if len(status.Proxies) == 1 && status.Proxies[0].Proxy == proxy { |
| 258 | ch <- 2 |
| 259 | return |
| 260 | } |
| 261 | if time.Now().After(then) { |
| 262 | t.Fatalf("timed out") |
| 263 | } |
| 264 | time.Sleep(100 * time.Millisecond) |
| 265 | } |
| 266 | } |
| 267 | proxyEP, _ := naming.SplitAddressName(addrs[0]) |
| 268 | proxiedEP, err := inaming.NewEndpoint(proxyEP) |
| 269 | if err != nil { |
| 270 | t.Fatalf("unexpected error for %q: %s", proxyEP, err) |
| 271 | } |
| 272 | proxiedEP.RID = naming.FixedRoutingID(0x555555555) |
Asim Shankar | 7171a25 | 2015-03-07 14:41:40 -0800 | [diff] [blame] | 273 | proxiedEP.Blessings = []string{"server"} |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 274 | expectedNames := []string{naming.JoinAddressName(proxiedEP.String(), "suffix")} |
| 275 | if hasLocalListener { |
| 276 | expectedNames = append(expectedNames, naming.JoinAddressName(eps[0].String(), "suffix")) |
| 277 | } |
| 278 | |
| 279 | // Proxy connetions are created asynchronously, so we wait for the |
| 280 | // expected number of endpoints to appear for the specified service name. |
| 281 | ch := make(chan int, 2) |
| 282 | go waitForMountTable(ch, len(expectedNames)) |
| 283 | go waitForServerStatus(ch, spec.Proxy) |
| 284 | select { |
| 285 | case <-time.After(time.Minute): |
| 286 | t.Fatalf("timedout waiting for two entries in the mount table and server status") |
| 287 | case i := <-ch: |
| 288 | select { |
| 289 | case <-time.After(time.Minute): |
| 290 | t.Fatalf("timedout waiting for two entries in the mount table or server status") |
| 291 | case j := <-ch: |
| 292 | if !((i == 1 && j == 2) || (i == 2 && j == 1)) { |
| 293 | t.Fatalf("unexpected return values from waiters") |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | status := server.Status() |
| 299 | if got, want := status.Proxies[0].Endpoint, proxiedEP; !reflect.DeepEqual(got, want) { |
| 300 | t.Fatalf("got %q, want %q", got, want) |
| 301 | } |
| 302 | |
| 303 | got := []string{} |
| 304 | for _, s := range verifyMount(t, ctx, ns, name) { |
| 305 | got = append(got, s) |
| 306 | } |
| 307 | sort.Strings(got) |
| 308 | sort.Strings(expectedNames) |
| 309 | if !reflect.DeepEqual(got, expectedNames) { |
| 310 | t.Errorf("got %v, want %v", got, expectedNames) |
| 311 | } |
| 312 | |
| 313 | if hasLocalListener { |
| 314 | // Listen will publish both the local and proxied endpoint with the |
| 315 | // mount table, given that we're trying to test the proxy, we remove |
| 316 | // the local endpoint from the mount table entry! We have to remove both |
| 317 | // the tcp and the websocket address. |
| 318 | sep := eps[0].String() |
| 319 | ns.Unmount(ctx, "mountpoint/server", sep) |
| 320 | } |
| 321 | |
| 322 | addrs = verifyMount(t, ctx, ns, name) |
| 323 | if len(addrs) != 1 { |
| 324 | t.Fatalf("failed to lookup proxy: addrs %v", addrs) |
| 325 | } |
| 326 | |
Ankur | 50a5f39 | 2015-02-27 18:46:30 -0800 | [diff] [blame] | 327 | // Proxied endpoint should be published and RPC should succeed (through proxy). |
| 328 | // Additionally, any server authorizaton options must only apply to the end server |
| 329 | // and not the proxy. |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 330 | const expected = `method:"Echo",suffix:"suffix",arg:"batman"` |
Ankur | 50a5f39 | 2015-02-27 18:46:30 -0800 | [diff] [blame] | 331 | if result, err := makeCall(options.ServerPublicKey{serverKey}); result != expected || err != nil { |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 332 | t.Fatalf("Got (%v, %v) want (%v, nil)", result, err, expected) |
| 333 | } |
Ankur | 50a5f39 | 2015-02-27 18:46:30 -0800 | [diff] [blame] | 334 | |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 335 | // Proxy dies, calls should fail and the name should be unmounted. |
| 336 | if err := proxy.Stop(ctx); err != nil { |
| 337 | t.Fatal(err) |
| 338 | } |
| 339 | |
Suharsh Sivakumar | 90da4c2 | 2015-02-12 15:45:56 -0800 | [diff] [blame] | 340 | if result, err := makeCall(options.NoRetry{}); err == nil || (!strings.HasPrefix(err.Error(), "RESOLVE") && !strings.Contains(err.Error(), "EOF")) { |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 341 | t.Fatalf(`Got (%v, %v) want ("", "RESOLVE: <err>" or "EOF") as proxy is down`, result, err) |
| 342 | } |
| 343 | |
| 344 | for { |
| 345 | if _, err := ns.Resolve(ctx, name); err != nil { |
| 346 | break |
| 347 | } |
| 348 | time.Sleep(10 * time.Millisecond) |
| 349 | } |
| 350 | verifyMountMissing(t, ctx, ns, name) |
| 351 | |
| 352 | status = server.Status() |
Todd Wang | 8fa3876 | 2015-03-25 14:04:59 -0700 | [diff] [blame] | 353 | if len(status.Proxies) != 1 || status.Proxies[0].Proxy != spec.Proxy || verror.ErrorID(status.Proxies[0].Error) != verror.ErrNoServers.ID { |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 354 | t.Fatalf("proxy status is incorrect: %v", status.Proxies) |
| 355 | } |
| 356 | |
| 357 | // Proxy restarts, calls should eventually start succeeding. |
| 358 | if err := proxy.Start(t, ctx, args...); err != nil { |
| 359 | t.Fatal(err) |
| 360 | } |
| 361 | |
| 362 | retries := 0 |
| 363 | for { |
| 364 | if result, err := makeCall(); err == nil { |
| 365 | if result != expected { |
| 366 | t.Errorf("Got (%v, %v) want (%v, nil)", result, err, expected) |
| 367 | } |
| 368 | break |
| 369 | } else { |
| 370 | retries++ |
| 371 | if retries > 10 { |
| 372 | t.Fatalf("Failed after 10 attempts: err: %s", err) |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
David Why Use Two When One Will Do Presotto | d424c21 | 2015-02-25 11:05:26 -0800 | [diff] [blame] | 378 | func verifyMount(t *testing.T, ctx *context.T, ns ns.Namespace, name string) []string { |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 379 | me, err := ns.Resolve(ctx, name) |
| 380 | if err != nil { |
| 381 | t.Errorf("%s not found in mounttable", name) |
| 382 | return nil |
| 383 | } |
| 384 | return me.Names() |
| 385 | } |
| 386 | |
David Why Use Two When One Will Do Presotto | d424c21 | 2015-02-25 11:05:26 -0800 | [diff] [blame] | 387 | func verifyMountMissing(t *testing.T, ctx *context.T, ns ns.Namespace, name string) { |
Suharsh Sivakumar | 9d17e4a | 2015-02-02 22:42:16 -0800 | [diff] [blame] | 388 | if me, err := ns.Resolve(ctx, name); err == nil { |
| 389 | names := me.Names() |
| 390 | t.Errorf("%s not supposed to be found in mounttable; got %d servers instead: %v", name, len(names), names) |
| 391 | } |
| 392 | } |