core: Change rt.New to veyron2.Init.
Change-Id: Ibdc54c066442f09a12225d7f91a2f933edcdf628
diff --git a/lib/modules/core/core_test.go b/lib/modules/core/core_test.go
index 64eeabb..e5071c2 100644
--- a/lib/modules/core/core_test.go
+++ b/lib/modules/core/core_test.go
@@ -10,6 +10,7 @@
"testing"
"time"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/expect"
@@ -18,7 +19,6 @@
"v.io/core/veyron/lib/modules/core"
"v.io/core/veyron/lib/testutil"
_ "v.io/core/veyron/profiles"
- "v.io/core/veyron2/rt"
)
func TestCommands(t *testing.T) {
@@ -38,11 +38,9 @@
// TODO(cnicolaou): add test for proxyd
func newShell(t *testing.T) (*modules.Shell, func()) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -53,7 +51,7 @@
} else {
sh.Cleanup(nil, nil)
}
- runtime.Cleanup()
+ shutdown()
}
}
diff --git a/lib/modules/core/echo.go b/lib/modules/core/echo.go
index 34c11b8..92160b9 100644
--- a/lib/modules/core/echo.go
+++ b/lib/modules/core/echo.go
@@ -8,7 +8,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/ipc"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron/lib/modules"
@@ -48,12 +47,8 @@
}
func echoServer(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
fl, args, err := parseListenFlags(args)
if err != nil {
@@ -85,12 +80,8 @@
}
func echoClient(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
args = args[1:]
name := args[0]
diff --git a/lib/modules/core/mounttable.go b/lib/modules/core/mounttable.go
index b549b65..6046c91 100644
--- a/lib/modules/core/mounttable.go
+++ b/lib/modules/core/mounttable.go
@@ -8,7 +8,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron/lib/modules"
mounttable "v.io/core/veyron/services/mounttable/lib"
@@ -32,12 +31,8 @@
}
func runMT(root bool, stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- r, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer r.Cleanup()
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
fl, args, err := parseListenFlags(args)
if err != nil {
@@ -75,13 +70,8 @@
}
func ls(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- r, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer r.Cleanup()
-
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
details := false
args = args[1:] // skip over command name
diff --git a/lib/modules/core/proxy.go b/lib/modules/core/proxy.go
index 00d1977..f137cf8 100644
--- a/lib/modules/core/proxy.go
+++ b/lib/modules/core/proxy.go
@@ -8,7 +8,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron/lib/modules"
"v.io/core/veyron/runtimes/google/ipc/stream/proxy"
@@ -20,11 +19,8 @@
}
func proxyServer(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- r, err := rt.New()
- if err != nil {
- panic(err)
- }
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
fl, args, err := parseListenFlags(args)
if err != nil {
@@ -46,7 +42,6 @@
fmt.Fprintf(stdout, "PID=%d\n", os.Getpid())
fmt.Fprintf(stdout, "PROXY_NAME=%s\n", proxy.Endpoint().Name())
if expected > 0 {
- defer r.Cleanup()
pub := publisher.New(ctx, veyron2.GetNamespace(ctx), time.Minute)
defer pub.WaitForStop()
defer pub.Stop()
diff --git a/lib/modules/core/test_identityd.go b/lib/modules/core/test_identityd.go
index 8951102..f1bc19a 100644
--- a/lib/modules/core/test_identityd.go
+++ b/lib/modules/core/test_identityd.go
@@ -8,7 +8,7 @@
"strconv"
"time"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/modules"
@@ -87,12 +87,9 @@
caveats.NewMockCaveatSelector())
l := initListenSpec(ifl)
- r, err := rt.New()
- if err != nil {
- return fmt.Errorf("rt.New() failed: %v", err)
- }
- defer r.Cleanup()
- ctx := r.NewContext()
+
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
_, veyronEPs, externalHttpaddress := s.Listen(ctx, &l, *host, *httpaddr, *tlsconfig)
diff --git a/lib/modules/examples_test.go b/lib/modules/examples_test.go
index ee78224..2784a03 100644
--- a/lib/modules/examples_test.go
+++ b/lib/modules/examples_test.go
@@ -6,6 +6,7 @@
"os"
"v.io/core/veyron/lib/modules"
+ "v.io/core/veyron2"
)
func init() {
@@ -20,6 +21,8 @@
}
func ExampleDispatch() {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
if modules.IsModulesProcess() {
// Child process. Dispatch will invoke the 'echo' command
if err := modules.Dispatch(); err != nil {
@@ -28,7 +31,7 @@
return
}
// Parent process.
- sh, _ := modules.NewShell(runtime.NewContext(), nil)
+ sh, _ := modules.NewShell(ctx, nil)
defer sh.Cleanup(nil, nil)
h, _ := sh.Start("echo", nil, "a", "b")
h.Shutdown(os.Stdout, os.Stderr)
@@ -39,9 +42,11 @@
}
func ExampleDispatchAndExit() {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
// DispatchAndExit will call os.Exit(0) when executed within the child.
modules.DispatchAndExit()
- sh, _ := modules.NewShell(runtime.NewContext(), nil)
+ sh, _ := modules.NewShell(ctx, nil)
defer sh.Cleanup(nil, nil)
h, _ := sh.Start("echo", nil, "c", "d")
h.Shutdown(os.Stdout, os.Stderr)
diff --git a/lib/modules/modules_internal_test.go b/lib/modules/modules_internal_test.go
index 3c26937..d3f9328 100644
--- a/lib/modules/modules_internal_test.go
+++ b/lib/modules/modules_internal_test.go
@@ -9,7 +9,7 @@
_ "v.io/core/veyron/profiles"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
)
func Echo(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
@@ -30,12 +30,10 @@
}
func TestState(t *testing.T) {
- r, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer r.Cleanup()
- sh, err := NewShell(r.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
diff --git a/lib/modules/modules_test.go b/lib/modules/modules_test.go
index 1f4e311..b92a696 100644
--- a/lib/modules/modules_test.go
+++ b/lib/modules/modules_test.go
@@ -21,13 +21,10 @@
_ "v.io/core/veyron/profiles"
"v.io/core/veyron2"
- "v.io/core/veyron2/rt"
)
const credentialsEnvPrefix = "\"" + consts.VeyronCredentials + "="
-var runtime veyron2.Runtime
-
func init() {
testutil.Init()
modules.RegisterChild("envtest", "envtest: <variables to print>...", PrintFromEnv)
@@ -40,11 +37,6 @@
modules.RegisterFunction("envtestf", "envtest: <variables to print>...", PrintFromEnv)
modules.RegisterFunction("echof", "[args]*", Echo)
modules.RegisterFunction("errortestFunc", "", ErrorMain)
- var err error
- runtime, err = rt.New()
- if err != nil {
- panic(err)
- }
}
func ignoresStdin(io.Reader, io.Writer, io.Writer, map[string]string, ...string) error {
@@ -61,7 +53,10 @@
}
func PrintBlessing(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- blessing := veyron2.GetPrincipal(runtime.NewContext()).BlessingStore().Default()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ blessing := veyron2.GetPrincipal(ctx).BlessingStore().Default()
fmt.Fprintf(stdout, "%s", blessing)
return nil
}
@@ -159,7 +154,10 @@
}
func TestChild(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -170,7 +168,10 @@
}
func TestAgent(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -180,7 +181,7 @@
if a != b {
t.Errorf("Expected same blessing for children, got %s and %s", a, b)
}
- sh2, err := modules.NewShell(runtime.NewContext(), nil)
+ sh2, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -192,9 +193,12 @@
}
func TestCustomPrincipal(t *testing.T) {
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
p := security.NewPrincipal("myshell")
cleanDebug := p.BlessingStore().DebugString()
- sh, err := modules.NewShell(runtime.NewContext(), p)
+ sh, err := modules.NewShell(ctx, p)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -224,7 +228,10 @@
}
func TestChildNoRegistration(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -239,7 +246,10 @@
}
func TestFunction(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -250,7 +260,10 @@
}
func TestErrorChild(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -290,7 +303,10 @@
}
func TestShutdownSubprocess(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -302,7 +318,10 @@
// forever if a child does not die upon closing stdin; but instead times out and
// returns an appropriate error.
func TestShutdownSubprocessIgnoresStdin(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -327,7 +346,10 @@
// implementation inappropriately sets stdout to the file that is to be closed
// in Wait.
func TestStdoutRace(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -359,7 +381,10 @@
}
func TestShutdownFunction(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -368,7 +393,10 @@
}
func TestErrorFunc(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -392,7 +420,10 @@
}
func TestEnvelope(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -444,7 +475,10 @@
}
func TestEnvMerge(t *testing.T) {
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
diff --git a/lib/signals/signals_test.go b/lib/signals/signals_test.go
index 21d3430..83f3438 100644
--- a/lib/signals/signals_test.go
+++ b/lib/signals/signals_test.go
@@ -16,8 +16,8 @@
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/mgmt"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/appcycle"
+ "v.io/core/veyron2/vtrace"
"v.io/core/veyron/lib/expect"
"v.io/core/veyron/lib/modules"
@@ -54,19 +54,14 @@
}
func program(stdin io.Reader, stdout io.Writer, signals ...os.Signal) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
-
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
closeStopLoop := make(chan struct{})
go stopLoop(ctx, stdin, closeStopLoop)
wait := ShutdownOnSignals(ctx, signals...)
fmt.Fprintf(stdout, "ready\n")
fmt.Fprintf(stdout, "received signal %s\n", <-wait)
- runtime.Cleanup()
+ shutdown()
<-closeStopLoop
}
@@ -86,13 +81,8 @@
}
func handleDefaultsIgnoreChan(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
-
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
closeStopLoop := make(chan struct{})
go stopLoop(ctx, stdin, closeStopLoop)
@@ -123,8 +113,8 @@
}
}
-func newShell(t *testing.T, r veyron2.Runtime, command string) (*modules.Shell, modules.Handle, *expect.Session) {
- sh, err := modules.NewShell(r.NewContext(), nil)
+func newShell(t *testing.T, ctx *context.T, command string) (*modules.Shell, modules.Handle, *expect.Session) {
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -141,12 +131,10 @@
// TestCleanShutdownSignal verifies that sending a signal to a child that
// handles it by default causes the child to shut down cleanly.
func TestCleanShutdownSignal(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
checkSignalIsDefault(t, syscall.SIGINT)
@@ -159,12 +147,10 @@
// TestCleanShutdownStop verifies that sending a stop comamnd to a child that
// handles stop commands by default causes the child to shut down cleanly.
func TestCleanShutdownStop(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
fmt.Fprintf(h.Stdin(), "stop\n")
@@ -178,12 +164,10 @@
// that handles stop command as part of a custom set of signals handled, causes
// the child to shut down cleanly.
func TestCleanShutdownStopCustom(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleCustomWithStop")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleCustomWithStop")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
fmt.Fprintf(h.Stdin(), "stop\n")
@@ -204,12 +188,10 @@
// TestStopNoHandler verifies that sending a stop command to a child that does
// not handle stop commands causes the child to exit immediately.
func TestStopNoHandler(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleCustom")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleCustom")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
fmt.Fprintf(h.Stdin(), "stop\n")
@@ -220,12 +202,10 @@
// that handles these signals by default causes the child to exit immediately
// upon receiving the second signal.
func TestDoubleSignal(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
checkSignalIsDefault(t, syscall.SIGTERM)
@@ -240,12 +220,10 @@
// to a child that handles these by default causes the child to exit immediately
// upon receiving the stop command.
func TestSignalAndStop(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
checkSignalIsDefault(t, syscall.SIGTERM)
@@ -259,12 +237,10 @@
// that handles stop commands by default causes the child to exit immediately
// upon receiving the second stop command.
func TestDoubleStop(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
fmt.Fprintf(h.Stdin(), "stop\n")
@@ -276,12 +252,10 @@
// TestSendUnhandledSignal verifies that sending a signal that the child does
// not handle causes the child to exit as per the signal being sent.
func TestSendUnhandledSignal(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaults")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaults")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
checkSignalIsNotDefault(t, syscall.SIGABRT)
@@ -294,12 +268,10 @@
// process to exit (ensures that there is no dependency in ShutdownOnSignals
// on having a goroutine read from the returned channel).
func TestDoubleSignalIgnoreChan(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleDefaultsIgnoreChan")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleDefaultsIgnoreChan")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
// Even if we ignore the channel that ShutdownOnSignals returns,
@@ -314,12 +286,10 @@
// TestHandlerCustomSignal verifies that sending a non-default signal to a
// server that listens for that signal causes the server to shut down cleanly.
func TestHandlerCustomSignal(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- sh, h, s := newShell(t, runtime, "handleCustom")
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ sh, h, s := newShell(t, ctx, "handleCustom")
defer sh.Cleanup(os.Stderr, os.Stderr)
s.Expect("ready")
checkSignalIsNotDefault(t, syscall.SIGABRT)
@@ -333,13 +303,12 @@
// to a server that listens for that signal causes the server to shut down
// cleanly, even when a STOP signal is also among the handled signals.
func TestHandlerCustomSignalWithStop(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
for _, signal := range []syscall.Signal{syscall.SIGABRT, syscall.SIGHUP} {
- sh, h, s := newShell(t, runtime, "handleCustomWithStop")
+ ctx, _ := vtrace.SetNewTrace(rootCtx)
+ sh, h, s := newShell(t, ctx, "handleCustomWithStop")
s.Expect("ready")
checkSignalIsNotDefault(t, signal)
syscall.Kill(h.Pid(), signal)
@@ -395,14 +364,10 @@
// TestCleanRemoteShutdown verifies that remote shutdown works correctly.
func TestCleanRemoteShutdown(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- sh, err := modules.NewShell(runtime.NewContext(), nil)
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
diff --git a/lib/testutil/integration/util.go b/lib/testutil/integration/util.go
index 61de99d..335150d 100644
--- a/lib/testutil/integration/util.go
+++ b/lib/testutil/integration/util.go
@@ -40,8 +40,7 @@
"v.io/core/veyron/lib/modules"
"v.io/core/veyron/lib/modules/core"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/security"
)
@@ -132,6 +131,9 @@
// The testing framework.
t *testing.T
+ // The function to shutdown the context used to create the environment.
+ shutdown veyron2.Shutdown
+
// The shell to use to start commands.
shell *modules.Shell
@@ -261,6 +263,8 @@
}
func (e *integrationTestEnvironment) Cleanup() {
+ e.shutdown()
+
for _, binary := range e.builtBinaries {
binary.cleanupFunc()
}
@@ -397,13 +401,16 @@
// ...
// }
func NewTestEnvironment(t *testing.T) TestEnvironment {
+ ctx, shutdown := veyron2.Init()
+
t.Log("creating root principal")
principal := tsecurity.NewPrincipal("root")
- runtime, err := rt.New(options.RuntimePrincipal{principal})
+ ctx, err := veyron2.SetPrincipal(ctx, principal)
if err != nil {
- t.Fatalf("rt.New() failed: %v", err)
+ t.Fatalf("failed to set principal: %v", err)
}
- shell, err := modules.NewShell(runtime.NewContext(), principal)
+
+ shell, err := modules.NewShell(ctx, principal)
if err != nil {
t.Fatalf("NewShell() failed: %v", err)
}
@@ -424,6 +431,7 @@
mtEndpoint: mtEndpoint,
tempFiles: []*os.File{},
tempDirs: []string{},
+ shutdown: shutdown,
}
}
diff --git a/lib/testutil/security/util_test.go b/lib/testutil/security/util_test.go
index 2057f54..440533a 100644
--- a/lib/testutil/security/util_test.go
+++ b/lib/testutil/security/util_test.go
@@ -7,7 +7,6 @@
"sort"
"testing"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/security/access"
@@ -65,11 +64,6 @@
}
func TestSaveACLToFile(t *testing.T) {
- r, err := rt.New()
- if err != nil {
- t.Fatalf("rt.New failed: %v", err)
- }
- defer r.Cleanup()
acl := access.TaggedACLMap{
"Admin": access.ACL{
In: []security.BlessingPattern{"comics/..."},
diff --git a/profiles/roaming/net_watcher.go b/profiles/roaming/net_watcher.go
index 82348ea..607bcd4 100644
--- a/profiles/roaming/net_watcher.go
+++ b/profiles/roaming/net_watcher.go
@@ -8,21 +8,14 @@
"v.io/core/veyron2"
"v.io/core/veyron2/config"
- "v.io/core/veyron2/rt"
- "v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/netstate"
"v.io/core/veyron/profiles/roaming"
)
func main() {
- r, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer r.Cleanup()
-
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
profileName := veyron2.GetProfile(ctx).Name()
fmt.Println("Profile: ", profileName)
@@ -31,14 +24,15 @@
routes := netstate.GetRoutes()
fmt.Printf("Routes:\n%s\n", strings.Replace(routes.String(), ")", ")\n", -1))
- chooser := roaming.ListenSpec.AddressChooser
+ listenSpec := veyron2.GetListenSpec(ctx)
+ chooser := listenSpec.AddressChooser
if chooser != nil {
if gce, err := chooser("", nil); err == nil {
fmt.Printf("%s: 1:1 NAT address is %s\n", profileName, gce)
}
}
- if chosen, err := roaming.ListenSpec.AddressChooser("tcp", accessible); err != nil {
+ if chosen, err := listenSpec.AddressChooser("tcp", accessible); err != nil {
fmt.Printf("Failed to chosen address %s\n", err)
} else {
al := netstate.AddrList(chosen)
diff --git a/profiles/roaming/roaming_server.go b/profiles/roaming/roaming_server.go
index e49caa8..e85f22e 100644
--- a/profiles/roaming/roaming_server.go
+++ b/profiles/roaming/roaming_server.go
@@ -5,29 +5,26 @@
import (
"fmt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/ipc"
- "v.io/core/veyron2/rt"
- "v.io/core/veyron2/vlog"
"v.io/core/veyron/profiles/roaming"
)
func main() {
- r, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer r.Cleanup()
- log := r.Logger()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ log := veyron2.GetLogger(ctx)
- server, err := r.NewServer()
- defer server.Stop()
+ server, err := veyron2.NewServer(ctx)
if err != nil {
log.Fatalf("unexpected error: %q", err)
}
- fmt.Printf("listen spec: %v\n", roaming.ListenSpec)
- ep, err := server.Listen(roaming.ListenSpec)
+ listenSpec := veyron2.GetListenSpec(ctx)
+
+ fmt.Printf("listen spec: %v\n", listenSpec)
+ ep, err := server.Listen(listenSpec)
if err != nil {
log.Fatalf("unexpected error: %q", err)
}
diff --git a/runtimes/google/ipc/benchmark/benchmark_test.go b/runtimes/google/ipc/benchmark/benchmark_test.go
index b51ae42..f16eea1 100644
--- a/runtimes/google/ipc/benchmark/benchmark_test.go
+++ b/runtimes/google/ipc/benchmark/benchmark_test.go
@@ -6,7 +6,7 @@
"v.io/core/veyron/lib/testutil/benchmark"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron2"
"v.io/core/veyron2/context"
@@ -112,8 +112,7 @@
panic(err)
}
- var serverStop func()
- serverAddr, serverStop = StartServer(ctx, profiles.LocalListenSpec)
+ serverAddr, serverStop := StartServer(ctx, veyron2.GetListenSpec(ctx))
// Create a VC to exclude the VC setup time from the benchmark.
CallEcho(&testing.B{}, ctx, serverAddr, 1, 0, benchmark.NewStats(1))
diff --git a/runtimes/google/ipc/benchmark/bmclient/main.go b/runtimes/google/ipc/benchmark/bmclient/main.go
index e6fc5d3..f3145cf 100644
--- a/runtimes/google/ipc/benchmark/bmclient/main.go
+++ b/runtimes/google/ipc/benchmark/bmclient/main.go
@@ -12,7 +12,7 @@
_ "v.io/core/veyron/profiles"
"v.io/core/veyron/runtimes/google/ipc/benchmark"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
)
@@ -28,15 +28,12 @@
)
func main() {
- vrt, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer vrt.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
if *chunkCntMux > 0 && *payloadSizeMux > 0 {
dummyB := testing.B{}
- _, stop := benchmark.StartEchoStream(&dummyB, vrt.NewContext(), *server, 0, *chunkCntMux, *payloadSizeMux, nil)
+ _, stop := benchmark.StartEchoStream(&dummyB, ctx, *server, 0, *chunkCntMux, *payloadSizeMux, nil)
defer stop()
vlog.Infof("Started background streaming (chunk_size=%d, payload_size=%d)", *chunkCntMux, *payloadSizeMux)
}
@@ -45,7 +42,6 @@
stats := tbm.NewStats(16)
now := time.Now()
- ctx := vrt.NewContext()
if *chunkCnt == 0 {
benchmark.CallEcho(&dummyB, ctx, *server, *iterations, *payloadSize, stats)
} else {
diff --git a/runtimes/google/ipc/benchmark/bmserver/main.go b/runtimes/google/ipc/benchmark/bmserver/main.go
index 9c3fcd8..416762c 100644
--- a/runtimes/google/ipc/benchmark/bmserver/main.go
+++ b/runtimes/google/ipc/benchmark/bmserver/main.go
@@ -6,18 +6,13 @@
"v.io/core/veyron/profiles/roaming"
"v.io/core/veyron/runtimes/google/ipc/benchmark"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
)
func main() {
- vrt, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer vrt.Cleanup()
-
- ctx := vrt.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
addr, stop := benchmark.StartServer(ctx, roaming.ListenSpec)
vlog.Infof("Listening on %s", addr)
diff --git a/runtimes/google/ipc/benchmark/glob/glob_test.go b/runtimes/google/ipc/benchmark/glob/glob_test.go
index 951b16d..c8f1cf4 100644
--- a/runtimes/google/ipc/benchmark/glob/glob_test.go
+++ b/runtimes/google/ipc/benchmark/glob/glob_test.go
@@ -8,7 +8,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
tsecurity "v.io/core/veyron/lib/testutil/security"
@@ -156,15 +155,12 @@
}
func RunBenchmarkGlob(b *testing.B, obj interface{}) {
- runtime, err := rt.New()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
panic(err)
}
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
- panic(err)
- }
addr, stop, err := startServer(b, ctx, obj)
if err != nil {
diff --git a/runtimes/google/ipc/client_test.go b/runtimes/google/ipc/client_test.go
index 122abb2..d9ebb6a 100644
--- a/runtimes/google/ipc/client_test.go
+++ b/runtimes/google/ipc/client_test.go
@@ -13,8 +13,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
verror "v.io/core/veyron2/verror2"
"v.io/core/veyron2/vlog"
@@ -32,17 +30,14 @@
}
func newCtx() (*context.T, veyron2.Shutdown) {
- r, err := rt.New()
+ ctx, shutdown := veyron2.Init()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
panic(err)
}
- ctx := r.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
- panic(err)
- }
veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
- return ctx, r.Cleanup
+ return ctx, shutdown
}
func testArgs(args ...string) []string {
@@ -115,6 +110,7 @@
func TestMultipleEndpoints(t *testing.T) {
ctx, shutdown := newCtx()
defer shutdown()
+
sh, fn := runMountTable(t, ctx)
defer fn()
srv, err := sh.Start(core.EchoServerCommand, nil, testArgs("echoServer", "echoServer")...)
@@ -176,11 +172,8 @@
}
func childPing(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- r, err := rt.New()
- if err != nil {
- panic(err)
- }
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
name := args[1]
@@ -278,23 +271,19 @@
}
func TestAccessDenied(t *testing.T) {
- r1, _ := rt.New()
- r2, _ := rt.New()
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
- // The server and client use different runtimes and hence different
- // principals and without any shared blessings the server will deny
- // access to the client
- ctx1 := r1.NewContext()
- var err error
- if ctx1, err = veyron2.SetPrincipal(ctx1, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ ctx1, err := veyron2.SetPrincipal(rootCtx, tsecurity.NewPrincipal("test-blessing"))
+ if err != nil {
t.Fatal(err)
}
name, fn := initServer(t, ctx1)
defer fn()
- ctx2 := r2.NewContext()
- if ctx2, err = veyron2.SetPrincipal(ctx2, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ ctx2, err := veyron2.SetPrincipal(rootCtx, tsecurity.NewPrincipal("test-blessing"))
+ if err != nil {
t.Fatal(err)
}
client2 := veyron2.GetClient(ctx2)
@@ -506,12 +495,15 @@
// connection to the server if the server dies and comes back (on the same
// endpoint).
func TestReconnect(t *testing.T) {
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
principal := tsecurity.NewPrincipal("client")
- r, err := rt.New(options.RuntimePrincipal{principal})
+ ctx, err := veyron2.SetPrincipal(rootCtx, principal)
if err != nil {
- t.Fatalf("unexpected error: %s", err)
+ t.Fatal(err)
}
- sh, err := modules.NewShell(r.NewContext(), principal)
+ sh, err := modules.NewShell(ctx, principal)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -525,8 +517,9 @@
serverName := session.ExpectVar("NAME")
serverEP, _ := naming.SplitAddressName(serverName)
ep, _ := inaming.NewEndpoint(serverEP)
- makeCall := func() (string, error) {
- ctx, _ := context.WithDeadline(r.NewContext(), time.Now().Add(10*time.Second))
+
+ makeCall := func(ctx *context.T) (string, error) {
+ ctx, _ = context.WithDeadline(ctx, time.Now().Add(10*time.Second))
call, err := veyron2.GetClient(ctx).StartCall(ctx, serverName, "Echo", []interface{}{"bratman"})
if err != nil {
return "", fmt.Errorf("START: %s", err)
@@ -538,8 +531,9 @@
}
return result, nil
}
+
expected := "mymessage: bratman\n"
- if result, err := makeCall(); err != nil || result != expected {
+ if result, err := makeCall(ctx); err != nil || result != expected {
t.Errorf("Got (%q, %v) want (%q, nil)", result, err, expected)
}
// Kill the server, verify client can't talk to it anymore.
@@ -548,7 +542,7 @@
t.Fatalf("unexpected error: %s", err)
}
- if _, err := makeCall(); err == nil || (!strings.HasPrefix(err.Error(), "START") && !strings.Contains(err.Error(), "EOF")) {
+ if _, err := makeCall(ctx); err == nil || (!strings.HasPrefix(err.Error(), "START") && !strings.Contains(err.Error(), "EOF")) {
t.Fatalf(`Got (%v) want ("START: <err>" or "EOF") as server is down`, err)
}
@@ -562,7 +556,7 @@
session = expect.NewSession(t, server.Stdout(), time.Minute)
defer server.Shutdown(os.Stderr, os.Stderr)
expected = "mymessage again: bratman\n"
- if result, err := makeCall(); err != nil || result != expected {
+ if result, err := makeCall(ctx); err != nil || result != expected {
t.Errorf("Got (%q, %v) want (%q, nil)", result, err, expected)
}
diff --git a/runtimes/google/ipc/glob_test.go b/runtimes/google/ipc/glob_test.go
index 799a67e..cb50932 100644
--- a/runtimes/google/ipc/glob_test.go
+++ b/runtimes/google/ipc/glob_test.go
@@ -10,7 +10,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron/lib/glob"
@@ -36,13 +35,10 @@
}
func TestGlob(t *testing.T) {
- runtime, err := rt.New()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
diff --git a/runtimes/google/ipc/resolve_test.go b/runtimes/google/ipc/resolve_test.go
index 53dfdbc..1b22f21 100644
--- a/runtimes/google/ipc/resolve_test.go
+++ b/runtimes/google/ipc/resolve_test.go
@@ -7,7 +7,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron/lib/expect"
"v.io/core/veyron/lib/modules"
@@ -35,12 +34,8 @@
defer sh.Cleanup(nil, nil)
root := startMT(t, sh)
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("rt.New failed: %s", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
diff --git a/runtimes/google/ipc/signature_test.go b/runtimes/google/ipc/signature_test.go
index a0604c8..0f98e6a 100644
--- a/runtimes/google/ipc/signature_test.go
+++ b/runtimes/google/ipc/signature_test.go
@@ -10,7 +10,6 @@
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/ipc/reserved"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vdl"
"v.io/core/veyron2/vdl/vdlroot/src/signature"
@@ -60,13 +59,10 @@
}
func TestMethodSignature(t *testing.T) {
- runtime, err := rt.New()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
- t.Fatalf("Couldn't initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
ep, stop, err := startSigServer(ctx, sigImpl{})
@@ -113,13 +109,10 @@
}
func TestSignature(t *testing.T) {
- runtime, err := rt.New()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ ctx, err := veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing"))
if err != nil {
- t.Fatalf("Couldn't initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
- if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
ep, stop, err := startSigServer(ctx, sigImpl{})
diff --git a/runtimes/google/naming/namespace/all_test.go b/runtimes/google/naming/namespace/all_test.go
index 4590568..29c4932 100644
--- a/runtimes/google/naming/namespace/all_test.go
+++ b/runtimes/google/naming/namespace/all_test.go
@@ -12,7 +12,6 @@
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
verror "v.io/core/veyron2/verror2"
"v.io/core/veyron2/vlog"
@@ -29,31 +28,19 @@
testutil.Init()
}
-func createRuntimes(t *testing.T) (sc, c *context.T, cleanup func()) {
- // Create a runtime for the server.
- sr, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %v", err)
- }
- sc = sr.NewContext()
- if sc, err = veyron2.SetPrincipal(sc, tsecurity.NewPrincipal("test-blessing")); err != nil {
+func createContexts(t *testing.T) (sc, c *context.T, cleanup func()) {
+ ctx, shutdown := veyron2.Init()
+
+ var err error
+ if sc, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
- // We use a different runtime for the client side.
- r, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %v", err)
- }
- c = r.NewContext()
- if c, err = veyron2.SetPrincipal(c, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ if c, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
t.Fatal(err)
}
- return sc, c, func() {
- sr.Cleanup()
- r.Cleanup()
- }
+ return sc, c, shutdown
}
func boom(t *testing.T, f string, v ...interface{}) {
@@ -282,7 +269,7 @@
// TestNamespaceCommon tests common use of the Namespace library
// against a root mount table and some mount tables mounted on it.
func TestNamespaceCommon(t *testing.T) {
- _, c, cleanup := createRuntimes(t)
+ _, c, cleanup := createContexts(t)
defer cleanup()
root, mts, jokes, stopper := createNamespace(t, c)
@@ -314,7 +301,7 @@
// TestNamespaceDetails tests more detailed use of the Namespace library.
func TestNamespaceDetails(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, mts, _, stopper := createNamespace(t, sc)
@@ -368,7 +355,7 @@
// TestNestedMounts tests some more deeply nested mounts
func TestNestedMounts(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, mts, _, stopper := createNamespace(t, sc)
@@ -393,7 +380,7 @@
// TestServers tests invoking RPCs on simple servers
func TestServers(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, mts, jokes, stopper := createNamespace(t, sc)
@@ -418,7 +405,7 @@
// TestGlob tests some glob patterns.
func TestGlob(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, mts, _, stopper := createNamespace(t, sc)
@@ -489,7 +476,7 @@
// TestGlobEarlyStop tests that Glob doesn't query terminal servers with finished patterns.
func TestGlobEarlyStop(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, mts, _, stopper := createNamespace(t, sc)
@@ -529,7 +516,7 @@
}
func TestCycles(t *testing.T) {
- sc, c, cleanup := createRuntimes(t)
+ sc, c, cleanup := createContexts(t)
defer cleanup()
root, _, _, stopper := createNamespace(t, sc)
@@ -580,7 +567,7 @@
// TestGoroutineLeaks tests for leaking goroutines - we have many:-(
func TestGoroutineLeaks(t *testing.T) {
t.Skip()
- sc, _, cleanup := createRuntimes(t)
+ sc, _, cleanup := createContexts(t)
defer cleanup()
_, _, _, stopper := createNamespace(t, sc)
@@ -612,7 +599,7 @@
}
func TestRootBlessing(t *testing.T) {
- c, cc, cleanup := createRuntimes(t)
+ c, cc, cleanup := createContexts(t)
defer cleanup()
proot, err := vsecurity.NewPrincipal()
diff --git a/security/agent/agent_test.go b/security/agent/agent_test.go
index bfc7ddd..8b1f757 100644
--- a/security/agent/agent_test.go
+++ b/security/agent/agent_test.go
@@ -13,7 +13,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/verror2"
)
@@ -49,16 +48,13 @@
)
func TestAgent(t *testing.T) {
- r, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %s", err)
- }
- defer r.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
var (
thirdPartyCaveat, discharge = newThirdPartyCaveatAndDischarge(t)
mockP = newMockPrincipal()
- agent = setupAgent(t, r.NewContext(), mockP)
+ agent = setupAgent(t, ctx, mockP)
)
tests := []testInfo{
{"BlessSelf", V{"self"}, newBlessing(t, "blessing"), nil},
diff --git a/security/agent/agentd/main.go b/security/agent/agentd/main.go
index 3896545..c011d8a 100644
--- a/security/agent/agentd/main.go
+++ b/security/agent/agentd/main.go
@@ -20,8 +20,6 @@
"v.io/core/veyron/security/agent/server"
"v.io/core/veyron2"
- "v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/vlog"
)
@@ -76,13 +74,12 @@
vlog.Fatalf("failed to create new principal from dir(%s): %v", dir, err)
}
- runtime, err := rt.New(options.RuntimePrincipal{p})
- if err != nil {
- panic("Could not initialize runtime: " + err.Error())
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- ctx := runtime.NewContext()
+ if ctx, err = veyron2.SetPrincipal(ctx, p); err != nil {
+ vlog.Panic("failed to set principal for ctx: %v", err)
+ }
log := veyron2.GetLogger(ctx)
diff --git a/security/agent/keymgr/keymgr_test.go b/security/agent/keymgr/keymgr_test.go
index 422767a..b78c454 100644
--- a/security/agent/keymgr/keymgr_test.go
+++ b/security/agent/keymgr/keymgr_test.go
@@ -14,7 +14,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
)
@@ -40,13 +39,10 @@
}
func TestNoDeviceManager(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
- agent, cleanup, err := createAgent(runtime.NewContext(), "")
+ agent, cleanup, err := createAgent(ctx, "")
defer cleanup()
if err == nil {
t.Fatal(err)
@@ -75,12 +71,8 @@
}
func TestSigning(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
path, err := ioutil.TempDir("", "agent")
if err != nil {
@@ -146,12 +138,8 @@
}
func TestInMemorySigning(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
path, err := ioutil.TempDir("", "agent")
if err != nil {
@@ -163,7 +151,7 @@
t.Fatal(err)
}
- id, conn, err := agent.NewPrincipal(runtime.NewContext(), true)
+ id, conn, err := agent.NewPrincipal(ctx, true)
if err != nil {
t.Fatal(err)
}
diff --git a/security/agent/pingpong/main.go b/security/agent/pingpong/main.go
index 8bc1354..532edd9 100644
--- a/security/agent/pingpong/main.go
+++ b/security/agent/pingpong/main.go
@@ -7,9 +7,7 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
- "v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/signals"
_ "v.io/core/veyron/profiles"
@@ -67,13 +65,8 @@
func main() {
flag.Parse()
- runtime, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer runtime.Cleanup()
-
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
if *runServer {
serverMain(ctx)
diff --git a/services/identity/identityd/main.go b/services/identity/identityd/main.go
index e747f34..ebdf5b6 100644
--- a/services/identity/identityd/main.go
+++ b/services/identity/identityd/main.go
@@ -12,10 +12,10 @@
_ "github.com/go-sql-driver/mysql"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
- "v.io/core/veyron/profiles/static"
+ _ "v.io/core/veyron/profiles/static"
"v.io/core/veyron/services/identity/auditor"
"v.io/core/veyron/services/identity/blesser"
"v.io/core/veyron/services/identity/caveats"
@@ -72,13 +72,10 @@
vlog.Fatalf("Failed to start RevocationManager: %v", err)
}
- runtime, err := rt.New()
- if err != nil {
- vlog.Fatalf("Failed to create Runtime: %v", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ listenSpec := veyron2.GetListenSpec(ctx)
s := server.NewIdentityServer(
googleoauth,
auditor,
@@ -86,7 +83,7 @@
revocationManager,
googleOAuthBlesserParams(googleoauth, revocationManager),
caveats.NewBrowserCaveatSelector())
- s.Serve(ctx, &static.ListenSpec, *host, *httpaddr, *tlsconfig)
+ s.Serve(ctx, &listenSpec, *host, *httpaddr, *tlsconfig)
}
func usage() {
diff --git a/services/identity/identityd_test/main.go b/services/identity/identityd_test/main.go
index 63ab350..d9c8a23 100644
--- a/services/identity/identityd_test/main.go
+++ b/services/identity/identityd_test/main.go
@@ -7,10 +7,10 @@
"os"
"time"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron2/vlog"
- "v.io/core/veyron/profiles/static"
+ _ "v.io/core/veyron/profiles/static"
"v.io/core/veyron/services/identity/auditor"
"v.io/core/veyron/services/identity/blesser"
"v.io/core/veyron/services/identity/caveats"
@@ -58,13 +58,10 @@
RevocationManager: revocationManager,
}
- runtime, err := rt.New()
- if err != nil {
- vlog.Fatalf("Failed to create Runtime: %v", err)
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
+ listenSpec := veyron2.GetListenSpec(ctx)
s := server.NewIdentityServer(
oauthProvider,
auditor,
@@ -72,7 +69,7 @@
revocationManager,
params,
caveats.NewMockCaveatSelector())
- s.Serve(ctx, &static.ListenSpec, *host, *httpaddr, *tlsconfig)
+ s.Serve(ctx, &listenSpec, *host, *httpaddr, *tlsconfig)
}
func usage() {
diff --git a/services/identity/revocation/revocation_test.go b/services/identity/revocation/revocation_test.go
index 0283459..c43b94f 100644
--- a/services/identity/revocation/revocation_test.go
+++ b/services/identity/revocation/revocation_test.go
@@ -3,13 +3,12 @@
import (
"testing"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
services "v.io/core/veyron/services/security"
"v.io/core/veyron/services/security/discharger"
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/vom"
)
@@ -20,7 +19,7 @@
if err != nil {
t.Fatalf("r.NewServer: %s", err)
}
- dischargerEPs, err := dischargerServer.Listen(profiles.LocalListenSpec)
+ dischargerEPs, err := dischargerServer.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Fatalf("dischargerServer.Listen failed: %v", err)
}
@@ -37,12 +36,8 @@
}
func TestDischargeRevokeDischargeRevokeDischarge(t *testing.T) {
- r, err := rt.New()
- if err != nil {
- t.Fatalf("Could not initialize runtime: %v", err)
- }
- defer r.Cleanup()
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
dcKey, dc, revoker, closeFunc := revokerSetup(t, ctx)
defer closeFunc()
@@ -59,19 +54,19 @@
var impetus security.DischargeImpetus
- if _, err = discharger.Discharge(r.NewContext(), cav, impetus); err != nil {
+ if _, err = discharger.Discharge(ctx, cav, impetus); err != nil {
t.Fatalf("failed to get discharge: %s", err)
}
if err = revoker.Revoke(cav.ID()); err != nil {
t.Fatalf("failed to revoke: %s", err)
}
- if discharge, err := discharger.Discharge(r.NewContext(), cav, impetus); err == nil || discharge != nil {
+ if discharge, err := discharger.Discharge(ctx, cav, impetus); err == nil || discharge != nil {
t.Fatalf("got a discharge for a revoked caveat: %s", err)
}
if err = revoker.Revoke(cav.ID()); err != nil {
t.Fatalf("failed to revoke again: %s", err)
}
- if discharge, err := discharger.Discharge(r.NewContext(), cav, impetus); err == nil || discharge != nil {
+ if discharge, err := discharger.Discharge(ctx, cav, impetus); err == nil || discharge != nil {
t.Fatalf("got a discharge for a doubly revoked caveat: %s", err)
}
}
diff --git a/services/mgmt/pprof/client/proxy_test.go b/services/mgmt/pprof/client/proxy_test.go
index 53f0ef0..a5c4630 100644
--- a/services/mgmt/pprof/client/proxy_test.go
+++ b/services/mgmt/pprof/client/proxy_test.go
@@ -9,7 +9,7 @@
"v.io/core/veyron2"
"v.io/core/veyron2/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/pprof/client"
"v.io/core/veyron/services/mgmt/pprof/impl"
)
@@ -31,7 +31,7 @@
t.Fatalf("failed to start server: %v", err)
}
defer s.Stop()
- endpoints, err := s.Listen(profiles.LocalListenSpec)
+ endpoints, err := s.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Fatalf("failed to listen: %v", err)
}
diff --git a/services/mounttable/lib/mounttable_test.go b/services/mounttable/lib/mounttable_test.go
index 85cb3ff..06a8120 100644
--- a/services/mounttable/lib/mounttable_test.go
+++ b/services/mounttable/lib/mounttable_test.go
@@ -15,19 +15,17 @@
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/security/access"
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/testutil"
+ tsecurity "v.io/core/veyron/lib/testutil/security"
"v.io/core/veyron/profiles"
)
// Simulate different processes with different runtimes.
// rootCtx is the one running the mounttable service.
-var rootCtx, aliceCtx, bobCtx *context.T
-
const ttlSecs = 60 * 60
func boom(t *testing.T, f string, v ...interface{}) {
@@ -255,7 +253,7 @@
}
}
-func newMT(t *testing.T, acl string) (ipc.Server, string) {
+func newMT(t *testing.T, acl string, rootCtx *context.T) (ipc.Server, string) {
server, err := veyron2.NewServer(rootCtx, options.ServesMountTable(true))
if err != nil {
boom(t, "r.NewServer: %s", err)
@@ -278,7 +276,7 @@
return server, estr
}
-func newCollection(t *testing.T, acl string) (ipc.Server, string) {
+func newCollection(t *testing.T, acl string, rootCtx *context.T) (ipc.Server, string) {
server, err := veyron2.NewServer(rootCtx)
if err != nil {
boom(t, "r.NewServer: %s", err)
@@ -300,9 +298,12 @@
}
func TestMountTable(t *testing.T) {
- mt, mtAddr := newMT(t, "testdata/test.acl")
+ rootCtx, aliceCtx, bobCtx, shutdown := initTest()
+ defer shutdown()
+
+ mt, mtAddr := newMT(t, "testdata/test.acl", rootCtx)
defer mt.Stop()
- collection, collectionAddr := newCollection(t, "testdata/test.acl")
+ collection, collectionAddr := newCollection(t, "testdata/test.acl", rootCtx)
defer collection.Stop()
collectionName := naming.JoinAddressName(collectionAddr, "collection")
@@ -447,7 +448,10 @@
}
func TestGlob(t *testing.T) {
- server, estr := newMT(t, "")
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ server, estr := newMT(t, "", rootCtx)
defer server.Stop()
// set up a mount space
@@ -491,7 +495,10 @@
}
func TestACLTemplate(t *testing.T) {
- server, estr := newMT(t, "testdata/test.acl")
+ rootCtx, aliceCtx, bobCtx, shutdown := initTest()
+ defer shutdown()
+
+ server, estr := newMT(t, "testdata/test.acl", rootCtx)
defer server.Stop()
fakeServer := naming.JoinAddressName(estr, "quux")
@@ -507,7 +514,10 @@
}
func TestGlobACLs(t *testing.T) {
- server, estr := newMT(t, "testdata/test.acl")
+ rootCtx, aliceCtx, bobCtx, shutdown := initTest()
+ defer shutdown()
+
+ server, estr := newMT(t, "testdata/test.acl", rootCtx)
defer server.Stop()
// set up a mount space
@@ -537,7 +547,10 @@
}
func TestCleanup(t *testing.T) {
- server, estr := newMT(t, "")
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ server, estr := newMT(t, "", rootCtx)
defer server.Stop()
// Set up one mount.
@@ -561,7 +574,10 @@
}
func TestDelete(t *testing.T) {
- server, estr := newMT(t, "testdata/test.acl")
+ rootCtx, aliceCtx, bobCtx, shutdown := initTest()
+ defer shutdown()
+
+ server, estr := newMT(t, "testdata/test.acl", rootCtx)
defer server.Stop()
// set up a mount space
@@ -585,7 +601,10 @@
}
func TestServerFormat(t *testing.T) {
- server, estr := newMT(t, "")
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ server, estr := newMT(t, "", rootCtx)
defer server.Stop()
doMount(t, rootCtx, estr, "endpoint", naming.JoinAddressName(estr, "life/on/the/mississippi"), true)
@@ -597,9 +616,12 @@
}
func TestExpiry(t *testing.T) {
- server, estr := newMT(t, "")
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
+
+ server, estr := newMT(t, "", rootCtx)
defer server.Stop()
- collection, collectionAddr := newCollection(t, "testdata/test.acl")
+ collection, collectionAddr := newCollection(t, "testdata/test.acl", rootCtx)
defer collection.Stop()
collectionName := naming.JoinAddressName(collectionAddr, "collection")
@@ -634,24 +656,20 @@
}
}
-func init() {
+func initTest() (rootCtx *context.T, aliceCtx *context.T, bobCtx *context.T, shutdown veyron2.Shutdown) {
testutil.Init()
- // Create the runtime for each of the three "processes"
+ ctx, shutdown := veyron2.Init()
- var rootRT, aliceRT, bobRT veyron2.Runtime
var err error
- if rootRT, err = rt.New(); err != nil {
- panic(err)
+ if rootCtx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("root")); err != nil {
+ panic("failed to set root principal")
}
- rootCtx = rootRT.NewContext()
- if aliceRT, err = rt.New(); err != nil {
- panic(err)
+ if aliceCtx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("alice")); err != nil {
+ panic("failed to set alice principal")
}
- aliceCtx = aliceRT.NewContext()
- if bobRT, err = rt.New(); err != nil {
- panic(err)
+ if bobCtx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("bob")); err != nil {
+ panic("failed to set bob principal")
}
- bobCtx = bobRT.NewContext()
// A hack to set the namespace roots to a value that won't work.
for _, r := range []*context.T{rootCtx, aliceCtx, bobCtx} {
@@ -684,4 +702,6 @@
}
}
}
+
+ return rootCtx, aliceCtx, bobCtx, shutdown
}
diff --git a/services/mounttable/lib/neighborhood_test.go b/services/mounttable/lib/neighborhood_test.go
index 6f197d6..b22e724 100644
--- a/services/mounttable/lib/neighborhood_test.go
+++ b/services/mounttable/lib/neighborhood_test.go
@@ -27,6 +27,8 @@
}
func TestNeighborhood(t *testing.T) {
+ rootCtx, shutdown := veyron2.Init()
+ defer shutdown()
vlog.Infof("TestNeighborhood")
server, err := veyron2.NewServer(rootCtx)
if err != nil {
diff --git a/services/mounttable/mounttabled/mounttable.go b/services/mounttable/mounttabled/mounttable.go
index fd8081f..b6d60b9 100644
--- a/services/mounttable/mounttabled/mounttable.go
+++ b/services/mounttable/mounttabled/mounttable.go
@@ -9,11 +9,10 @@
"v.io/core/veyron2"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/options"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/signals"
- "v.io/core/veyron/profiles/roaming"
+ _ "v.io/core/veyron/profiles/roaming"
mounttable "v.io/core/veyron/services/mounttable/lib"
)
@@ -24,13 +23,8 @@
)
func main() {
- r, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %v", err)
- }
- defer r.Cleanup()
-
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
mtServer, err := veyron2.NewServer(ctx, options.ServesMountTable(true))
if err != nil {
@@ -43,7 +37,8 @@
vlog.Errorf("r.NewMountTable failed: %v", err)
os.Exit(1)
}
- mtEndpoints, err := mtServer.Listen(roaming.ListenSpec)
+ listenSpec := veyron2.GetListenSpec(ctx)
+ mtEndpoints, err := mtServer.Listen(listenSpec)
if err != nil {
vlog.Errorf("mtServer.Listen failed: %v", err)
os.Exit(1)
@@ -58,9 +53,9 @@
vlog.Infof("Mount table service at: %q endpoint: %s", name, mtEndpoint.Name())
if len(*nhName) > 0 {
- neighborhoodListenSpec := roaming.ListenSpec
+ neighborhoodListenSpec := listenSpec
// The ListenSpec code ensures that we have a valid address here.
- host, port, _ := net.SplitHostPort(roaming.ListenSpec.Addrs[0].Address)
+ host, port, _ := net.SplitHostPort(listenSpec.Addrs[0].Address)
if port != "" {
neighborhoodListenSpec.Addrs[0].Address = net.JoinHostPort(host, "0")
}
diff --git a/services/proxy/proxyd/main.go b/services/proxy/proxyd/main.go
index c985659..63bf175 100644
--- a/services/proxy/proxyd/main.go
+++ b/services/proxy/proxyd/main.go
@@ -10,7 +10,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/vlog"
_ "v.io/core/veyron/profiles"
@@ -31,12 +30,8 @@
)
func main() {
- r, err := rt.New()
- if err != nil {
- vlog.Fatalf("Could not initialize runtime: %s", err)
- }
- defer r.Cleanup()
- ctx := r.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
rid, err := naming.NewRoutingID()
if err != nil {
diff --git a/tools/binary/impl_test.go b/tools/binary/impl_test.go
index d0f7ca6..28b62b2 100644
--- a/tools/binary/impl_test.go
+++ b/tools/binary/impl_test.go
@@ -15,7 +15,6 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/binary"
"v.io/core/veyron2/services/mgmt/repository"
@@ -121,12 +120,10 @@
}
func TestBinaryClient(t *testing.T) {
- runtime, err := rt.New()
- if err != nil {
- t.Fatalf("Unexpected error initializing runtime: %s", err)
- }
- defer runtime.Cleanup()
- gctx = runtime.NewContext()
+ var shutdown veyron2.Shutdown
+ gctx, shutdown = veyron2.Init()
+ defer shutdown()
+ var err error
if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
panic(err)
}
diff --git a/tools/mgmt/device/acl_test.go b/tools/mgmt/device/acl_test.go
index b242182..a146e82 100644
--- a/tools/mgmt/device/acl_test.go
+++ b/tools/mgmt/device/acl_test.go
@@ -20,6 +20,9 @@
)
func TestACLGetCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -66,6 +69,9 @@
}
func TestACLSetCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
diff --git a/tools/mgmt/device/impl_test.go b/tools/mgmt/device/impl_test.go
index 1e38b25..065574c 100644
--- a/tools/mgmt/device/impl_test.go
+++ b/tools/mgmt/device/impl_test.go
@@ -12,23 +12,23 @@
"v.io/core/veyron2"
"v.io/core/veyron2/naming"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/device"
verror "v.io/core/veyron2/verror2"
)
-func init() {
- runtime, err := rt.New()
- if err != nil {
- panic(err)
- }
- gctx = runtime.NewContext()
+func initTest() (shutdown veyron2.Shutdown) {
+ var err error
+ gctx, shutdown = veyron2.Init()
if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
panic(err)
}
+ return shutdown
}
func TestListCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -81,6 +81,9 @@
}
func TestAddCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -131,6 +134,9 @@
}
func TestRemoveCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -168,6 +174,9 @@
}
func TestInstallCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -258,6 +267,9 @@
}
func TestClaimCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -335,6 +347,9 @@
}
func TestStartCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
diff --git a/tools/mgmt/device/instance_impl_test.go b/tools/mgmt/device/instance_impl_test.go
index 97e567f..10f6702 100644
--- a/tools/mgmt/device/instance_impl_test.go
+++ b/tools/mgmt/device/instance_impl_test.go
@@ -11,6 +11,9 @@
)
func TestStopCommand(t *testing.T) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
@@ -83,6 +86,9 @@
}
func testHelper(t *testing.T, lower, upper string) {
+ shutdown := initTest()
+ defer shutdown()
+
tape := NewTape()
server, endpoint, err := startServer(t, gctx, tape)
if err != nil {
diff --git a/tools/mounttable/impl_test.go b/tools/mounttable/impl_test.go
index 7fd56d3..d1aefc9 100644
--- a/tools/mounttable/impl_test.go
+++ b/tools/mounttable/impl_test.go
@@ -15,7 +15,7 @@
"v.io/core/veyron2/vlog"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
)
type server struct {
@@ -83,7 +83,7 @@
t.Errorf("NewServer failed: %v", err)
return nil, nil, err
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Errorf("Listen failed: %v", err)
return nil, nil, err
diff --git a/tools/naming/simulator/driver.go b/tools/naming/simulator/driver.go
index 685f19a..34c6e91 100644
--- a/tools/naming/simulator/driver.go
+++ b/tools/naming/simulator/driver.go
@@ -18,7 +18,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron/lib/expect"
"v.io/core/veyron/lib/modules"
@@ -96,21 +95,17 @@
}
}
-var runtime veyron2.Runtime
var ctx *context.T
func main() {
- var err error
- if runtime, err = rt.New(); err != nil {
- panic(err)
- }
- defer runtime.Cleanup()
- ctx = runtime.NewContext()
+ var shutdown veyron2.Shutdown
+ ctx, shutdown = veyron2.Init()
// Subprocesses commands are run by fork/execing this binary
// so we must test to see if this instance is a subprocess or the
// the original command line instance.
if modules.IsModulesProcess() {
+ shutdown()
// Subprocess, run the requested command.
if err := modules.Dispatch(); err != nil {
fmt.Fprintf(os.Stderr, "failed: %v\n", err)
@@ -118,6 +113,7 @@
}
return
}
+ defer shutdown()
shell, err := modules.NewShell(ctx, nil)
if err != nil {
diff --git a/tools/profile/impl_test.go b/tools/profile/impl_test.go
index 891e36d..25de771 100644
--- a/tools/profile/impl_test.go
+++ b/tools/profile/impl_test.go
@@ -15,7 +15,7 @@
"v.io/core/veyron2/vlog"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/profile"
"v.io/core/veyron/services/mgmt/repository"
)
@@ -90,7 +90,7 @@
t.Errorf("NewServer failed: %v", err)
return nil, nil, err
}
- endpoints, err := server.Listen(profiles.LocalListenSpec)
+ endpoints, err := server.Listen(veyron2.GetListenSpec(ctx))
if err != nil {
t.Errorf("Listen failed: %v", err)
return nil, nil, err
diff --git a/tools/servicerunner/main.go b/tools/servicerunner/main.go
index 09a8e37..225e19a 100644
--- a/tools/servicerunner/main.go
+++ b/tools/servicerunner/main.go
@@ -9,7 +9,7 @@
"strings"
"time"
- "v.io/core/veyron2/rt"
+ "v.io/core/veyron2"
"v.io/core/veyron/lib/expect"
"v.io/core/veyron/lib/flags/consts"
@@ -55,20 +55,24 @@
}
func main() {
- r, err := rt.New()
- if err != nil {
- panic(fmt.Sprintf("Could not initialize runtime %s", err))
- }
- defer r.Cleanup()
+ 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
}
+ defer shutdown()
vars := map[string]string{}
- sh, err := modules.NewShell(r.NewContext(), nil)
+ sh, err := modules.NewShell(ctx, nil)
if err != nil {
panic(fmt.Sprintf("modules.NewShell: %s", err))
}
diff --git a/tools/vrpc/vrpc_test.go b/tools/vrpc/vrpc_test.go
index 573c367..e039db9 100644
--- a/tools/vrpc/vrpc_test.go
+++ b/tools/vrpc/vrpc_test.go
@@ -10,7 +10,7 @@
"v.io/core/veyron2/vlog"
tsecurity "v.io/core/veyron/lib/testutil/security"
- "v.io/core/veyron/profiles"
+ _ "v.io/core/veyron/profiles"
"v.io/core/veyron/tools/vrpc/test_base"
)
@@ -120,7 +120,7 @@
t.Fatalf("NewServer failed: %v", err)
return
}
- endpoints, err := ipcServer.Listen(profiles.LocalListenSpec)
+ endpoints, err := ipcServer.Listen(veyron2.GetListenSpec(gctx))
if err != nil {
t.Fatalf("Listen failed: %v", err)
return
@@ -129,9 +129,9 @@
obj := test_base.TypeTesterServer(&server{})
if err := ipcServer.Serve("", obj, nil); err != nil {
t.Fatalf("Serve failed: %v", err)
- return
+ return name, shutdown
}
- return
+ return name, shutdown
}
func TestSignature(t *testing.T) {
diff --git a/tools/vrun/vrun.go b/tools/vrun/vrun.go
index eb34737..fb3bec2 100644
--- a/tools/vrun/vrun.go
+++ b/tools/vrun/vrun.go
@@ -14,7 +14,6 @@
"v.io/core/veyron2"
"v.io/core/veyron2/context"
- "v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/vlog"
@@ -45,13 +44,8 @@
}
func vrun(cmd *cmdline.Command, args []string) error {
- runtime, err := rt.New()
- if err != nil {
- vlog.Errorf("Could not initialize runtime")
- return err
- }
- defer runtime.Cleanup()
- ctx := runtime.NewContext()
+ ctx, shutdown := veyron2.Init()
+ defer shutdown()
if len(args) == 0 {
return cmd.UsageErrorf("vrun: no command specified")