diff options
author | Alexander Polcyn <apolcyn@google.com> | 2017-04-27 00:26:25 -0700 |
---|---|---|
committer | Alexander Polcyn <apolcyn@google.com> | 2017-05-09 22:52:32 -0700 |
commit | b2c0b7bc7411c0914e2f65d56096ecde1a207b53 (patch) | |
tree | 9cc63524ed7318f6b60e03dcdeb085fb36d5bb72 /src/ruby/spec | |
parent | 6be939708977833104b7f81b7b52a02923ed3152 (diff) |
constant state watch without timeouts
Diffstat (limited to 'src/ruby/spec')
-rw-r--r-- | src/ruby/spec/channel_connection_spec.rb | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/ruby/spec/channel_connection_spec.rb b/src/ruby/spec/channel_connection_spec.rb index 940d68b9b0..b3edec8f93 100644 --- a/src/ruby/spec/channel_connection_spec.rb +++ b/src/ruby/spec/channel_connection_spec.rb @@ -28,6 +28,10 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require 'grpc' +require 'timeout' + +include Timeout +include GRPC::Core # A test message class EchoMsg @@ -62,7 +66,7 @@ end EchoStub = EchoService.rpc_stub_class def start_server(port = 0) - @srv = GRPC::RpcServer.new + @srv = GRPC::RpcServer.new(pool_size: 1) server_port = @srv.add_http2_port("localhost:#{port}", :this_port_is_insecure) @srv.handle(EchoService) @server_thd = Thread.new { @srv.run } @@ -138,4 +142,33 @@ describe 'channel connection behavior' do stop_server end + + it 'observably connects and reconnects to transient server' \ + ' when using the channel state API' do + timeout(180) do + port = start_server + ch = GRPC::Core::Channel.new("localhost:#{port}", {}, + :this_channel_is_insecure) + stop_server + + thds = [] + 50.times do + thds << Thread.new do + while ch.connectivity_state(true) != ConnectivityStates::READY + ch.watch_connectivity_state( + ConnectivityStates::READY, Time.now + 60) + break + end + end + end + + sleep 0.01 + + start_server(port) + + thds.each(&:join) + + stop_server + end + end end |