Merge "veyron/lib/modules: Make modules parse flags using the veyron2.Init flag parsing mechanism."
diff --git a/lib/filelocker/locker_test.go b/lib/filelocker/locker_test.go
index b58bfe2..cf483a7 100644
--- a/lib/filelocker/locker_test.go
+++ b/lib/filelocker/locker_test.go
@@ -42,7 +42,7 @@
func testLockChild(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
// Lock the file
- unlocker, err := Lock(args[1])
+ unlocker, err := Lock(args[0])
if err != nil {
return fmt.Errorf("Lock failed: %v", err)
}
diff --git a/lib/flags/flags.go b/lib/flags/flags.go
index b2c767e..241420c 100644
--- a/lib/flags/flags.go
+++ b/lib/flags/flags.go
@@ -5,6 +5,7 @@
"fmt"
"os"
"strings"
+ "sync"
"v.io/core/veyron/lib/flags/consts"
)
@@ -236,12 +237,40 @@
return f
}
+var (
+ defaultProtocol = "wsh" // GUARDED_BY listenMu
+ defaultHostPort = ":0" // GUARDED_BY listenMu
+ listenMu sync.RWMutex
+)
+
+// SetDefaultProtocol sets the default protocol used when --veyron.tcp.protocol is
+// not provided. It must be called before flags are parsed for it to take effect.
+func SetDefaultProtocol(protocol string) {
+ listenMu.Lock()
+ defaultProtocol = protocol
+ listenMu.Unlock()
+}
+
+// SetDefaultHostPort sets the default host and port used when --veyron.tcp.address
+// is not provided. It must be called before flags are parsed for it to take effect.
+func SetDefaultHostPort(s string) {
+ listenMu.Lock()
+ defaultHostPort = s
+ listenMu.Unlock()
+}
+
// createAndRegisterListenFlags creates and registers the ListenFlags
// group with the supplied flag.FlagSet.
func createAndRegisterListenFlags(fs *flag.FlagSet) *ListenFlags {
+ listenMu.RLock()
+ defer listenMu.RUnlock()
+ var ipHostPortFlag IPHostPortFlag
+ if err := ipHostPortFlag.Set(defaultHostPort); err != nil {
+ panic(err)
+ }
f := &ListenFlags{
- protocol: TCPProtocolFlag{"wsh"},
- addresses: ipHostPortFlagVar{validator: IPHostPortFlag{Port: "0"}},
+ protocol: TCPProtocolFlag{defaultProtocol},
+ addresses: ipHostPortFlagVar{validator: ipHostPortFlag},
}
f.addresses.flags = f
diff --git a/lib/modules/core/core_test.go b/lib/modules/core/core_test.go
index a0e03e8..9f2b0b5 100644
--- a/lib/modules/core/core_test.go
+++ b/lib/modules/core/core_test.go
@@ -55,7 +55,7 @@
}
func testArgs(args ...string) []string {
- var targs = []string{"--", "--veyron.tcp.address=127.0.0.1:0"}
+ var targs = []string{"--veyron.tcp.address=127.0.0.1:0"}
return append(targs, args...)
}
diff --git a/lib/modules/core/echo.go b/lib/modules/core/echo.go
index 92160b9..8ba8f5f 100644
--- a/lib/modules/core/echo.go
+++ b/lib/modules/core/echo.go
@@ -50,13 +50,6 @@
ctx, shutdown := veyron2.Init()
defer shutdown()
- fl, args, err := parseListenFlags(args)
- if err != nil {
- return fmt.Errorf("failed to parse args: %s", err)
- }
- if err := checkArgs(args, 2, "<message> <name>"); err != nil {
- return err
- }
id, mp := args[0], args[1]
disp := &treeDispatcher{id: id}
server, err := veyron2.NewServer(ctx)
@@ -64,7 +57,7 @@
return err
}
defer server.Stop()
- eps, err := server.Listen(initListenSpec(fl))
+ eps, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
return err
}
@@ -83,7 +76,6 @@
ctx, shutdown := veyron2.Init()
defer shutdown()
- args = args[1:]
name := args[0]
args = args[1:]
client := veyron2.GetClient(ctx)
diff --git a/lib/modules/core/mounttable.go b/lib/modules/core/mounttable.go
index 6046c91..00acb04 100644
--- a/lib/modules/core/mounttable.go
+++ b/lib/modules/core/mounttable.go
@@ -34,11 +34,7 @@
ctx, shutdown := veyron2.Init()
defer shutdown()
- fl, args, err := parseListenFlags(args)
- if err != nil {
- return fmt.Errorf("failed to parse args: %s", err)
- }
- lspec := initListenSpec(fl)
+ lspec := veyron2.GetListenSpec(ctx)
server, err := veyron2.NewServer(ctx, options.ServesMountTable(true))
if err != nil {
return fmt.Errorf("root failed: %v", err)
@@ -74,7 +70,6 @@
defer shutdown()
details := false
- args = args[1:] // skip over command name
if len(args) > 0 && args[0] == "-l" {
details = true
args = args[1:]
diff --git a/lib/modules/core/proxy.go b/lib/modules/core/proxy.go
index 79d826b..691d1ca 100644
--- a/lib/modules/core/proxy.go
+++ b/lib/modules/core/proxy.go
@@ -22,18 +22,17 @@
ctx, shutdown := veyron2.Init()
defer shutdown()
- fl, args, err := parseListenFlags(args)
- if err != nil {
- return fmt.Errorf("failed to parse args: %s", err)
- }
expected := len(args)
rid, err := naming.NewRoutingID()
if err != nil {
return err
}
- lf := fl.ListenFlags()
- proxy, err := proxy.New(rid, veyron2.GetPrincipal(ctx), lf.Addrs[0].Protocol, lf.Addrs[0].Address, "")
+ listenSpec := veyron2.GetListenSpec(ctx)
+ protocol := listenSpec.Addrs[0].Protocol
+ addr := listenSpec.Addrs[0].Address
+
+ proxy, err := proxy.New(rid, veyron2.GetPrincipal(ctx), protocol, addr, "")
if err != nil {
return err
}
diff --git a/lib/modules/core/test_identityd.go b/lib/modules/core/test_identityd.go
index f1bc19a..793824a 100644
--- a/lib/modules/core/test_identityd.go
+++ b/lib/modules/core/test_identityd.go
@@ -10,7 +10,6 @@
"v.io/core/veyron2"
- "v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/modules"
"v.io/core/veyron/services/identity/auditor"
@@ -23,46 +22,41 @@
)
var (
- ifs *flag.FlagSet = flag.NewFlagSet("test_identityd", flag.ContinueOnError)
-
- googleDomain = ifs.String("google_domain", "", "An optional domain name. When set, only email addresses from this domain are allowed to authenticate via Google OAuth")
- host = ifs.String("host", "localhost", "Hostname the HTTP server listens on. This can be the name of the host running the webserver, but if running behind a NAT or load balancer, this should be the host name that clients will connect to. For example, if set to 'x.com', Veyron identities will have the IssuerName set to 'x.com' and clients can expect to find the root name and public key of the signer at 'x.com/blessing-root'.")
- httpaddr = ifs.String("httpaddr", "localhost:0", "Address on which the HTTP server listens on.")
- tlsconfig = ifs.String("tlsconfig", "", "Comma-separated list of TLS certificate and private key files. This must be provided.")
-
- ifl *flags.Flags = flags.CreateAndRegister(ifs, flags.Listen)
+ googleDomain = flag.CommandLine.String("google_domain", "", "An optional domain name. When set, only email addresses from this domain are allowed to authenticate via Google OAuth")
+ host = flag.CommandLine.String("host", "localhost", "Hostname the HTTP server listens on. This can be the name of the host running the webserver, but if running behind a NAT or load balancer, this should be the host name that clients will connect to. For example, if set to 'x.com', Veyron identities will have the IssuerName set to 'x.com' and clients can expect to find the root name and public key of the signer at 'x.com/blessing-root'.")
+ httpaddr = flag.CommandLine.String("httpaddr", "localhost:0", "Address on which the HTTP server listens on.")
+ tlsconfig = flag.CommandLine.String("tlsconfig", "", "Comma-separated list of TLS certificate and private key files. This must be provided.")
)
func init() {
- modules.RegisterChild(TestIdentitydCommand, usage(ifs), startTestIdentityd)
+ modules.RegisterChild(TestIdentitydCommand, usage(flag.CommandLine), startTestIdentityd)
}
func startTestIdentityd(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- if err := parseFlags(ifl, args); err != nil {
- return fmt.Errorf("failed to parse args: %s", err)
- }
-
// Duration to use for tls cert and blessing duration.
duration := 365 * 24 * time.Hour
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
// If no tlsconfig has been provided, generate new cert and key and use them.
- if ifs.Lookup("tlsconfig").Value.String() == "" {
+ if flag.CommandLine.Lookup("tlsconfig").Value.String() == "" {
certFile, keyFile, err := util.WriteCertAndKey(*host, duration)
if err != nil {
return fmt.Errorf("Could not write cert and key: %v", err)
}
- if err := ifs.Set("tlsconfig", certFile+","+keyFile); err != nil {
+ if err := flag.CommandLine.Set("tlsconfig", certFile+","+keyFile); err != nil {
return fmt.Errorf("Could not set tlsconfig: %v", err)
}
}
// Pick a free port if httpaddr flag is not set.
- // We can't use :0 here, because the identity server calles
- // http.ListenAndServeTLS, which block, leaving us with no way to tell
+ // We can't use :0 here, because the identity server calls
+ // http.ListenAndServeTLS, which blocks, leaving us with no way to tell
// what port the server is running on. Hence, we must pass in an
// actual port so we know where the server is running.
- if ifs.Lookup("httpaddr").Value.String() == ifs.Lookup("httpaddr").DefValue {
- if err := ifs.Set("httpaddr", "localhost:"+freePort()); err != nil {
+ if flag.CommandLine.Lookup("httpaddr").Value.String() == flag.CommandLine.Lookup("httpaddr").DefValue {
+ if err := flag.CommandLine.Set("httpaddr", "localhost:"+freePort()); err != nil {
return fmt.Errorf("Could not set httpaddr: %v", err)
}
}
@@ -86,10 +80,7 @@
params,
caveats.NewMockCaveatSelector())
- l := initListenSpec(ifl)
-
- ctx, shutdown := veyron2.Init()
- defer shutdown()
+ l := veyron2.GetListenSpec(ctx)
_, veyronEPs, externalHttpaddress := s.Listen(ctx, &l, *host, *httpaddr, *tlsconfig)
diff --git a/lib/modules/core/util.go b/lib/modules/core/util.go
index 3d16bb7..08c53f3 100644
--- a/lib/modules/core/util.go
+++ b/lib/modules/core/util.go
@@ -4,36 +4,8 @@
"flag"
"fmt"
"strings"
-
- "v.io/core/veyron2/ipc"
-
- "v.io/core/veyron/lib/flags"
)
-func parseFlags(fl *flags.Flags, args []string) error {
- if len(args) == 0 {
- return nil
- }
- return fl.Parse(args[1:], nil)
-}
-
-// parseListenFlags parses the given args using just the flags and env vars
-// defined in the veyron/lib/flags package.
-func parseListenFlags(args []string) (*flags.Flags, []string, error) {
- fs := flag.NewFlagSet("modules/core", flag.ContinueOnError)
- fl := flags.CreateAndRegister(fs, flags.Listen)
- err := parseFlags(fl, args)
- return fl, fl.Args(), err
-}
-
-func initListenSpec(fl *flags.Flags) ipc.ListenSpec {
- lf := fl.ListenFlags()
- return ipc.ListenSpec{
- Addrs: ipc.ListenAddrs(lf.Addrs),
- Proxy: lf.ListenProxy,
- }
-}
-
// checkArgs checks for the expected number of args in args. A negative
// value means at least that number of args are expected.
func checkArgs(args []string, expected int, usage string) error {
diff --git a/lib/modules/core/wspr.go b/lib/modules/core/wspr.go
index 42db213..8e38a84 100644
--- a/lib/modules/core/wspr.go
+++ b/lib/modules/core/wspr.go
@@ -5,7 +5,6 @@
"fmt"
"io"
- "v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/modules"
"v.io/wspr/veyron/services/wsprd/wspr"
@@ -13,29 +12,19 @@
)
var (
- // TODO(sadovsky): We should restructure things so that we can avoid
- // duplicating code between subprocess command impls and actual main()'s.
- fs *flag.FlagSet = flag.NewFlagSet("wspr", flag.ContinueOnError)
-
- port *int = fs.Int("port", 0, "Port to listen on.")
- identd *string = fs.String("identd", "", "identd server name. Must be set.")
-
- fl *flags.Flags = flags.CreateAndRegister(fs, flags.Listen)
+ port *int = flag.CommandLine.Int("port", 0, "Port to listen on.")
+ identd *string = flag.CommandLine.String("identd", "", "identd server name. Must be set.")
)
func init() {
- modules.RegisterChild(WSPRCommand, usage(fs), startWSPR)
+ modules.RegisterChild(WSPRCommand, usage(flag.CommandLine), startWSPR)
}
func startWSPR(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- if err := parseFlags(fl, args); err != nil {
- return fmt.Errorf("failed to parse args: %s", err)
- }
-
ctx, shutdown := veyron2.Init()
defer shutdown()
- l := initListenSpec(fl)
+ l := veyron2.GetListenSpec(ctx)
proxy := wspr.NewWSPR(ctx, *port, &l, *identd, nil)
defer proxy.Shutdown()
diff --git a/lib/modules/examples_test.go b/lib/modules/examples_test.go
index cb97b64..e4ab42a 100644
--- a/lib/modules/examples_test.go
+++ b/lib/modules/examples_test.go
@@ -36,9 +36,8 @@
h, _ := sh.Start("echo", nil, "a", "b")
h.Shutdown(os.Stdout, os.Stderr)
// Output:
- // 0: echo
- // 1: a
- // 2: b
+ // 0: a
+ // 1: b
}
func ExampleDispatchAndExit() {
@@ -51,7 +50,6 @@
h, _ := sh.Start("echo", nil, "c", "d")
h.Shutdown(os.Stdout, os.Stderr)
// Output:
- // 0: echo
- // 1: c
- // 2: d
+ // 0: c
+ // 1: d
}
diff --git a/lib/modules/func.go b/lib/modules/func.go
index 5c5bc4c..24f1fde 100644
--- a/lib/modules/func.go
+++ b/lib/modules/func.go
@@ -88,7 +88,7 @@
cenv := envSliceToMap(env)
vlog.VI(1).Infof("Start: %q args: %v", fh.name, args)
vlog.VI(2).Infof("Start: %q env: %v", fh.name, cenv)
- err := main(stdin, stdout, stderr, cenv, args...)
+ err := main(stdin, stdout, stderr, cenv, args[1:]...)
if err != nil {
fmt.Fprintf(stderr, "%s\n", err)
}
diff --git a/lib/modules/modules_test.go b/lib/modules/modules_test.go
index 277fb2f..a5c989d 100644
--- a/lib/modules/modules_test.go
+++ b/lib/modules/modules_test.go
@@ -62,7 +62,7 @@
}
func PrintFromEnv(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- for _, a := range args[1:] {
+ for _, a := range args {
if v := env[a]; len(v) > 0 {
fmt.Fprintf(stdout, "%s\n", a+"="+v)
} else {
@@ -286,7 +286,7 @@
var stdoutBuf bytes.Buffer
var stderrBuf bytes.Buffer
sh.Cleanup(&stdoutBuf, &stderrBuf)
- stdoutOutput, stderrOutput := "stdout: "+command+"\n", "stderr: "+command+"\n"
+ var stdoutOutput, stderrOutput string
for _, a := range args {
stdoutOutput += fmt.Sprintf("stdout: %s\n", a)
stderrOutput += fmt.Sprintf("stderr: %s\n", a)
diff --git a/lib/modules/registry.go b/lib/modules/registry.go
index 8331f9c..f473d14 100644
--- a/lib/modules/registry.go
+++ b/lib/modules/registry.go
@@ -200,8 +200,8 @@
}
}(os.Getppid())
- args := append([]string{command}, flag.Args()...)
- return m.main(os.Stdin, os.Stdout, os.Stderr, envSliceToMap(os.Environ()), args...)
+ flag.Parse()
+ return m.main(os.Stdin, os.Stdout, os.Stderr, envSliceToMap(os.Environ()), flag.Args()...)
}
// WaitForEOF returns when a read on its io.Reader parameter returns io.EOF
diff --git a/lib/testutil/glob.go b/lib/testutil/glob.go
index 84d7ec7..0c6fd23 100644
--- a/lib/testutil/glob.go
+++ b/lib/testutil/glob.go
@@ -35,5 +35,6 @@
if ferr := call.Finish(&err); ferr != nil {
err = ferr
}
+
return results, err
}
diff --git a/lib/testutil/integration/util.go b/lib/testutil/integration/util.go
index da7db76..82870e2 100644
--- a/lib/testutil/integration/util.go
+++ b/lib/testutil/integration/util.go
@@ -548,7 +548,7 @@
// returns a handle for the started command along with the object name
// of the mount table.
func startRootMT(shell *modules.Shell) (modules.Handle, string, error) {
- handle, err := shell.Start(core.RootMTCommand, nil, "--", "--veyron.tcp.address=127.0.0.1:0")
+ handle, err := shell.Start(core.RootMTCommand, nil, "--veyron.tcp.address=127.0.0.1:0")
if err != nil {
return nil, "", err
}
diff --git a/profiles/genericinit.go b/profiles/genericinit.go
index b071c31..936cd2f 100644
--- a/profiles/genericinit.go
+++ b/profiles/genericinit.go
@@ -24,7 +24,9 @@
func init() {
veyron2.RegisterProfileInit(Init)
stream.RegisterUnknownProtocol("wsh", websocket.HybridDial, websocket.HybridListener)
- commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime)
+ flags.SetDefaultProtocol("tcp")
+ flags.SetDefaultHostPort("127.0.0.1:0")
+ commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime, flags.Listen)
}
func Init(ctx *context.T) (veyron2.Runtime, *context.T, veyron2.Shutdown, error) {
@@ -34,13 +36,17 @@
ac := appcycle.New()
+ lf := commonFlags.ListenFlags()
+ listenSpec := ipc.ListenSpec{
+ Addrs: ipc.ListenAddrs(lf.Addrs),
+ AddressChooser: internal.IPAddressChooser,
+ Proxy: lf.ListenProxy,
+ }
+
runtime, ctx, shutdown, err := grt.Init(ctx,
ac,
nil,
- &ipc.ListenSpec{
- Addrs: ipc.ListenAddrs{{"tcp", "127.0.0.1:0"}},
- AddressChooser: internal.IPAddressChooser,
- },
+ &listenSpec,
commonFlags.RuntimeFlags(),
nil)
if err != nil {
diff --git a/runtimes/google/ipc/client_test.go b/runtimes/google/ipc/client_test.go
index b91f8c0..548db9a 100644
--- a/runtimes/google/ipc/client_test.go
+++ b/runtimes/google/ipc/client_test.go
@@ -36,17 +36,12 @@
return ctx, shutdown
}
-func testArgs(args ...string) []string {
- var targs = []string{"--", "--veyron.tcp.address=127.0.0.1:0"}
- return append(targs, args...)
-}
-
func runMountTable(t *testing.T, ctx *context.T) (*modules.Shell, func()) {
sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
- root, err := sh.Start(core.RootMTCommand, nil, testArgs()...)
+ root, err := sh.Start(core.RootMTCommand, nil)
if err != nil {
t.Fatalf("unexpected error for root mt: %s", err)
}
@@ -109,7 +104,7 @@
sh, fn := runMountTable(t, ctx)
defer fn()
- srv, err := sh.Start(core.EchoServerCommand, nil, testArgs("echoServer", "echoServer")...)
+ srv, err := sh.Start(core.EchoServerCommand, nil, "echoServer", "echoServer")
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -172,7 +167,7 @@
defer shutdown()
veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
- name := args[1]
+ name := args[0]
call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Ping", nil)
if err != nil {
fmt.Errorf("unexpected error: %s", err)
@@ -334,7 +329,7 @@
// backoff of some minutes.
startServer := func() {
time.Sleep(10 * time.Millisecond)
- srv, _ := sh.Start(core.EchoServerCommand, nil, testArgs("message", name)...)
+ srv, _ := sh.Start(core.EchoServerCommand, nil, "message", name)
s := expect.NewSession(t, srv.Stdout(), time.Minute)
s.ExpectVar("PID")
s.ExpectVar("NAME")
@@ -495,7 +490,7 @@
t.Fatalf("unexpected error: %s", err)
}
defer sh.Cleanup(os.Stderr, os.Stderr)
- server, err := sh.Start(core.EchoServerCommand, nil, "--", "--veyron.tcp.address=127.0.0.1:0", "mymessage", "")
+ server, err := sh.Start(core.EchoServerCommand, nil, "--veyron.tcp.address=127.0.0.1:0", "mymessage", "")
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -536,7 +531,7 @@
// Resurrect the server with the same address, verify client
// re-establishes the connection. This is racy if another
// process grabs the port.
- server, err = sh.Start(core.EchoServerCommand, nil, "--", "--veyron.tcp.address="+ep.Address, "mymessage again", "")
+ server, err = sh.Start(core.EchoServerCommand, nil, "--veyron.tcp.address="+ep.Address, "mymessage again", "")
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
diff --git a/runtimes/google/ipc/full_test.go b/runtimes/google/ipc/full_test.go
index 2db17e4..c7e5252 100644
--- a/runtimes/google/ipc/full_test.go
+++ b/runtimes/google/ipc/full_test.go
@@ -6,6 +6,7 @@
"fmt"
"io"
"net"
+ "os"
"path/filepath"
"reflect"
"runtime"
@@ -1745,6 +1746,10 @@
}
func init() {
- testutil.Init()
vdl.Register(fakeTimeCaveat(0))
}
+
+func TestMain(m *testing.M) {
+ testutil.Init()
+ os.Exit(m.Run())
+}
diff --git a/runtimes/google/ipc/proxy_test.go b/runtimes/google/ipc/proxy_test.go
new file mode 100644
index 0000000..08123c6
--- /dev/null
+++ b/runtimes/google/ipc/proxy_test.go
@@ -0,0 +1,330 @@
+package ipc_test
+
+import (
+ "fmt"
+ "os"
+ "reflect"
+ "sort"
+ "strings"
+ "testing"
+ "time"
+
+ "v.io/core/veyron2/context"
+ "v.io/core/veyron2/ipc"
+ "v.io/core/veyron2/naming"
+ "v.io/core/veyron2/security"
+ verror "v.io/core/veyron2/verror2"
+ "v.io/core/veyron2/vtrace"
+
+ "v.io/core/veyron/lib/expect"
+ "v.io/core/veyron/lib/flags"
+ "v.io/core/veyron/lib/modules"
+ "v.io/core/veyron/lib/modules/core"
+ tsecurity "v.io/core/veyron/lib/testutil/security"
+ _ "v.io/core/veyron/profiles"
+ iipc "v.io/core/veyron/runtimes/google/ipc"
+ imanager "v.io/core/veyron/runtimes/google/ipc/stream/manager"
+ "v.io/core/veyron/runtimes/google/ipc/stream/vc"
+ inaming "v.io/core/veyron/runtimes/google/naming"
+ tnaming "v.io/core/veyron/runtimes/google/testing/mocks/naming"
+ ivtrace "v.io/core/veyron/runtimes/google/vtrace"
+)
+
+func testContext() *context.T {
+ ctx, _ := context.WithTimeout(testContextWithoutDeadline(), 20*time.Second)
+ return ctx
+}
+
+func testContextWithoutDeadline() *context.T {
+ ctx, _ := context.RootContext()
+ ctx, err := ivtrace.Init(ctx, flags.VtraceFlags{})
+ if err != nil {
+ panic(err)
+ }
+ ctx, _ = vtrace.SetNewTrace(ctx)
+ return ctx
+}
+
+type testServer struct{}
+
+func (*testServer) Echo(ctx ipc.ServerContext, arg string) string {
+ return fmt.Sprintf("method:%q,suffix:%q,arg:%q", ctx.Method(), ctx.Suffix(), arg)
+}
+
+type testServerAuthorizer struct{}
+
+func (testServerAuthorizer) Authorize(c security.Context) error {
+ return nil
+}
+
+type testServerDisp struct{ server interface{} }
+
+func (t testServerDisp) Lookup(suffix string) (interface{}, security.Authorizer, error) {
+ return t.server, testServerAuthorizer{}, nil
+}
+
+type proxyHandle struct {
+ ns naming.Namespace
+ sh *modules.Shell
+ proxy modules.Handle
+ name string
+}
+
+func (h *proxyHandle) Start(t *testing.T, ctx *context.T, args ...string) error {
+ sh, err := modules.NewShell(nil, nil)
+ if err != nil {
+ t.Fatalf("unexpected error: %s", err)
+ }
+ h.sh = sh
+ p, err := sh.Start(core.ProxyServerCommand, nil, args...)
+ if err != nil {
+ t.Fatalf("unexpected error: %s", err)
+ }
+ h.proxy = p
+ s := expect.NewSession(t, p.Stdout(), time.Minute)
+ s.ReadLine()
+ h.name = s.ExpectVar("PROXY_NAME")
+ if len(h.name) == 0 {
+ t.Fatalf("failed to get PROXY_NAME from proxyd")
+ }
+ return h.ns.Mount(ctx, "proxy", h.name, time.Hour)
+}
+
+func (h *proxyHandle) Stop(ctx *context.T) error {
+ defer h.sh.Cleanup(os.Stderr, os.Stderr)
+ if err := h.proxy.Shutdown(os.Stderr, os.Stderr); err != nil {
+ return err
+ }
+ if len(h.name) == 0 {
+ return nil
+ }
+ return h.ns.Unmount(ctx, "proxy", h.name)
+}
+
+func TestProxyOnly(t *testing.T) {
+ listenSpec := ipc.ListenSpec{Proxy: "proxy"}
+ testProxy(t, listenSpec)
+}
+
+func TestProxy(t *testing.T) {
+ proxyListenSpec := ipc.ListenSpec{Addrs: ipc.ListenAddrs{{"tcp", "127.0.0.1:0"}}}
+ proxyListenSpec.Proxy = "proxy"
+ testProxy(t, proxyListenSpec)
+}
+
+func TestWSProxy(t *testing.T) {
+ proxyListenSpec := ipc.ListenSpec{Addrs: ipc.ListenAddrs{{"tcp", "127.0.0.1:0"}}}
+ proxyListenSpec.Proxy = "proxy"
+ // The proxy uses websockets only, but the server is using tcp.
+ testProxy(t, proxyListenSpec, "--veyron.tcp.protocol=ws")
+}
+
+func testProxy(t *testing.T, spec ipc.ListenSpec, args ...string) {
+ sm := imanager.InternalNew(naming.FixedRoutingID(0x555555555))
+ defer sm.Shutdown()
+ ns := tnaming.NewSimpleNamespace()
+ client, err := iipc.InternalNewClient(sm, ns, vc.LocalPrincipal{tsecurity.NewPrincipal("client")})
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer client.Close()
+ ctx := testContext()
+ server, err := iipc.InternalNewServer(ctx, sm, ns, nil, vc.LocalPrincipal{tsecurity.NewPrincipal("server")})
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer server.Stop()
+
+ // If no address is specified then we'll only 'listen' via
+ // the proxy.
+ hasLocalListener := len(spec.Addrs) > 0 && len(spec.Addrs[0].Address) != 0
+
+ name := "mountpoint/server/suffix"
+ makeCall := func() (string, error) {
+ ctx, _ := context.WithDeadline(testContext(), time.Now().Add(5*time.Second))
+ // Let's fail fast so that the tests don't take as long to run.
+ call, err := client.StartCall(ctx, name, "Echo", []interface{}{"batman"})
+ if err != nil {
+ // proxy is down, we should return here/.... prepend
+ // the error with a well known string so that we can test for that.
+ return "", fmt.Errorf("RESOLVE: %s", err)
+ }
+ var result string
+ if err = call.Finish(&result); err != nil {
+ return "", err
+ }
+ return result, nil
+ }
+ proxy := &proxyHandle{ns: ns}
+ if err := proxy.Start(t, ctx, args...); err != nil {
+ t.Fatal(err)
+ }
+ defer proxy.Stop(ctx)
+ addrs := verifyMount(t, ctx, ns, spec.Proxy)
+ if len(addrs) != 1 {
+ t.Fatalf("failed to lookup proxy")
+ }
+
+ eps, err := server.Listen(spec)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := server.ServeDispatcher("mountpoint/server", testServerDisp{&testServer{}}); err != nil {
+ t.Fatal(err)
+ }
+
+ // Proxy connections are started asynchronously, so we need to wait..
+ waitForMountTable := func(ch chan int, expect int) {
+ then := time.Now().Add(time.Minute)
+ for {
+ me, err := ns.Resolve(ctx, name)
+ if err == nil && len(me.Servers) == expect {
+ ch <- 1
+ return
+ }
+ if time.Now().After(then) {
+ t.Fatalf("timed out")
+ }
+ time.Sleep(100 * time.Millisecond)
+ }
+ }
+ waitForServerStatus := func(ch chan int, proxy string) {
+ then := time.Now().Add(time.Minute)
+ for {
+ status := server.Status()
+ if len(status.Proxies) == 1 && status.Proxies[0].Proxy == proxy {
+ ch <- 2
+ return
+ }
+ if time.Now().After(then) {
+ t.Fatalf("timed out")
+ }
+ time.Sleep(100 * time.Millisecond)
+ }
+ }
+ proxyEP, _ := naming.SplitAddressName(addrs[0])
+ proxiedEP, err := inaming.NewEndpoint(proxyEP)
+ if err != nil {
+ t.Fatalf("unexpected error for %q: %s", proxyEP, err)
+ }
+ proxiedEP.RID = naming.FixedRoutingID(0x555555555)
+ expectedNames := []string{naming.JoinAddressName(proxiedEP.String(), "suffix")}
+ if hasLocalListener {
+ expectedNames = append(expectedNames, naming.JoinAddressName(eps[0].String(), "suffix"))
+ }
+
+ // Proxy connetions are created asynchronously, so we wait for the
+ // expected number of endpoints to appear for the specified service name.
+ ch := make(chan int, 2)
+ go waitForMountTable(ch, len(expectedNames))
+ go waitForServerStatus(ch, spec.Proxy)
+ select {
+ case <-time.After(time.Minute):
+ t.Fatalf("timedout waiting for two entries in the mount table and server status")
+ case i := <-ch:
+ select {
+ case <-time.After(time.Minute):
+ t.Fatalf("timedout waiting for two entries in the mount table or server status")
+ case j := <-ch:
+ if !((i == 1 && j == 2) || (i == 2 && j == 1)) {
+ t.Fatalf("unexpected return values from waiters")
+ }
+ }
+ }
+
+ status := server.Status()
+ if got, want := status.Proxies[0].Endpoint, proxiedEP; !reflect.DeepEqual(got, want) {
+ t.Fatalf("got %q, want %q", got, want)
+ }
+
+ got := []string{}
+ for _, s := range verifyMount(t, ctx, ns, name) {
+ got = append(got, s)
+ }
+ sort.Strings(got)
+ sort.Strings(expectedNames)
+ if !reflect.DeepEqual(got, expectedNames) {
+ t.Errorf("got %v, want %v", got, expectedNames)
+ }
+
+ if hasLocalListener {
+ // Listen will publish both the local and proxied endpoint with the
+ // mount table, given that we're trying to test the proxy, we remove
+ // the local endpoint from the mount table entry! We have to remove both
+ // the tcp and the websocket address.
+ sep := eps[0].String()
+ ns.Unmount(ctx, "mountpoint/server", sep)
+ }
+
+ addrs = verifyMount(t, ctx, ns, name)
+ if len(addrs) != 1 {
+ t.Fatalf("failed to lookup proxy: addrs %v", addrs)
+ }
+
+ // Proxied endpoint should be published and RPC should succeed (through proxy)
+ const expected = `method:"Echo",suffix:"suffix",arg:"batman"`
+ if result, err := makeCall(); result != expected || err != nil {
+ t.Fatalf("Got (%v, %v) want (%v, nil)", result, err, expected)
+ }
+ // Proxy dies, calls should fail and the name should be unmounted.
+ if err := proxy.Stop(ctx); err != nil {
+ t.Fatal(err)
+ }
+
+ if result, err := makeCall(); err == nil || (!strings.HasPrefix(err.Error(), "RESOLVE") && !strings.Contains(err.Error(), "EOF")) {
+ t.Fatalf(`Got (%v, %v) want ("", "RESOLVE: <err>" or "EOF") as proxy is down`, result, err)
+ }
+
+ for {
+ if _, err := ns.Resolve(ctx, name); err != nil {
+ break
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ verifyMountMissing(t, ctx, ns, name)
+
+ status = server.Status()
+ if len(status.Proxies) != 1 || status.Proxies[0].Proxy != spec.Proxy || !verror.Is(status.Proxies[0].Error, verror.NoServers.ID) {
+ t.Fatalf("proxy status is incorrect: %v", status.Proxies)
+ }
+
+ // Proxy restarts, calls should eventually start succeeding.
+ if err := proxy.Start(t, ctx, args...); err != nil {
+ t.Fatal(err)
+ }
+
+ retries := 0
+ for {
+ if result, err := makeCall(); err == nil {
+ if result != expected {
+ t.Errorf("Got (%v, %v) want (%v, nil)", result, err, expected)
+ }
+ break
+ } else {
+ retries++
+ if retries > 10 {
+ t.Fatalf("Failed after 10 attempts: err: %s", err)
+ }
+ }
+ }
+}
+
+func verifyMount(t *testing.T, ctx *context.T, ns naming.Namespace, name string) []string {
+ me, err := ns.Resolve(ctx, name)
+ if err != nil {
+ t.Errorf("%s not found in mounttable", name)
+ return nil
+ }
+ return me.Names()
+}
+
+func verifyMountMissing(t *testing.T, ctx *context.T, ns naming.Namespace, name string) {
+ if me, err := ns.Resolve(ctx, name); err == nil {
+ names := me.Names()
+ t.Errorf("%s not supposed to be found in mounttable; got %d servers instead: %v", name, len(names), names)
+ }
+}
+
+func TestHelperProcess(t *testing.T) {
+ modules.DispatchInTest()
+}
diff --git a/runtimes/google/ipc/resolve_test.go b/runtimes/google/ipc/resolve_test.go
index ece505c..d7b5261 100644
--- a/runtimes/google/ipc/resolve_test.go
+++ b/runtimes/google/ipc/resolve_test.go
@@ -17,7 +17,7 @@
)
func startMT(t *testing.T, sh *modules.Shell) string {
- h, err := sh.Start(core.RootMTCommand, nil, "--", "--veyron.tcp.address=127.0.0.1:0")
+ h, err := sh.Start(core.RootMTCommand, nil, "--veyron.tcp.address=127.0.0.1:0")
if err != nil {
t.Fatalf("unexpected error for root mt: %s", err)
}
diff --git a/runtimes/google/ipc/results_store_test.go b/runtimes/google/ipc/results_store_test.go
index 5c31331..c41bdec 100644
--- a/runtimes/google/ipc/results_store_test.go
+++ b/runtimes/google/ipc/results_store_test.go
@@ -8,8 +8,6 @@
"v.io/core/veyron/lib/testutil"
)
-func init() { testutil.Init() }
-
func randomKeys() []uint64 {
n := (testutil.Rand.Intn(256*10) / 10) + 256
k := make([]uint64, n)
diff --git a/runtimes/google/ipc/server_test.go b/runtimes/google/ipc/server_test.go
index d83367a..728a4bf 100644
--- a/runtimes/google/ipc/server_test.go
+++ b/runtimes/google/ipc/server_test.go
@@ -1,12 +1,9 @@
package ipc
import (
- "fmt"
"net"
- "os"
"reflect"
"sort"
- "strings"
"testing"
"time"
@@ -18,9 +15,6 @@
verror "v.io/core/veyron2/verror2"
"v.io/core/veyron2/vlog"
- "v.io/core/veyron/lib/expect"
- "v.io/core/veyron/lib/modules"
- "v.io/core/veyron/lib/modules/core"
"v.io/core/veyron/lib/netstate"
tsecurity "v.io/core/veyron/lib/testutil/security"
imanager "v.io/core/veyron/runtimes/google/ipc/stream/manager"
@@ -90,252 +84,6 @@
}
}
-type proxyHandle struct {
- ns naming.Namespace
- sh *modules.Shell
- proxy modules.Handle
- name string
-}
-
-func (h *proxyHandle) Start(t *testing.T, args ...string) error {
- sh, err := modules.NewShell(nil, nil)
- if err != nil {
- t.Fatalf("unexpected error: %s", err)
- }
- h.sh = sh
- p, err := sh.Start(core.ProxyServerCommand, nil, args...)
- if err != nil {
- t.Fatalf("unexpected error: %s", err)
- }
- h.proxy = p
- s := expect.NewSession(t, p.Stdout(), time.Minute)
- s.ReadLine()
- h.name = s.ExpectVar("PROXY_NAME")
- if len(h.name) == 0 {
- t.Fatalf("failed to get PROXY_NAME from proxyd")
- }
- return h.ns.Mount(testContext(), "proxy", h.name, time.Hour)
-}
-
-func (h *proxyHandle) Stop() error {
- defer h.sh.Cleanup(os.Stderr, os.Stderr)
- if err := h.proxy.Shutdown(os.Stderr, os.Stderr); err != nil {
- return err
- }
- if len(h.name) == 0 {
- return nil
- }
- return h.ns.Unmount(testContext(), "proxy", h.name)
-}
-
-func TestProxyOnly(t *testing.T) {
- listenSpec := ipc.ListenSpec{Proxy: "proxy"}
- testProxy(t, listenSpec, "--", "--veyron.tcp.address=127.0.0.1:0")
-}
-
-func TestProxy(t *testing.T) {
- proxyListenSpec := listenSpec
- proxyListenSpec.Proxy = "proxy"
- testProxy(t, proxyListenSpec, "--", "--veyron.tcp.address=127.0.0.1:0")
-}
-
-func TestWSProxy(t *testing.T) {
- proxyListenSpec := listenSpec
- proxyListenSpec.Proxy = "proxy"
- // The proxy uses websockets only, but the server is using tcp.
- testProxy(t, proxyListenSpec, "--", "--veyron.tcp.protocol=ws", "--veyron.tcp.address=127.0.0.1:0")
-}
-
-func testProxy(t *testing.T, spec ipc.ListenSpec, args ...string) {
- sm := imanager.InternalNew(naming.FixedRoutingID(0x555555555))
- defer sm.Shutdown()
- ns := tnaming.NewSimpleNamespace()
- client, err := InternalNewClient(sm, ns, vc.LocalPrincipal{tsecurity.NewPrincipal("client")})
- if err != nil {
- t.Fatal(err)
- }
- defer client.Close()
- ctx := testContext()
- server, err := testInternalNewServer(ctx, sm, ns, vc.LocalPrincipal{tsecurity.NewPrincipal("server")})
- if err != nil {
- t.Fatal(err)
- }
- defer server.Stop()
-
- // If no address is specified then we'll only 'listen' via
- // the proxy.
- hasLocalListener := len(spec.Addrs) > 0 && len(spec.Addrs[0].Address) != 0
-
- name := "mountpoint/server/suffix"
- makeCall := func() (string, error) {
- ctx, _ := context.WithDeadline(testContext(), time.Now().Add(5*time.Second))
- // Let's fail fast so that the tests don't take as long to run.
- call, err := client.StartCall(ctx, name, "Echo", []interface{}{"batman"})
- if err != nil {
- // proxy is down, we should return here/.... prepend
- // the error with a well known string so that we can test for that.
- return "", fmt.Errorf("RESOLVE: %s", err)
- }
- var result string
- if err = call.Finish(&result); err != nil {
- return "", err
- }
- return result, nil
- }
- proxy := &proxyHandle{ns: ns}
- if err := proxy.Start(t, args...); err != nil {
- t.Fatal(err)
- }
- defer proxy.Stop()
- addrs := verifyMount(t, ns, spec.Proxy)
- if len(addrs) != 1 {
- t.Fatalf("failed to lookup proxy")
- }
-
- eps, err := server.Listen(spec)
- if err != nil {
- t.Fatal(err)
- }
- if err := server.ServeDispatcher("mountpoint/server", testServerDisp{&testServer{}}); err != nil {
- t.Fatal(err)
- }
-
- // Proxy connections are started asynchronously, so we need to wait..
- waitForMountTable := func(ch chan int, expect int) {
- then := time.Now().Add(time.Minute)
- for {
- me, err := ns.Resolve(testContext(), name)
- if err == nil && len(me.Servers) == expect {
- ch <- 1
- return
- }
- if time.Now().After(then) {
- t.Fatalf("timed out")
- }
- time.Sleep(100 * time.Millisecond)
- }
- }
- waitForServerStatus := func(ch chan int, proxy string) {
- then := time.Now().Add(time.Minute)
- for {
- status := server.Status()
- if len(status.Proxies) == 1 && status.Proxies[0].Proxy == proxy {
- ch <- 2
- return
- }
- if time.Now().After(then) {
- t.Fatalf("timed out")
- }
- time.Sleep(100 * time.Millisecond)
- }
- }
- proxyEP, _ := naming.SplitAddressName(addrs[0])
- proxiedEP, err := inaming.NewEndpoint(proxyEP)
- if err != nil {
- t.Fatalf("unexpected error for %q: %s", proxyEP, err)
- }
- proxiedEP.RID = naming.FixedRoutingID(0x555555555)
- expectedNames := []string{naming.JoinAddressName(proxiedEP.String(), "suffix")}
- if hasLocalListener {
- expectedNames = append(expectedNames, naming.JoinAddressName(eps[0].String(), "suffix"))
- }
-
- // Proxy connetions are created asynchronously, so we wait for the
- // expected number of endpoints to appear for the specified service name.
- ch := make(chan int, 2)
- go waitForMountTable(ch, len(expectedNames))
- go waitForServerStatus(ch, spec.Proxy)
- select {
- case <-time.After(time.Minute):
- t.Fatalf("timedout waiting for two entries in the mount table and server status")
- case i := <-ch:
- select {
- case <-time.After(time.Minute):
- t.Fatalf("timedout waiting for two entries in the mount table or server status")
- case j := <-ch:
- if !((i == 1 && j == 2) || (i == 2 && j == 1)) {
- t.Fatalf("unexpected return values from waiters")
- }
- }
- }
-
- status := server.Status()
- if got, want := status.Proxies[0].Endpoint, proxiedEP; !reflect.DeepEqual(got, want) {
- t.Fatalf("got %q, want %q", got, want)
- }
-
- got := []string{}
- for _, s := range verifyMount(t, ns, name) {
- got = append(got, s)
- }
- sort.Strings(got)
- sort.Strings(expectedNames)
- if !reflect.DeepEqual(got, expectedNames) {
- t.Errorf("got %v, want %v", got, expectedNames)
- }
-
- if hasLocalListener {
- // Listen will publish both the local and proxied endpoint with the
- // mount table, given that we're trying to test the proxy, we remove
- // the local endpoint from the mount table entry! We have to remove both
- // the tcp and the websocket address.
- sep := eps[0].String()
- ns.Unmount(testContext(), "mountpoint/server", sep)
- }
-
- addrs = verifyMount(t, ns, name)
- if len(addrs) != 1 {
- t.Fatalf("failed to lookup proxy: addrs %v", addrs)
- }
-
- // Proxied endpoint should be published and RPC should succeed (through proxy)
- const expected = `method:"Echo",suffix:"suffix",arg:"batman"`
- if result, err := makeCall(); result != expected || err != nil {
- t.Fatalf("Got (%v, %v) want (%v, nil)", result, err, expected)
- }
- // Proxy dies, calls should fail and the name should be unmounted.
- if err := proxy.Stop(); err != nil {
- t.Fatal(err)
- }
-
- if result, err := makeCall(); err == nil || (!strings.HasPrefix(err.Error(), "RESOLVE") && !strings.Contains(err.Error(), "EOF")) {
- t.Fatalf(`Got (%v, %v) want ("", "RESOLVE: <err>" or "EOF") as proxy is down`, result, err)
- }
-
- for {
- if _, err := ns.Resolve(testContext(), name); err != nil {
- break
- }
- time.Sleep(10 * time.Millisecond)
- }
- verifyMountMissing(t, ns, name)
-
- status = server.Status()
- if len(status.Proxies) != 1 || status.Proxies[0].Proxy != spec.Proxy || !verror.Is(status.Proxies[0].Error, verror.NoServers.ID) {
- t.Fatalf("proxy status is incorrect: %v", status.Proxies)
- }
-
- // Proxy restarts, calls should eventually start succeeding.
- if err := proxy.Start(t, args...); err != nil {
- t.Fatal(err)
- }
-
- retries := 0
- for {
- if result, err := makeCall(); err == nil {
- if result != expected {
- t.Errorf("Got (%v, %v) want (%v, nil)", result, err, expected)
- }
- break
- } else {
- retries++
- if retries > 10 {
- t.Fatalf("Failed after 10 attempts: err: %s", err)
- }
- }
- }
-}
-
func TestServerArgs(t *testing.T) {
sm := imanager.InternalNew(naming.FixedRoutingID(0x555555555))
defer sm.Shutdown()
@@ -382,11 +130,12 @@
}
func TestServerStatus(t *testing.T) {
+ ctx := testContext()
sm := imanager.InternalNew(naming.FixedRoutingID(0x555555555))
defer sm.Shutdown()
ns := tnaming.NewSimpleNamespace()
principal := vc.LocalPrincipal{tsecurity.NewPrincipal("testServerStatus")}
- server, err := testInternalNewServer(testContext(), sm, ns, principal)
+ server, err := testInternalNewServer(ctx, sm, ns, principal)
if err != nil {
t.Fatal(err)
}
@@ -414,12 +163,12 @@
progress := make(chan error)
client, err := InternalNewClient(sm, ns, principal)
- makeCall := func() {
- call, err := client.StartCall(testContext(), "test", "Hang", nil)
+ makeCall := func(ctx *context.T) {
+ call, err := client.StartCall(ctx, "test", "Hang", nil)
progress <- err
progress <- call.Finish()
}
- go makeCall()
+ go makeCall(ctx)
// Wait for RPC to start
if err := <-progress; err != nil {
@@ -473,6 +222,7 @@
sm := imanager.InternalNew(naming.FixedRoutingID(0x555555555))
defer sm.Shutdown()
ns := tnaming.NewSimpleNamespace()
+ ctx := testContext()
expectBadState := func(err error) {
if !verror.Is(err, verror.BadState.ID) {
@@ -486,7 +236,7 @@
}
}
- server, err := testInternalNewServer(testContext(), sm, ns)
+ server, err := testInternalNewServer(ctx, sm, ns)
expectNoError(err)
defer server.Stop()
@@ -873,8 +623,3 @@
}
}
-
-// Required by modules framework.
-func TestHelperProcess(t *testing.T) {
- modules.DispatchInTest()
-}
diff --git a/runtimes/google/ipc/signature_test.go b/runtimes/google/ipc/signature_test.go
index bd54d06..7dcc056 100644
--- a/runtimes/google/ipc/signature_test.go
+++ b/runtimes/google/ipc/signature_test.go
@@ -17,8 +17,6 @@
_ "v.io/core/veyron/profiles"
)
-func init() { testutil.Init() }
-
func startSigServer(ctx *context.T, sig sigImpl) (string, func(), error) {
server, err := veyron2.NewServer(ctx)
if err != nil {
diff --git a/runtimes/google/ipc/stream/manager/manager_test.go b/runtimes/google/ipc/stream/manager/manager_test.go
index e1fb7b4..861b3f4 100644
--- a/runtimes/google/ipc/stream/manager/manager_test.go
+++ b/runtimes/google/ipc/stream/manager/manager_test.go
@@ -555,7 +555,7 @@
func runServer(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
server := InternalNew(naming.FixedRoutingID(0x55555555))
- _, ep, err := server.Listen(args[1], args[2])
+ _, ep, err := server.Listen(args[0], args[1])
if err != nil {
fmt.Fprintln(stderr, err)
return err
diff --git a/runtimes/google/ipc/stream/proxy/proxy_test.go b/runtimes/google/ipc/stream/proxy/proxy_test.go
index 8fd3b8c..9d23ab4 100644
--- a/runtimes/google/ipc/stream/proxy/proxy_test.go
+++ b/runtimes/google/ipc/stream/proxy/proxy_test.go
@@ -4,6 +4,7 @@
"bytes"
"fmt"
"io"
+ "os"
"reflect"
"strings"
"testing"
@@ -19,7 +20,10 @@
"v.io/core/veyron/runtimes/google/ipc/stream/vc"
)
-func init() { testutil.Init() }
+func TestMain(m *testing.M) {
+ testutil.Init()
+ os.Exit(m.Run())
+}
func TestProxy(t *testing.T) {
proxy, err := proxy.New(naming.FixedRoutingID(0xbbbbbbbbbbbbbbbb), nil, "tcp", "127.0.0.1:0", "")
diff --git a/runtimes/google/ipc/stream/vc/vc_test.go b/runtimes/google/ipc/stream/vc/vc_test.go
index aa6e129..05f4edd 100644
--- a/runtimes/google/ipc/stream/vc/vc_test.go
+++ b/runtimes/google/ipc/stream/vc/vc_test.go
@@ -7,6 +7,7 @@
"fmt"
"io"
"net"
+ "os"
"reflect"
"runtime"
"strings"
@@ -29,7 +30,10 @@
"v.io/core/veyron2/security"
)
-func init() { testutil.Init() }
+func TestMain(m *testing.M) {
+ testutil.Init()
+ os.Exit(m.Run())
+}
const (
// Convenience alias to avoid conflicts between the package name "vc" and variables called "vc".
diff --git a/runtimes/google/ipc/stream/vif/vif_test.go b/runtimes/google/ipc/stream/vif/vif_test.go
index 0ba3a12..232f985 100644
--- a/runtimes/google/ipc/stream/vif/vif_test.go
+++ b/runtimes/google/ipc/stream/vif/vif_test.go
@@ -9,6 +9,7 @@
"fmt"
"io"
"net"
+ "os"
"reflect"
"runtime"
"sort"
@@ -27,7 +28,10 @@
"v.io/core/veyron2/naming"
)
-func init() { testutil.Init() }
+func TestMain(m *testing.M) {
+ testutil.Init()
+ os.Exit(m.Run())
+}
func newPrincipal(defaultBlessing string) vc.LocalPrincipal {
return vc.LocalPrincipal{tsecurity.NewPrincipal("defaultBlessing")}
diff --git a/runtimes/google/ipc/testutil_test.go b/runtimes/google/ipc/testutil_test.go
index 1011dd6..01f9444 100644
--- a/runtimes/google/ipc/testutil_test.go
+++ b/runtimes/google/ipc/testutil_test.go
@@ -6,12 +6,8 @@
"v.io/core/veyron2/security"
"v.io/core/veyron2/verror2"
-
- "v.io/core/veyron/lib/testutil"
)
-func init() { testutil.Init() }
-
func makeResultPtrs(ins []interface{}) []interface{} {
outs := make([]interface{}, len(ins))
for ix, in := range ins {
diff --git a/runtimes/google/rt/rt_test.go b/runtimes/google/rt/rt_test.go
index aaebf45..0935d28 100644
--- a/runtimes/google/rt/rt_test.go
+++ b/runtimes/google/rt/rt_test.go
@@ -151,7 +151,7 @@
if err != nil {
return err
}
- if _, err := sh.Start("principal", nil, args[1:]...); err != nil {
+ if _, err := sh.Start("principal", nil, args...); err != nil {
return err
}
// Cleanup copies the output of sh to these Writers.
diff --git a/services/mgmt/application/impl/acl_test.go b/services/mgmt/application/impl/acl_test.go
index c16dd3f..aae2619 100644
--- a/services/mgmt/application/impl/acl_test.go
+++ b/services/mgmt/application/impl/acl_test.go
@@ -42,7 +42,6 @@
}
func appRepository(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- args = args[1:]
if len(args) < 2 {
vlog.Fatalf("repository expected at least name and store arguments and optionally ACL flags per TaggedACLMapFromFlag")
}
diff --git a/services/mgmt/binary/impl/acl_test.go b/services/mgmt/binary/impl/acl_test.go
index 67e468b..7f81a0f 100644
--- a/services/mgmt/binary/impl/acl_test.go
+++ b/services/mgmt/binary/impl/acl_test.go
@@ -40,7 +40,6 @@
}
func binaryd(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- args = args[1:]
if len(args) < 2 {
vlog.Fatalf("binaryd expected at least name and store arguments and optionally ACL flags per TaggedACLMapFromFlag")
}
diff --git a/services/mgmt/device/impl/impl_test.go b/services/mgmt/device/impl/impl_test.go
index 74e7291..79957c6 100644
--- a/services/mgmt/device/impl/impl_test.go
+++ b/services/mgmt/device/impl/impl_test.go
@@ -79,13 +79,17 @@
modules.RegisterChild(execScriptCmd, "", execScript)
modules.RegisterChild(deviceManagerCmd, "", deviceManager)
modules.RegisterChild(appCmd, "", app)
- testutil.Init()
if modules.IsModulesProcess() {
return
}
}
+func TestMain(m *testing.M) {
+ testutil.Init()
+ os.Exit(m.Run())
+}
+
// TestHelperProcess is the entrypoint for the modules commands in a
// a test subprocess.
func TestHelperProcess(t *testing.T) {
@@ -107,7 +111,6 @@
// execScript launches the script passed as argument.
func execScript(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- args = args[1:]
if want, got := 1, len(args); want != got {
vlog.Fatalf("execScript expected %d arguments, got %d instead", want, got)
}
@@ -134,7 +137,6 @@
func deviceManager(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
ctx, shutdown := testutil.InitForTest()
- args = args[1:]
if len(args) == 0 {
vlog.Fatalf("deviceManager expected at least an argument")
}
@@ -257,7 +259,6 @@
veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
- args = args[1:]
if expected, got := 1, len(args); expected != got {
vlog.Fatalf("Unexpected number of arguments: expected %d, got %d", expected, got)
}
diff --git a/services/mgmt/lib/testutil/modules.go b/services/mgmt/lib/testutil/modules.go
index 23aa53e..dcfecf4 100644
--- a/services/mgmt/lib/testutil/modules.go
+++ b/services/mgmt/lib/testutil/modules.go
@@ -31,7 +31,7 @@
// StartRootMT sets up a root mount table for tests.
func StartRootMT(t *testing.T, sh *modules.Shell) (string, modules.Handle) {
- h, err := sh.Start(core.RootMTCommand, nil, "--", "--veyron.tcp.address=127.0.0.1:0")
+ h, err := sh.Start(core.RootMTCommand, nil, "--veyron.tcp.address=127.0.0.1:0")
if err != nil {
t.Fatalf("failed to start root mount table: %s", err)
}
diff --git a/tools/naming/simulator/shell_functions.go b/tools/naming/simulator/shell_functions.go
index 552635b..5a8f899 100644
--- a/tools/naming/simulator/shell_functions.go
+++ b/tools/naming/simulator/shell_functions.go
@@ -43,11 +43,11 @@
}
func mountServer(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- if err := checkArgs(args[1:], -3, "<mount point> <server> <ttl> [M][R]"); err != nil {
+ if err := checkArgs(args, -3, "<mount point> <server> <ttl> [M][R]"); err != nil {
return err
}
var opts []naming.MountOpt
- for _, arg := range args[4:] {
+ for _, arg := range args[3:] {
for _, c := range arg {
switch c {
case 'R':
@@ -57,7 +57,7 @@
}
}
}
- mp, server, ttlstr := args[1], args[2], args[3]
+ mp, server, ttlstr := args[0], args[1], args[2]
ttl, err := time.ParseDuration(ttlstr)
if err != nil {
return fmt.Errorf("failed to parse time from %q", ttlstr)
@@ -71,7 +71,7 @@
}
func namespaceCache(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- if err := checkArgs(args[1:], 1, "on|off"); err != nil {
+ if err := checkArgs(args, 1, "on|off"); err != nil {
return err
}
disable := true
@@ -90,10 +90,10 @@
type resolver func(ctx *context.T, name string, opts ...naming.ResolveOpt) (me *naming.MountEntry, err error)
func resolve(fn resolver, stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- if err := checkArgs(args[1:], 1, "<name>"); err != nil {
+ if err := checkArgs(args, 1, "<name>"); err != nil {
return err
}
- name := args[1]
+ name := args[0]
me, err := fn(ctx, name)
if err != nil {
fmt.Fprintf(stdout, "RN=0\n")
diff --git a/tools/servicerunner/main.go b/tools/servicerunner/main.go
index 3e0b345..0631399 100644
--- a/tools/servicerunner/main.go
+++ b/tools/servicerunner/main.go
@@ -55,19 +55,12 @@
}
func main() {
- ctx, shutdown := veyron2.Init()
-
if modules.IsModulesProcess() {
- // TODO(suharshs): This is a hack and we should find a better way to parse flags in the modules.
- // This is needed because the modules commands call veyron2.Init and multiple runtimes cannot
- // be initialized simultaneously.
- // In addition the modules read their args from flag.Args() (all flags after "--") which means
- // the flags must still be parsed before calling modules.Dispatch(). Thus moving veyron2.Init
- // below this clause solves nothing.
- shutdown()
panicOnError(modules.Dispatch())
return
}
+
+ ctx, shutdown := veyron2.Init()
defer shutdown()
vars := map[string]string{}
@@ -78,7 +71,7 @@
}
defer sh.Cleanup(os.Stderr, os.Stderr)
- h, err := sh.Start(core.RootMTCommand, nil, "--", "--veyron.tcp.protocol=ws", "--veyron.tcp.address=127.0.0.1:0")
+ h, err := sh.Start(core.RootMTCommand, nil, "--veyron.tcp.protocol=ws", "--veyron.tcp.address=127.0.0.1:0")
panicOnError(err)
panicOnError(updateVars(h, vars, "MT_NAME"))
@@ -90,15 +83,15 @@
// NOTE(sadovsky): The proxyd binary requires --protocol and --address flags
// while the proxyd command instead uses ListenSpec flags.
- h, err = sh.Start(core.ProxyServerCommand, nil, "--", "--veyron.tcp.protocol=ws", "--veyron.tcp.address=127.0.0.1:0", "test/proxy")
+ h, err = sh.Start(core.ProxyServerCommand, nil, "--veyron.tcp.protocol=ws", "--veyron.tcp.address=127.0.0.1:0", "test/proxy")
panicOnError(err)
panicOnError(updateVars(h, vars, "PROXY_NAME"))
- h, err = sh.Start(core.WSPRCommand, nil, "--", "--veyron.tcp.protocol=ws", "--veyron.tcp.address=127.0.0.1:0", "--veyron.proxy=test/proxy", "--identd=test/identd")
+ h, err = sh.Start(core.WSPRCommand, nil, "--veyron.tcp.protocol=ws", "--veyron.tcp.address=127.0.0.1:0", "--veyron.proxy=test/proxy", "--identd=test/identd")
panicOnError(err)
panicOnError(updateVars(h, vars, "WSPR_ADDR"))
- h, err = sh.Start(core.TestIdentitydCommand, nil, "--", "--veyron.tcp.protocol=ws", "--veyron.tcp.address=127.0.0.1:0", "--veyron.proxy=test/proxy", "--host=localhost", "--httpaddr=localhost:0")
+ h, err = sh.Start(core.TestIdentitydCommand, nil, "--veyron.tcp.protocol=ws", "--veyron.tcp.address=127.0.0.1:0", "--veyron.proxy=test/proxy", "--host=localhost", "--httpaddr=localhost:0")
panicOnError(err)
panicOnError(updateVars(h, vars, "TEST_IDENTITYD_NAME", "TEST_IDENTITYD_HTTP_ADDR"))