"core": Makes Tests pass under agent

This is part 1 out of n of a series of CLs to make all go tests
pass when they run under an agent (for e.g., inside vbash)

This CL fixes all tests under "veyron/runtimes/google/..."

Most tests currenly fail because of the following pattern:
func TextXXX(t *testing.T) {
  runtime, err := rt.New()  // In the new world this is veyron2.Init()
  ctx := runtime.NewContext()
  doSomething(ctx)
  ...
}
The issue here is that rt.New (or veyron2.Init) initializes the
principal via the environment variables (for e.g., when run inside
vbash, the test initializes its principal through the agent). This is
a problem for multiple reasons:
- the test is not self-contained
- the test can pollute the environment provided principal's state
- the test was likely written with the assumption that rt.New() always
  generates a self-signed principal which is False.

To fix this, I am changing the code to:
func TextXXX(t *testing.T) {
  runtime, err := rt.New()  // In the new world this is veyron2.Init()
  ctx := runtime.NewContext()
  ctx, err = veyron2.SetPrincipal(tsecurity.NewPrincipal(...))
  doSomething(ctx)
  ...
}

Change-Id: I2d427f4284b87e206057011f88f88575c0868af3
diff --git a/runtimes/google/ipc/benchmark/benchmark_test.go b/runtimes/google/ipc/benchmark/benchmark_test.go
index 89b1e4f..941a22d 100644
--- a/runtimes/google/ipc/benchmark/benchmark_test.go
+++ b/runtimes/google/ipc/benchmark/benchmark_test.go
@@ -5,6 +5,7 @@
 	"testing"
 
 	"v.io/core/veyron/lib/testutil/benchmark"
+	tsecurity "v.io/core/veyron/lib/testutil/security"
 	"v.io/core/veyron/profiles"
 
 	"v.io/core/veyron2"
@@ -106,6 +107,9 @@
 		panic(err)
 	}
 	ctx := vrt.NewContext()
+	if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		panic(err)
+	}
 
 	var serverStop func()
 	serverAddr, serverStop = StartServer(ctx, profiles.LocalListenSpec)
diff --git a/runtimes/google/ipc/benchmark/glob/glob_test.go b/runtimes/google/ipc/benchmark/glob/glob_test.go
index db032b3..951b16d 100644
--- a/runtimes/google/ipc/benchmark/glob/glob_test.go
+++ b/runtimes/google/ipc/benchmark/glob/glob_test.go
@@ -11,6 +11,7 @@
 	"v.io/core/veyron2/rt"
 	"v.io/core/veyron2/security"
 
+	tsecurity "v.io/core/veyron/lib/testutil/security"
 	"v.io/core/veyron/profiles"
 )
 
@@ -161,6 +162,9 @@
 	}
 	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 e44b5bb..499c7bc 100644
--- a/runtimes/google/ipc/client_test.go
+++ b/runtimes/google/ipc/client_test.go
@@ -27,17 +27,22 @@
 	inaming "v.io/core/veyron/runtimes/google/naming"
 )
 
