Exemplo n.º 1
0
func TestStubClosesPipe(t *testing.T) {
	request, pointer := echo.CreateMessagePipeForEcho()
	// Create a message with valid header and invalid payload and send it.
	header := bindings.MessageHeader{0, bindings.MessageIsResponseFlag, 1}
	message, err := bindings.EncodeMessage(header, &header)
	if err != nil {
		t.Fatalf("Error encoding message: %v", err)
	}
	pointerPipe := pointer.PassMessagePipe()
	if r := pointerPipe.WriteMessage(message.Bytes, nil, system.MOJO_WRITE_MESSAGE_FLAG_NONE); r != system.MOJO_RESULT_OK {
		t.Fatalf("Can't send a message: %v", r)
	}

	// Make echo request with response (that is already sent).
	echoStub := echo.NewEchoStub(request, &echoImpl{}, waiter)
	if err := echoStub.ServeRequest(); err == nil {
		t.Fatalf("Message is invalid, error expected")
	}

	// Wait for the pipe to be closed.
	waitResponseChan := make(chan bindings.WaitResponse)
	waiter.AsyncWait(pointerPipe, system.MOJO_HANDLE_SIGNAL_PEER_CLOSED, waitResponseChan)
	waitResponse := <-waitResponseChan
	if waitResponse.Result != system.MOJO_RESULT_OK {
		t.Fatalf("Error waiting on pipe to be closed: %v", waitResponse.Result)
	}
	pointerPipe.Close()
}
Exemplo n.º 2
0
func (delegate *EchoDelegate) Create(request echo.Echo_Request) {
	stub := echo.NewEchoStub(request, &EchoImpl{}, bindings.GetAsyncWaiter())
	go func() {
		if err := stub.ServeRequest(); err != nil {
			panic(err)
		}
		stub.Close()
		delegate.Wg.Done()
	}()
}
Exemplo n.º 3
0
func (delegate *EchoServerDelegate) Create(request echo.Echo_Request) {
	stub := echo.NewEchoStub(request, &EchoImpl{}, bindings.GetAsyncWaiter())
	delegate.stubs = append(delegate.stubs, stub)
	go func() {
		for {
			if err := stub.ServeRequest(); err != nil {
				connectionError, ok := err.(*bindings.ConnectionError)
				if !ok || !connectionError.Closed() {
					log.Println(err)
				}
				break
			}
		}
	}()
}