Example #1
0
func closeClient(c *gc.C, client *rpc.Conn, srvDone <-chan error) {
	err := client.Close()
	c.Assert(err, gc.IsNil)
	err = chanReadError(c, srvDone, "server done")
	c.Assert(err, gc.IsNil)
}
Example #2
0
func testBadCall(
	c *gc.C,
	client *rpc.Conn,
	clientNotifier, serverNotifier *notifier,
	req rpc.Request,
	expectedErr string,
	expectedErrCode string,
	requestKnown bool,
) {
	clientNotifier.reset()
	serverNotifier.reset()
	err := client.Call(req, nil, nil)
	msg := expectedErr
	if expectedErrCode != "" {
		msg += " (" + expectedErrCode + ")"
	}
	c.Assert(err, gc.ErrorMatches, regexp.QuoteMeta("request error: "+msg))

	// Test that there was a notification for the client request.
	c.Assert(clientNotifier.clientRequests, gc.HasLen, 1)
	clientReq := clientNotifier.clientRequests[0]
	requestId := clientReq.hdr.RequestId
	c.Assert(clientReq, gc.DeepEquals, requestEvent{
		hdr: rpc.Header{
			RequestId: requestId,
			Request:   req,
		},
		body: struct{}{},
	})
	// Test that there was a notification for the client reply.
	c.Assert(clientNotifier.clientReplies, gc.HasLen, 1)
	clientReply := clientNotifier.clientReplies[0]
	c.Assert(clientReply, gc.DeepEquals, replyEvent{
		req: req,
		hdr: rpc.Header{
			RequestId: requestId,
			Error:     expectedErr,
			ErrorCode: expectedErrCode,
		},
	})

	// Test that there was a notification for the server request.
	c.Assert(serverNotifier.serverRequests, gc.HasLen, 1)
	serverReq := serverNotifier.serverRequests[0]

	// From docs on ServerRequest:
	// 	If the request was not recognized or there was
	//	an error reading the body, body will be nil.
	var expectBody interface{}
	if requestKnown {
		expectBody = struct{}{}
	}
	c.Assert(serverReq, gc.DeepEquals, requestEvent{
		hdr: rpc.Header{
			RequestId: requestId,
			Request:   req,
		},
		body: expectBody,
	})

	// Test that there was a notification for the server reply.
	c.Assert(serverNotifier.serverReplies, gc.HasLen, 1)
	serverReply := serverNotifier.serverReplies[0]
	c.Assert(serverReply, gc.DeepEquals, replyEvent{
		hdr: rpc.Header{
			RequestId: requestId,
			Error:     expectedErr,
			ErrorCode: expectedErrCode,
		},
		req:  req,
		body: struct{}{},
	})
}