blob: e948f783c9997e9f833c2bddc9c05e3cb694bf95 [file] [log] [blame]
Sergey Rogulenkob86c99a2015-10-02 11:18:57 -07001// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package tests
6
7import (
8 "fmt"
9 "sync"
10 "testing"
11
12 test "mojo/public/interfaces/bindings/tests/regression_tests"
13)
14
15type methodWithEmptyResponseValidator struct {
16 mu sync.Mutex
17 methodCalled bool
18}
19
20func (v *methodWithEmptyResponseValidator) WithoutParameterAndEmptyResponse() error {
21 v.mu.Lock()
22 v.methodCalled = true
23 v.mu.Unlock()
24 return nil
25}
26
27func (v *methodWithEmptyResponseValidator) WithParameterAndEmptyResponse(b bool) error {
28 return nil
29}
30
31// TestCheckMethodWithEmptyResponse checks that the proxy waits for a server
32// response if a method has 0 response arguments.
33func TestCheckMethodWithEmptyResponse(t *testing.T) {
34 iterations := 50
35 for i := 0; i < iterations; i++ {
36 interfaceRequest, interfacePointer := test.CreateMessagePipeForCheckMethodWithEmptyResponse()
37 proxy := test.NewCheckMethodWithEmptyResponseProxy(interfacePointer, waiter)
38 v := &methodWithEmptyResponseValidator{}
39 stub := test.NewCheckMethodWithEmptyResponseStub(interfaceRequest, v, waiter)
40 go func() {
41 if err := stub.ServeRequest(); err != nil {
42 panic(fmt.Sprintf("can't serve a request: %v", err))
43 }
44 }()
45 if err := proxy.WithoutParameterAndEmptyResponse(); err != nil {
46 t.Fatalf("error sending request: %v", err)
47 }
48 v.mu.Lock()
49 if !v.methodCalled {
50 t.Fatal("proxy returned from the call before the stub sent the response")
51 }
52 v.mu.Unlock()
Mitch Rudominer1f037be2016-04-05 16:14:00 -070053 proxy.Close_Proxy()
54 stub.Close()
Sergey Rogulenkob86c99a2015-10-02 11:18:57 -070055 }
56}