wspr: Update to new reserved.Signature calls.

Related to this CL:
https://vanadium-review.googlesource.com/1362

Change-Id: Ia024469ed5ec9cb4df8ce50af64dc7ba0e280e20
MultiPart: 2/2
diff --git a/services/wsprd/app/app.go b/services/wsprd/app/app.go
index a4fd68a..400c2de 100644
--- a/services/wsprd/app/app.go
+++ b/services/wsprd/app/app.go
@@ -125,9 +125,6 @@
 	// the default implementation.
 	writerCreator func(id int32) lib.ClientWriter
 
-	// There is only one client per Controller since there is a single principal per app.
-	client ipc.Client
-
 	veyronProxyEP string
 
 	// Store for all the Blessings that javascript has a handle to.
@@ -148,15 +145,10 @@
 	if namespaceRoots != nil {
 		r.Namespace().SetRoots(namespaceRoots...)
 	}
-	client, err := r.NewClient()
-	if err != nil {
-		return nil, err
-	}
 
 	controller := &Controller{
 		ctx:            r.NewContext(),
 		cancel:         r.Cleanup,
-		client:         client,
 		writerCreator:  writerCreator,
 		listenSpec:     listenSpec,
 		blessingsStore: principal.NewJSBlessingsHandles(),
@@ -226,12 +218,9 @@
 }
 
 func (c *Controller) startCall(ctx *context.T, w lib.ClientWriter, msg *VeyronRPC) (ipc.Call, error) {
-	if c.client == nil {
-		return nil, verror2.Make(verror2.BadArg, ctx, "app.Controller.client")
-	}
 	methodName := lib.UppercaseFirstCharacter(msg.Method)
 	retryTimeoutOpt := options.RetryTimeout(time.Duration(*retryTimeout) * time.Second)
-	clientCall, err := c.client.StartCall(ctx, msg.Name, methodName, msg.InArgs, retryTimeoutOpt)
+	clientCall, err := veyron2.GetClient(ctx).StartCall(ctx, msg.Name, methodName, msg.InArgs, retryTimeoutOpt)
 	if err != nil {
 		return nil, fmt.Errorf("error starting call (name: %v, method: %v, args: %v): %v", msg.Name, methodName, msg.InArgs, err)
 	}
@@ -627,7 +616,7 @@
 
 func (c *Controller) getSignature(ctx *context.T, name string) ([]signature.Interface, error) {
 	retryTimeoutOpt := options.RetryTimeout(time.Duration(*retryTimeout) * time.Second)
-	return c.signatureManager.Signature(ctx, name, c.client, retryTimeoutOpt)
+	return c.signatureManager.Signature(ctx, name, retryTimeoutOpt)
 }
 
 // HandleSignatureRequest uses signature manager to get and cache signature of a remote server
diff --git a/services/wsprd/lib/signature_manager.go b/services/wsprd/lib/signature_manager.go
index 1078200..c616646 100644
--- a/services/wsprd/lib/signature_manager.go
+++ b/services/wsprd/lib/signature_manager.go
@@ -12,7 +12,7 @@
 )
 
 type SignatureManager interface {
-	Signature(ctx *context.T, name string, client ipc.Client, opts ...ipc.CallOpt) ([]signature.Interface, error)
+	Signature(ctx *context.T, name string, opts ...ipc.CallOpt) ([]signature.Interface, error)
 	FlushCacheEntry(name string)
 }
 
@@ -49,10 +49,10 @@
 
 const pkgPath = "v.io/wspr/veyron/services/wsprd/lib"
 
-// Signature uses the given client to fetch the signature for the given service
-// name.  It either returns the signature from the cache, or blocks until it
-// fetches the signature from the remote server.
-func (sm *signatureManager) Signature(ctx *context.T, name string, client ipc.Client, opts ...ipc.CallOpt) ([]signature.Interface, error) {
+// Signature fetches the signature for the given service name.  It either
+// returns the signature from the cache, or blocks until it fetches the
+// signature from the remote server.
+func (sm *signatureManager) Signature(ctx *context.T, name string, opts ...ipc.CallOpt) ([]signature.Interface, error) {
 	sm.Lock()
 	defer sm.Unlock()
 
@@ -62,7 +62,7 @@
 	}
 
 	// Fetch from the remote server.
-	sig, err := reserved.Signature(ctx, client, name, opts...)
+	sig, err := reserved.Signature(ctx, name, opts...)
 	if err != nil {
 		return nil, verror2.Make(verror2.NoServers, ctx, name, err)
 	}
diff --git a/services/wsprd/lib/signature_manager_test.go b/services/wsprd/lib/signature_manager_test.go
index 7dc519c..0a73903 100644
--- a/services/wsprd/lib/signature_manager_test.go
+++ b/services/wsprd/lib/signature_manager_test.go
@@ -5,8 +5,9 @@
 	"testing"
 
 	_ "v.io/core/veyron/profiles"
+	google_rt "v.io/core/veyron/runtimes/google/rt"
 	mocks_ipc "v.io/core/veyron/runtimes/google/testing/mocks/ipc"
-	"v.io/core/veyron2/rt"
+	"v.io/core/veyron2/context"
 	"v.io/core/veyron2/vdl"
 	"v.io/core/veyron2/vdl/vdlroot/src/signature"
 )
