Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
| 2 | |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | # Copyright 2015 gRPC authors. |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 4 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 8 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 10 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 16 | |
Alexander Polcyn | d1143ab | 2017-04-16 10:26:44 -0700 | [diff] [blame] | 17 | # For GRPC::Core classes, which use the grpc c-core, object init |
| 18 | # is interesting because it's related to overall library init. |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 19 | |
| 20 | require_relative './end2end_common' |
| 21 | |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 22 | def construct_many(test_proc) |
| 23 | thds = [] |
| 24 | 4.times do |
| 25 | thds << Thread.new do |
| 26 | 20.times do |
| 27 | test_proc.call |
| 28 | end |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 29 | end |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 30 | end |
| 31 | 20.times do |
| 32 | test_proc.call |
| 33 | end |
| 34 | thds.each(&:join) |
| 35 | end |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 36 | |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 37 | def run_gc_stress_test(test_proc) |
| 38 | GC.disable |
| 39 | construct_many(test_proc) |
Alexander Polcyn | deeed7f | 2017-04-16 13:31:58 -0700 | [diff] [blame] | 40 | |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 41 | GC.enable |
| 42 | construct_many(test_proc) |
| 43 | |
Alexander Polcyn | 010ea65 | 2017-09-01 09:06:11 -0700 | [diff] [blame] | 44 | GC.start |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 45 | construct_many(test_proc) |
| 46 | end |
| 47 | |
Alexander Polcyn | fd4cbb7 | 2017-05-17 09:57:25 -0700 | [diff] [blame] | 48 | def run_concurrency_stress_test(test_proc) |
Alexander Polcyn | fd4cbb7 | 2017-05-17 09:57:25 -0700 | [diff] [blame] | 49 | 100.times do |
Alexander Polcyn | 916893b | 2017-05-17 10:05:39 -0700 | [diff] [blame] | 50 | Thread.new do |
Alexander Polcyn | fd4cbb7 | 2017-05-17 09:57:25 -0700 | [diff] [blame] | 51 | test_proc.call |
| 52 | end |
| 53 | end |
| 54 | |
Alexander Polcyn | 916893b | 2017-05-17 10:05:39 -0700 | [diff] [blame] | 55 | test_proc.call |
| 56 | |
Alexander Polcyn | 5c6dda8 | 2017-05-17 13:08:34 -0700 | [diff] [blame] | 57 | fail 'exception thrown while child thread initing class' |
Alexander Polcyn | fd4cbb7 | 2017-05-17 09:57:25 -0700 | [diff] [blame] | 58 | end |
| 59 | |
| 60 | # default (no gc_stress and no concurrency_stress) |
| 61 | def run_default_test(test_proc) |
| 62 | thd = Thread.new do |
| 63 | test_proc.call |
| 64 | end |
| 65 | test_proc.call |
Alexander Polcyn | 5c6dda8 | 2017-05-17 13:08:34 -0700 | [diff] [blame] | 66 | thd.join |
Alexander Polcyn | fd4cbb7 | 2017-05-17 09:57:25 -0700 | [diff] [blame] | 67 | end |
| 68 | |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 69 | def get_test_proc(grpc_class) |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 70 | case grpc_class |
| 71 | when 'channel' |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 72 | return proc do |
Alexander Polcyn | d1143ab | 2017-04-16 10:26:44 -0700 | [diff] [blame] | 73 | GRPC::Core::Channel.new('dummy_host', nil, :this_channel_is_insecure) |
| 74 | end |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 75 | when 'server' |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 76 | return proc do |
Alexander Polcyn | d1143ab | 2017-04-16 10:26:44 -0700 | [diff] [blame] | 77 | GRPC::Core::Server.new({}) |
| 78 | end |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 79 | when 'channel_credentials' |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 80 | return proc do |
Alexander Polcyn | d1143ab | 2017-04-16 10:26:44 -0700 | [diff] [blame] | 81 | GRPC::Core::ChannelCredentials.new |
| 82 | end |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 83 | when 'call_credentials' |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 84 | return proc do |
Alexander Polcyn | d1143ab | 2017-04-16 10:26:44 -0700 | [diff] [blame] | 85 | GRPC::Core::CallCredentials.new(proc { |noop| noop }) |
| 86 | end |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 87 | when 'compression_options' |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 88 | return proc do |
Alexander Polcyn | d1143ab | 2017-04-16 10:26:44 -0700 | [diff] [blame] | 89 | GRPC::Core::CompressionOptions.new |
| 90 | end |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 91 | else |
| 92 | fail "bad --grpc_class=#{grpc_class} param" |
| 93 | end |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 94 | end |
Alexander Polcyn | deeed7f | 2017-04-16 13:31:58 -0700 | [diff] [blame] | 95 | |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 96 | def main |
| 97 | grpc_class = '' |
Alexander Polcyn | fd4cbb7 | 2017-05-17 09:57:25 -0700 | [diff] [blame] | 98 | stress_test = '' |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 99 | OptionParser.new do |opts| |
| 100 | opts.on('--grpc_class=P', String) do |p| |
| 101 | grpc_class = p |
| 102 | end |
Alexander Polcyn | fd4cbb7 | 2017-05-17 09:57:25 -0700 | [diff] [blame] | 103 | opts.on('--stress_test=P') do |p| |
| 104 | stress_test = p |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 105 | end |
| 106 | end.parse! |
| 107 | |
| 108 | test_proc = get_test_proc(grpc_class) |
| 109 | |
Alexander Polcyn | fd4cbb7 | 2017-05-17 09:57:25 -0700 | [diff] [blame] | 110 | # the different test configs need to be ran |
| 111 | # in separate processes, since each one tests |
| 112 | # clean shutdown in a different way |
| 113 | case stress_test |
| 114 | when 'gc' |
| 115 | p 'run gc stress' |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 116 | run_gc_stress_test(test_proc) |
Alexander Polcyn | fd4cbb7 | 2017-05-17 09:57:25 -0700 | [diff] [blame] | 117 | when 'concurrency' |
| 118 | p 'run concurrency stress' |
| 119 | run_concurrency_stress_test(test_proc) |
| 120 | when '' |
| 121 | p 'run default' |
| 122 | run_default_test(test_proc) |
| 123 | else |
| 124 | fail "bad --stress_test=#{stress_test} param" |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 125 | end |
Alexander Polcyn | 4736e01 | 2017-04-14 17:32:00 -0700 | [diff] [blame] | 126 | end |
| 127 | |
| 128 | main |