-var r veyron2.Runtime
-var gctx *context.T
-
 func init() {
 	modules.RegisterChild("ping", "<name>", childPing)
-	var err error
-	if r, err = rt.New(); err != nil {
+}
+
+func newCtx() (*context.T, veyron2.Shutdown) {
+	r, err := rt.New()
+	if err != nil {
 		panic(err)
 	}
-	gctx = r.NewContext()
-	veyron2.GetNamespace(gctx).CacheCtl(naming.DisableCache(true))
+	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
 }
 
 func testArgs(args ...string) []string {
@@ -97,8 +102,8 @@
 	return nil
 }
 
-func numServers(t *testing.T, name string) int {
-	me, err := veyron2.GetNamespace(gctx).Resolve(gctx, name)
+func numServers(t *testing.T, ctx *context.T, name string) int {
+	me, err := veyron2.GetNamespace(ctx).Resolve(ctx, name)
 	if err != nil {
 		return 0
 	}
@@ -108,7 +113,9 @@
 // TODO(cnicolaou): figure out how to test and see what the internals
 // of tryCall are doing - e.g. using stats counters.
 func TestMultipleEndpoints(t *testing.T) {
-	sh, fn := runMountTable(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	sh, fn := runMountTable(t, ctx)
 	defer fn()
 	srv, err := sh.Start(core.EchoServerCommand, nil, testArgs("echoServer", "echoServer")...)
 	if err != nil {
@@ -119,7 +126,7 @@
 	s.ExpectVar("NAME")
 
 	// Verify that there are 1 entries for echoServer in the mount table.
-	if got, want := numServers(t, "echoServer"), 1; got != want {
+	if got, want := numServers(t, ctx, "echoServer"), 1; got != want {
 		t.Fatalf("got: %q, want: %q", got, want)
 	}
 
@@ -130,13 +137,13 @@
 		// 203.0.113.0 is TEST-NET-3 from RFC5737
 		ep := naming.FormatEndpoint("tcp", fmt.Sprintf("203.0.113.%d:443", i))
 		n := naming.JoinAddressName(ep, "")
-		if err := veyron2.GetNamespace(gctx).Mount(gctx, "echoServer", n, time.Hour); err != nil {
+		if err := veyron2.GetNamespace(ctx).Mount(ctx, "echoServer", n, time.Hour); err != nil {
 			t.Fatalf("unexpected error: %s", err)
 		}
 	}
 
 	// Verify that there are 101 entries for echoServer in the mount table.
-	if got, want := numServers(t, "echoServer"), 101; got != want {
+	if got, want := numServers(t, ctx, "echoServer"), 101; got != want {
 		t.Fatalf("got: %q, want: %q", got, want)
 	}
 
@@ -151,13 +158,15 @@
 	srv.Shutdown(nil, nil)
 
 	// Verify that there are 100 entries for echoServer in the mount table.
-	if got, want := numServers(t, "echoServer"), 100; got != want {
+	if got, want := numServers(t, ctx, "echoServer"), 100; got != want {
 		t.Fatalf("got: %d, want: %d", got, want)
 	}
 }
 
 func TestTimeoutCall(t *testing.T) {
-	ctx, _ := context.WithTimeout(gctx, 100*time.Millisecond)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	ctx, _ = context.WithTimeout(ctx, 100*time.Millisecond)
 	name := naming.JoinAddressName(naming.FormatEndpoint("tcp", "203.0.113.10:443"), "")
 	client := veyron2.GetClient(ctx)
 	_, err := client.StartCall(ctx, name, "echo", []interface{}{"args don't matter"})
@@ -167,8 +176,15 @@
 }
 
 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()
+	veyron2.GetNamespace(ctx).CacheCtl(naming.DisableCache(true))
+
 	name := args[1]
-	call, err := veyron2.GetClient(gctx).StartCall(gctx, name, "Ping", nil)
+	call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Ping", nil)
 	if err != nil {
 		fmt.Errorf("unexpected error: %s", err)
 	}
@@ -223,9 +239,11 @@
 }
 
 func TestTimeoutResponse(t *testing.T) {
-	name, fn := initServer(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	name, fn := initServer(t, ctx)
 	defer fn()
-	ctx, _ := context.WithTimeout(gctx, 100*time.Millisecond)
+	ctx, _ = context.WithTimeout(ctx, 100*time.Millisecond)
 	call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", nil)
 	if err != nil {
 		testForVerror(t, err, verror.Timeout, verror.BadProtocol)
@@ -237,17 +255,19 @@
 }
 
 func TestArgsAndResponses(t *testing.T) {
-	name, fn := initServer(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	name, fn := initServer(t, ctx)
 	defer fn()
 
-	call, err := veyron2.GetClient(gctx).StartCall(gctx, name, "Sleep", []interface{}{"too many args"})
+	call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", []interface{}{"too many args"})
 	if err != nil {
 		t.Fatalf("unexpected error: %s", err)
 	}
 	verr := call.Finish(&err)
 	testForVerror(t, verr, verror.BadProtocol)
 
-	call, err = veyron2.GetClient(gctx).StartCall(gctx, name, "Ping", nil)
+	call, err = veyron2.GetClient(ctx).StartCall(ctx, name, "Ping", nil)
 	if err != nil {
 		t.Fatalf("unexpected error: %s", err)
 	}
@@ -264,10 +284,19 @@
 	// The server and client use different runtimes and hence different
 	// principals and without any shared blessings the server will deny
 	// access to the client
-	name, fn := initServer(t, r1.NewContext())
+	ctx1 := r1.NewContext()
+	var err error
+	if ctx1, err = veyron2.SetPrincipal(ctx1, tsecurity.NewPrincipal("test-blessing")); 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 {
+		t.Fatal(err)
+	}
 	client2 := veyron2.GetClient(ctx2)
 	call, err := client2.StartCall(ctx2, name, "Sleep", nil)
 	if err != nil {
@@ -278,10 +307,12 @@
 }
 
 func TestCancelledBeforeFinish(t *testing.T) {
-	name, fn := initServer(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	name, fn := initServer(t, ctx)
 	defer fn()
 
-	ctx, cancel := context.WithCancel(gctx)
+	ctx, cancel := context.WithCancel(ctx)
 	call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", nil)
 	if err != nil {
 		t.Fatalf("unexpected error: %s", err)
@@ -294,10 +325,12 @@
 }
 
 func TestCancelledDuringFinish(t *testing.T) {
-	name, fn := initServer(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	name, fn := initServer(t, ctx)
 	defer fn()
 
-	ctx, cancel := context.WithCancel(gctx)
+	ctx, cancel := context.WithCancel(ctx)
 	call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", nil)
 	if err != nil {
 		t.Fatalf("unexpected error: %s", err)
@@ -313,7 +346,9 @@
 }
 
 func TestRendezvous(t *testing.T) {
-	sh, fn := runMountTable(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	sh, fn := runMountTable(t, ctx)
 	defer fn()
 
 	name := "echoServer"
@@ -330,7 +365,7 @@
 	}
 	go startServer()
 
-	call, err := veyron2.GetClient(gctx).StartCall(gctx, name, "Echo", []interface{}{"hello"})
+	call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Echo", []interface{}{"hello"})
 	if err != nil {
 		t.Fatalf("unexpected error: %s", err)
 	}
@@ -347,10 +382,12 @@
 }
 
 func TestCallback(t *testing.T) {
-	sh, fn := runMountTable(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	sh, fn := runMountTable(t, ctx)
 	defer fn()
 
-	name, fn := initServer(t, gctx)
+	name, fn := initServer(t, ctx)
 	defer fn()
 
 	srv, err := sh.Start("ping", nil, name)
@@ -364,11 +401,13 @@
 }
 
 func TestStreamTimeout(t *testing.T) {
-	name, fn := initServer(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	name, fn := initServer(t, ctx)
 	defer fn()
 
 	want := 10
-	ctx, _ := context.WithTimeout(gctx, 300*time.Millisecond)
+	ctx, _ = context.WithTimeout(ctx, 300*time.Millisecond)
 	call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Source", []interface{}{want})
 	if err != nil {
 		if !verror.Is(err, verror.Timeout.ID) && !verror.Is(err, verror.BadProtocol.ID) {
@@ -397,10 +436,12 @@
 }
 
 func TestStreamAbort(t *testing.T) {
-	name, fn := initServer(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	name, fn := initServer(t, ctx)
 	defer fn()
 
-	call, err := veyron2.GetClient(gctx).StartCall(gctx, name, "Sink", nil)
+	call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Sink", nil)
 	if err != nil {
 		t.Fatalf("unexpected error: %s", err)
 	}
@@ -434,10 +475,12 @@
 }
 
 func TestNoServersAvailable(t *testing.T) {
-	_, fn := runMountTable(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	_, fn := runMountTable(t, ctx)
 	defer fn()
 	name := "noservers"
-	ctx, _ := context.WithTimeout(gctx, 300*time.Millisecond)
+	ctx, _ = context.WithTimeout(ctx, 300*time.Millisecond)
 	call, verr := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", nil)
 	if verr != nil {
 		testForVerror(t, verr, verror.Timeout, verror.BadProtocol, verror.NoExist)
@@ -448,11 +491,13 @@
 }
 
 func TestNoMountTable(t *testing.T) {
-	veyron2.GetNamespace(gctx).SetRoots()
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	veyron2.GetNamespace(ctx).SetRoots()
 	name := "a_mount_table_entry"
 
 	// If there is no mount table, then we'll get a NoServers error message.
-	ctx, _ := context.WithTimeout(gctx, 300*time.Millisecond)
+	ctx, _ = context.WithTimeout(ctx, 300*time.Millisecond)
 	_, verr := veyron2.GetClient(ctx).StartCall(ctx, name, "Sleep", nil)
 	testForVerror(t, verr, verror.NoServers)
 }
diff --git a/runtimes/google/ipc/glob_test.go b/runtimes/google/ipc/glob_test.go
index 20b60af..799a67e 100644
--- a/runtimes/google/ipc/glob_test.go
+++ b/runtimes/google/ipc/glob_test.go
@@ -15,6 +15,7 @@
 
 	"v.io/core/veyron/lib/glob"
 	"v.io/core/veyron/lib/testutil"
+	tsecurity "v.io/core/veyron/lib/testutil/security"
 	"v.io/core/veyron/profiles"
 )
 
@@ -41,6 +42,9 @@
 	}
 	defer runtime.Cleanup()
 	ctx := runtime.NewContext()
+	if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		t.Fatal(err)
+	}
 
 	namespace := []string{
 		"a/b/c1/d1",
diff --git a/runtimes/google/ipc/resolve_test.go b/runtimes/google/ipc/resolve_test.go
index ab64566..53dfdbc 100644
--- a/runtimes/google/ipc/resolve_test.go
+++ b/runtimes/google/ipc/resolve_test.go
@@ -12,6 +12,7 @@
 	"v.io/core/veyron/lib/expect"
 	"v.io/core/veyron/lib/modules"
 	"v.io/core/veyron/lib/modules/core"
+	tsecurity "v.io/core/veyron/lib/testutil/security"
 	iipc "v.io/core/veyron/runtimes/google/ipc"
 	inaming "v.io/core/veyron/runtimes/google/naming"
 )
@@ -40,6 +41,9 @@
 	}
 	defer runtime.Cleanup()
 	ctx := runtime.NewContext()
+	if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		t.Fatal(err)
+	}
 
 	ns := veyron2.GetNamespace(ctx)
 	ns.SetRoots(root)
diff --git a/runtimes/google/ipc/signature_test.go b/runtimes/google/ipc/signature_test.go
index 26a5ec5..a0604c8 100644
--- a/runtimes/google/ipc/signature_test.go
+++ b/runtimes/google/ipc/signature_test.go
@@ -15,6 +15,7 @@
 	"v.io/core/veyron2/vdl/vdlroot/src/signature"
 
 	"v.io/core/veyron/lib/testutil"
+	tsecurity "v.io/core/veyron/lib/testutil/security"
 	"v.io/core/veyron/profiles"
 )
 
@@ -65,7 +66,9 @@
 	}
 	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{})
 	if err != nil {
 		t.Fatalf("startSigServer: %v", err)
@@ -116,7 +119,9 @@
 	}
 	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{})
 	if err != nil {
 		t.Fatalf("startSigServer: %v", err)
diff --git a/runtimes/google/ipc/simple_test.go b/runtimes/google/ipc/simple_test.go
index 39b1147..15b2a3b 100644
--- a/runtimes/google/ipc/simple_test.go
+++ b/runtimes/google/ipc/simple_test.go
@@ -67,11 +67,13 @@
 }
 
 func TestSimpleRPC(t *testing.T) {
-	name, fn := initServer(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	name, fn := initServer(t, ctx)
 	defer fn()
 
-	client := veyron2.GetClient(r.NewContext())
-	call, err := client.StartCall(r.NewContext(), name, "Ping", nil)
+	client := veyron2.GetClient(ctx)
+	call, err := client.StartCall(ctx, name, "Ping", nil)
 	if err != nil {
 		t.Fatalf("unexpected error: %s", err)
 	}
@@ -87,12 +89,13 @@
 }
 
 func TestSimpleStreaming(t *testing.T) {
-	name, fn := initServer(t, gctx)
+	ctx, shutdown := newCtx()
+	defer shutdown()
+	name, fn := initServer(t, ctx)
 	defer fn()
 
-	ctx := r.NewContext()
 	inc := 1
-	call, err := veyron2.GetClient(r.NewContext()).StartCall(ctx, name, "Inc", []interface{}{inc})
+	call, err := veyron2.GetClient(ctx).StartCall(ctx, name, "Inc", []interface{}{inc})
 	if err != nil {
 		t.Fatalf("unexpected error: %s", err)
 	}
diff --git a/runtimes/google/naming/namespace/all_test.go b/runtimes/google/naming/namespace/all_test.go
index ad898a7..4590568 100644
--- a/runtimes/google/naming/namespace/all_test.go
+++ b/runtimes/google/naming/namespace/all_test.go
@@ -18,6 +18,7 @@
 	"v.io/core/veyron2/vlog"
 
 	"v.io/core/veyron/lib/testutil"
+	tsecurity "v.io/core/veyron/lib/testutil/security"
 	"v.io/core/veyron/profiles"
 	"v.io/core/veyron/runtimes/google/naming/namespace"
 	vsecurity "v.io/core/veyron/security"
@@ -35,6 +36,9 @@
 		t.Fatalf("Could not initialize runtime: %v", err)
 	}
 	sc = sr.NewContext()
+	if sc, err = veyron2.SetPrincipal(sc, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		t.Fatal(err)
+	}
 
 	// We use a different runtime for the client side.
 	r, err := rt.New()
@@ -42,6 +46,9 @@
 		t.Fatalf("Could not initialize runtime: %v", err)
 	}
 	c = r.NewContext()
+	if c, err = veyron2.SetPrincipal(c, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		t.Fatal(err)
+	}
 
 	return sc, c, func() {
 		sr.Cleanup()
diff --git a/runtimes/google/rt/mgmt_test.go b/runtimes/google/rt/mgmt_test.go
index 220a562..f99ab44 100644
--- a/runtimes/google/rt/mgmt_test.go
+++ b/runtimes/google/rt/mgmt_test.go
@@ -14,11 +14,13 @@
 	"v.io/core/veyron2/ipc"
 	"v.io/core/veyron2/mgmt"
 	"v.io/core/veyron2/naming"
+	"v.io/core/veyron2/security"
 	"v.io/core/veyron2/services/mgmt/appcycle"
 
 	"v.io/core/veyron/lib/expect"
 	"v.io/core/veyron/lib/modules"
 	"v.io/core/veyron/lib/testutil"
+	tsecurity "v.io/core/veyron/lib/testutil/security"
 	"v.io/core/veyron/profiles"
 	vflag "v.io/core/veyron/security/flag"
 	"v.io/core/veyron/services/mgmt/device"
@@ -42,6 +44,10 @@
 func TestBasic(t *testing.T) {
 	ctx, shutdown := veyron2.Init()
 	defer shutdown()
+	var err error
+	if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		t.Fatal(err)
+	}
 
 	m := veyron2.GetAppCycle(ctx)
 	ch := make(chan string, 1)
@@ -64,6 +70,10 @@
 func TestMultipleWaiters(t *testing.T) {
 	ctx, shutdown := veyron2.Init()
 	defer shutdown()
+	var err error
+	if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		t.Fatal(err)
+	}
 
 	m := veyron2.GetAppCycle(ctx)
 	ch1 := make(chan string, 1)
@@ -87,6 +97,10 @@
 func TestMultipleStops(t *testing.T) {
 	ctx, shutdown := veyron2.Init()
 	defer shutdown()
+	var err error
+	if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		t.Fatal(err)
+	}
 
 	m := veyron2.GetAppCycle(ctx)
 	ch := make(chan string, 1)
@@ -187,6 +201,10 @@
 // tracker.
 func TestProgress(t *testing.T) {
 	ctx, shutdown := veyron2.Init()
+	var err error
+	if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		t.Fatal(err)
+	}
 
 	m := veyron2.GetAppCycle(ctx)
 	m.AdvanceGoal(50)
@@ -219,6 +237,10 @@
 // block when the tracker channels are full.
 func TestProgressMultipleTrackers(t *testing.T) {
 	ctx, shutdown := veyron2.Init()
+	var err error
+	if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		t.Fatal(err)
+	}
 
 	m := veyron2.GetAppCycle(ctx)
 	// ch1 is 1-buffered, ch2 is 2-buffered.
@@ -297,8 +319,12 @@
 	return server, eps[0].Name(), ch
 }
 
-func setupRemoteAppCycleMgr(t *testing.T) (*context.T, modules.Handle, appcycle.AppCycleClientMethods, func()) {
+func setupRemoteAppCycleMgr(t *testing.T, p security.Principal) (*context.T, modules.Handle, appcycle.AppCycleClientMethods, func()) {
 	ctx, shutdown := veyron2.Init()
+	var err error
+	if ctx, err = veyron2.SetPrincipal(ctx, p); err != nil {
+		t.Fatal(err)
+	}
 
 	configServer, configServiceName, ch := createConfigServer(t, ctx)
 	sh, err := modules.NewShell(ctx, veyron2.GetPrincipal(ctx))
@@ -329,7 +355,7 @@
 // TestRemoteForceStop verifies that the child process exits when sending it
 // a remote ForceStop rpc.
 func TestRemoteForceStop(t *testing.T) {
-	ctx, h, appCycle, cleanup := setupRemoteAppCycleMgr(t)
+	ctx, h, appCycle, cleanup := setupRemoteAppCycleMgr(t, tsecurity.NewPrincipal("test-blessing"))
 	defer cleanup()
 	if err := appCycle.ForceStop(ctx); err == nil || !strings.Contains(err.Error(), "EOF") {
 		t.Fatalf("Expected EOF error, got %v instead", err)
@@ -346,7 +372,7 @@
 // TestRemoteStop verifies that the child shuts down cleanly when sending it
 // a remote Stop rpc.
 func TestRemoteStop(t *testing.T) {
-	ctx, h, appCycle, cleanup := setupRemoteAppCycleMgr(t)
+	ctx, h, appCycle, cleanup := setupRemoteAppCycleMgr(t, tsecurity.NewPrincipal("test-blessing"))
 	defer cleanup()
 	stream, err := appCycle.Stop(ctx)
 	if err != nil {
diff --git a/runtimes/google/rt/rt_test.go b/runtimes/google/rt/rt_test.go
index 0d1c7a0..ce3a6a4 100644
--- a/runtimes/google/rt/rt_test.go
+++ b/runtimes/google/rt/rt_test.go
@@ -32,6 +32,7 @@
 }
 
 func TestInit(t *testing.T) {
+	testutil.UnsetPrincipalEnvVars()
 	ctx, shutdown := veyron2.Init()
 	defer shutdown()
 
diff --git a/runtimes/google/rt/runtimex_test.go b/runtimes/google/rt/runtimex_test.go
index bd10057..6562b52 100644
--- a/runtimes/google/rt/runtimex_test.go
+++ b/runtimes/google/rt/runtimex_test.go
@@ -6,6 +6,7 @@
 	"v.io/core/veyron2"
 	"v.io/core/veyron2/context"
 
+	tsecurity "v.io/core/veyron/lib/testutil/security"
 	"v.io/core/veyron/runtimes/google/rt"
 	"v.io/core/veyron/security"
 )
@@ -17,6 +18,9 @@
 	if err != nil {
 		t.Fatal(err)
 	}
+	if ctx, err = r.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		t.Fatal(err)
+	}
 	return r, ctx, func() {
 		cancel()
 		shutdown()
diff --git a/runtimes/google/rt/shutdown_servers_test.go b/runtimes/google/rt/shutdown_servers_test.go
index db4ab6b..37320fe 100644
--- a/runtimes/google/rt/shutdown_servers_test.go
+++ b/runtimes/google/rt/shutdown_servers_test.go
@@ -16,6 +16,7 @@
 
 	"v.io/core/veyron/lib/modules"
 	"v.io/core/veyron/lib/signals"
+	tsecurity "v.io/core/veyron/lib/testutil/security"
 	"v.io/core/veyron/profiles"
 )
 
@@ -75,6 +76,10 @@
 	// shutdown is optional, but it's a good idea to clean up, especially
 	// since it takes care of flushing the logs before exiting.
 	defer shutdown()
+	var err error
+	if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		vlog.Fatal(err)
+	}
 
 	// This is part of the test setup -- we need a way to accept
 	// commands from the parent process to simulate Stop and
@@ -214,14 +219,17 @@
 func simpleServerProgram(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
 	// Initialize the runtime.  This is boilerplate.
 	ctx, shutdown := veyron2.Init()
-	defer shutdown()
-	// r.Cleanup is optional, but it's a good idea to clean up, especially
+	// Calling shutdown is optional, but it's a good idea to clean up, especially
 	// since it takes care of flushing the logs before exiting.
 	//
 	// We use defer to ensure this is the last thing in the program (to
 	// avoid shutting down the runtime while it may still be in use), and to
 	// allow it to execute even if a panic occurs down the road.
 	defer shutdown()
+	var err error
+	if ctx, err = veyron2.SetPrincipal(ctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+		vlog.Fatal(err)
+	}
 
 	// This is part of the test setup -- we need a way to accept
 	// commands from the parent process to simulate Stop and