@@ -29,23 +30,26 @@
 	}
 }
 
-func client() *mocks_ipc.SimpleMockClient {
-	return mocks_ipc.NewSimpleClient(
+func initContext(t *testing.T) (*context.T, *mocks_ipc.SimpleMockClient) {
+	client := mocks_ipc.NewSimpleClient(
 		map[string][]interface{}{
 			"__Signature": []interface{}{wantSignature(), nil},
 		},
 	)
+	// The NewUninitializedContext call takes a runtime as its argument, which is
+	// used to set the runtime in the context.  None of our tests actually use the
+	// runtime, so we set an obviously bad value.
+	dummyRuntime := "ThisIsNotAnActualRuntime"
+	ctx := context.NewUninitializedContext(dummyRuntime)
+	ctx = google_rt.SetClient(ctx, client)
+	return ctx, client
 }
 
 func TestFetching(t *testing.T) {
-	runtime, err := rt.New()
-	if err != nil {
-		t.Fatalf("Could not initialize runtime: %s", err)
-	}
-	defer runtime.Cleanup()
+	ctx, _ := initContext(t)
 
 	sm := NewSignatureManager()
-	got, err := sm.Signature(runtime.NewContext(), name, client())
+	got, err := sm.Signature(ctx, name)
 	if err != nil {
 		t.Errorf(`Did not expect an error but got %v`, err)
 		return
@@ -56,14 +60,10 @@
 }
 
 func TestThatCachedAfterFetching(t *testing.T) {
-	runtime, err := rt.New()
-	if err != nil {
-		t.Fatalf("Could not initialize runtime: %s", err)
-	}
-	defer runtime.Cleanup()
+	ctx, _ := initContext(t)
 
 	sm := NewSignatureManager().(*signatureManager)
-	sig, _ := sm.Signature(runtime.NewContext(), name, client())
+	sig, _ := sm.Signature(ctx, name)
 	cache, ok := sm.cache[name]
 	if !ok {
 		t.Errorf(`Signature manager did not cache the results`)
@@ -75,18 +75,12 @@
 }
 
 func TestThatCacheIsUsed(t *testing.T) {
-	runtime, err := rt.New()
-	if err != nil {
-		t.Fatalf("Could not initialize runtime: %s", err)
-	}
-	defer runtime.Cleanup()
-
-	client := client()
-	sm := NewSignatureManager()
+	ctx, client := initContext(t)
 
 	// call twice
-	sm.Signature(runtime.NewContext(), name, client)
-	sm.Signature(runtime.NewContext(), name, client)
+	sm := NewSignatureManager()
+	sm.Signature(ctx, name)
+	sm.Signature(ctx, name)
 
 	// expect number of calls to Signature method of client to still be 1 since cache
 	// should have been used despite the second call
@@ -96,22 +90,17 @@
 }
 
 func TestThatLastAccessedGetUpdated(t *testing.T) {
-	runtime, err := rt.New()
-	if err != nil {
-		t.Fatalf("Could not initialize runtime: %s", err)
-	}
-	defer runtime.Cleanup()
+	ctx, _ := initContext(t)
 
-	client := client()
 	sm := NewSignatureManager().(*signatureManager)
-	sm.Signature(runtime.NewContext(), name, client)
+	sm.Signature(ctx, name)
 	// make last accessed be in the past to account for the fact that
 	// two consecutive calls to time.Now() can return identical values.
 	sm.cache[name].lastAccessed = sm.cache[name].lastAccessed.Add(-ttl / 2)
 	prevAccess := sm.cache[name].lastAccessed
 
 	// access again
-	sm.Signature(runtime.NewContext(), name, client)
+	sm.Signature(ctx, name)
 	newAccess := sm.cache[name].lastAccessed
 
 	if !newAccess.After(prevAccess) {
@@ -120,21 +109,16 @@
 }
 
 func TestThatTTLExpires(t *testing.T) {
-	runtime, err := rt.New()
-	if err != nil {
-		t.Fatalf("Could not initialize runtime: %s", err)
-	}
-	defer runtime.Cleanup()
+	ctx, client := initContext(t)
 
-	client := client()
 	sm := NewSignatureManager().(*signatureManager)
-	sm.Signature(runtime.NewContext(), name, client)
+	sm.Signature(ctx, name)
 
 	// make last accessed go over the ttl
 	sm.cache[name].lastAccessed = sm.cache[name].lastAccessed.Add(-2 * ttl)
 
 	// make a second call
-	sm.Signature(runtime.NewContext(), name, client)
+	sm.Signature(ctx, name)
 
 	// expect number of calls to Signature method of client to be 2 since cache should have expired
 	if client.TimesCalled("__Signature") != 2 {