| Sergey Rogulenko | b86c99a | 2015-10-02 11:18:57 -0700 | [diff] [blame] | 1 | // 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 | |
| 5 | package tests |
| 6 | |
| 7 | import ( |
| 8 | "fmt" |
| 9 | "sync" |
| 10 | "testing" |
| 11 | |
| 12 | test "mojo/public/interfaces/bindings/tests/regression_tests" |
| 13 | ) |
| 14 | |
| 15 | type methodWithEmptyResponseValidator struct { |
| 16 | mu sync.Mutex |
| 17 | methodCalled bool |
| 18 | } |
| 19 | |
| 20 | func (v *methodWithEmptyResponseValidator) WithoutParameterAndEmptyResponse() error { |
| 21 | v.mu.Lock() |
| 22 | v.methodCalled = true |
| 23 | v.mu.Unlock() |
| 24 | return nil |
| 25 | } |
| 26 | |
| 27 | func (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. |
| 33 | func 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 Rudominer | 1f037be | 2016-04-05 16:14:00 -0700 | [diff] [blame] | 53 | proxy.Close_Proxy() |
| 54 | stub.Close() |
| Sergey Rogulenko | b86c99a | 2015-10-02 11:18:57 -0700 | [diff] [blame] | 55 | } |
| 56 | } |