OLD | NEW |
(Empty) | |
| 1 # Copyright 2015, Google Inc. |
| 2 # All rights reserved. |
| 3 # |
| 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are |
| 6 # met: |
| 7 # |
| 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. |
| 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
| 30 require 'grpc' |
| 31 |
| 32 def load_test_certs |
| 33 test_root = File.join(File.dirname(__FILE__), 'testdata') |
| 34 files = ['ca.pem', 'server1.key', 'server1.pem'] |
| 35 files.map { |f| File.open(File.join(test_root, f)).read } |
| 36 end |
| 37 |
| 38 describe GRPC::Core::Channel do |
| 39 let(:fake_host) { 'localhost:0' } |
| 40 let(:cq) { GRPC::Core::CompletionQueue.new } |
| 41 |
| 42 def create_test_cert |
| 43 GRPC::Core::ChannelCredentials.new(load_test_certs[0]) |
| 44 end |
| 45 |
| 46 shared_examples '#new' do |
| 47 it 'take a host name without channel args' do |
| 48 blk = proc do |
| 49 GRPC::Core::Channel.new('dummy_host', nil, :this_channel_is_insecure) |
| 50 end |
| 51 expect(&blk).not_to raise_error |
| 52 end |
| 53 |
| 54 it 'does not take a hash with bad keys as channel args' do |
| 55 blk = construct_with_args(Object.new => 1) |
| 56 expect(&blk).to raise_error TypeError |
| 57 blk = construct_with_args(1 => 1) |
| 58 expect(&blk).to raise_error TypeError |
| 59 end |
| 60 |
| 61 it 'does not take a hash with bad values as channel args' do |
| 62 blk = construct_with_args(symbol: Object.new) |
| 63 expect(&blk).to raise_error TypeError |
| 64 blk = construct_with_args('1' => {}) |
| 65 expect(&blk).to raise_error TypeError |
| 66 end |
| 67 |
| 68 it 'can take a hash with a symbol key as channel args' do |
| 69 blk = construct_with_args(a_symbol: 1) |
| 70 expect(&blk).to_not raise_error |
| 71 end |
| 72 |
| 73 it 'can take a hash with a string key as channel args' do |
| 74 blk = construct_with_args('a_symbol' => 1) |
| 75 expect(&blk).to_not raise_error |
| 76 end |
| 77 |
| 78 it 'can take a hash with a string value as channel args' do |
| 79 blk = construct_with_args(a_symbol: '1') |
| 80 expect(&blk).to_not raise_error |
| 81 end |
| 82 |
| 83 it 'can take a hash with a symbol value as channel args' do |
| 84 blk = construct_with_args(a_symbol: :another_symbol) |
| 85 expect(&blk).to_not raise_error |
| 86 end |
| 87 |
| 88 it 'can take a hash with a numeric value as channel args' do |
| 89 blk = construct_with_args(a_symbol: 1) |
| 90 expect(&blk).to_not raise_error |
| 91 end |
| 92 |
| 93 it 'can take a hash with many args as channel args' do |
| 94 args = Hash[127.times.collect { |x| [x.to_s, x] }] |
| 95 blk = construct_with_args(args) |
| 96 expect(&blk).to_not raise_error |
| 97 end |
| 98 end |
| 99 |
| 100 describe '#new for secure channels' do |
| 101 def construct_with_args(a) |
| 102 proc { GRPC::Core::Channel.new('dummy_host', a, create_test_cert) } |
| 103 end |
| 104 |
| 105 it_behaves_like '#new' |
| 106 end |
| 107 |
| 108 describe '#new for insecure channels' do |
| 109 it_behaves_like '#new' |
| 110 |
| 111 def construct_with_args(a) |
| 112 proc do |
| 113 GRPC::Core::Channel.new('dummy_host', a, :this_channel_is_insecure) |
| 114 end |
| 115 end |
| 116 end |
| 117 |
| 118 describe '#create_call' do |
| 119 it 'creates a call OK' do |
| 120 ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure) |
| 121 |
| 122 deadline = Time.now + 5 |
| 123 |
| 124 blk = proc do |
| 125 ch.create_call(cq, nil, nil, 'dummy_method', nil, deadline) |
| 126 end |
| 127 expect(&blk).to_not raise_error |
| 128 end |
| 129 |
| 130 it 'raises an error if called on a closed channel' do |
| 131 ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure) |
| 132 ch.close |
| 133 |
| 134 deadline = Time.now + 5 |
| 135 blk = proc do |
| 136 ch.create_call(cq, nil, nil, 'dummy_method', nil, deadline) |
| 137 end |
| 138 expect(&blk).to raise_error(RuntimeError) |
| 139 end |
| 140 end |
| 141 |
| 142 describe '#destroy' do |
| 143 it 'destroys a channel ok' do |
| 144 ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure) |
| 145 blk = proc { ch.destroy } |
| 146 expect(&blk).to_not raise_error |
| 147 end |
| 148 |
| 149 it 'can be called more than once without error' do |
| 150 ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure) |
| 151 blk = proc { ch.destroy } |
| 152 blk.call |
| 153 expect(&blk).to_not raise_error |
| 154 end |
| 155 end |
| 156 |
| 157 describe '::SSL_TARGET' do |
| 158 it 'is a symbol' do |
| 159 expect(GRPC::Core::Channel::SSL_TARGET).to be_a(Symbol) |
| 160 end |
| 161 end |
| 162 |
| 163 describe '#close' do |
| 164 it 'closes a channel ok' do |
| 165 ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure) |
| 166 blk = proc { ch.close } |
| 167 expect(&blk).to_not raise_error |
| 168 end |
| 169 |
| 170 it 'can be called more than once without error' do |
| 171 ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure) |
| 172 blk = proc { ch.close } |
| 173 blk.call |
| 174 expect(&blk).to_not raise_error |
| 175 end |
| 176 end |
| 177 end |
OLD | NEW |