Exemple #1
0
			Eventually(ErrorDialing("unix", socketPath)).ShouldNot(HaveOccurred())

			serverConnection, err = net.Dial("unix", socketPath)
			Expect(err).ToNot(HaveOccurred())

			responses = bufio.NewReader(serverConnection)
		})

		writeMessages := func(message proto.Message) {
			num, err := protocol.Messages(message).WriteTo(serverConnection)
			Expect(err).ToNot(HaveOccurred())
			Expect(num).ToNot(Equal(0))
		}

		readResponse := func(response proto.Message) {
			err := transport.ReadMessage(responses, response)
			Expect(err).ToNot(HaveOccurred())
		}

		It("stops accepting new connections", func() {
			go wardenServer.Stop()
			Eventually(ErrorDialing("unix", socketPath)).Should(HaveOccurred())
		})

		It("stops handling requests on existing connections", func() {
			writeMessages(&protocol.PingRequest{})
			readResponse(&protocol.PingResponse{})

			go wardenServer.Stop()

			// server was already reading a request
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	protocol "github.com/cloudfoundry-incubator/garden/protocol"
	"github.com/cloudfoundry-incubator/garden/transport"
)

var _ = Describe("Reading response messages over the wire", func() {
	Context("when a message of the expected type is received", func() {
		It("populates the response object and returns no error", func() {
			var echoResponse protocol.EchoResponse

			err := transport.ReadMessage(
				bufio.NewReader(protocol.Messages(&protocol.EchoRequest{
					Message: proto.String("some message"),
				})),
				&echoResponse,
			)

			Expect(err).ToNot(HaveOccurred())

			Expect(echoResponse.GetMessage()).To(Equal("some message"))
		})
	})

	Context("when the connection is broken", func() {
		It("returns an error", func() {
			var dummyResponse protocol.PingResponse

			payload := protocol.Messages(&protocol.PingRequest{})
Exemple #3
0
func (c *connection) readResponse(response proto.Message) error {
	c.readLock.Lock()
	defer c.readLock.Unlock()
	return transport.ReadMessage(c.read, response)
}