Exemplo n.º 1
0
func ReadMessage(read *bufio.Reader, response proto.Message) error {
	payload, err := readPayload(read)
	if err != nil {
		return err
	}

	message := &protocol.Message{}
	err = proto.Unmarshal(payload, message)
	if err != nil {
		return err
	}

	// error response from server
	if message.GetType() == protocol.Message_Type(1) {
		errorResponse := &protocol.ErrorResponse{}
		err = proto.Unmarshal(message.Payload, errorResponse)
		if err != nil {
			return errors.New("error unmarshalling error!")
		}

		return &WardenError{
			Message:   errorResponse.GetMessage(),
			Data:      errorResponse.GetData(),
			Backtrace: errorResponse.GetBacktrace(),
		}
	}

	responseType := protocol.TypeForMessage(response)
	if message.GetType() != responseType {
		return &TypeMismatchError{
			Expected: responseType,
			Received: message.GetType(),
		}
	}

	return proto.Unmarshal(message.GetPayload(), response)
}
						"backtrace line 1",
						"backtrace line 2",
					},
				},
			))
		})
	})

	Context("when a message of the wrong type is received", func() {
		It("returns a TypeMismatchError", func() {
			var dummyResponse protocol.PingResponse

			actualResponse := &protocol.EchoResponse{
				Message: proto.String("some message"),
			}

			err := message_reader.ReadMessage(
				bufio.NewReader(protocol.Messages(actualResponse)),
				&dummyResponse,
			)

			Expect(err).To(Equal(
				&message_reader.TypeMismatchError{
					Expected: protocol.TypeForMessage(&dummyResponse),
					Received: protocol.TypeForMessage(actualResponse),
				},
			))
		})
	})
})
Exemplo n.º 3
0
					fakeContainer := container.(*fake_backend.FakeContainer)

					fakeContainer.StreamedJobChunks = []backend.JobStream{
						{
							ExitStatus: &exitStatus,
						},
					}
				})

				It("does not wait for it to complete", func() {
					writeMessages(request)

					time.Sleep(10 * time.Millisecond)

					before := time.Now()

					wardenServer.Stop()

					Expect(time.Since(before)).To(BeNumerically("<", 50*time.Millisecond))

					response := protocol.ResponseMessageForType(protocol.TypeForMessage(request))
					readResponse(response)

					_, err := protocol.Messages(&protocol.PingRequest{}).WriteTo(serverConnection)
					Expect(err).To(HaveOccurred())
				})
			})
		}
	})
})