1 #!/usr/bin/ruby 2 3 require 'google/protobuf' 4 require 'test/unit' 5 6 module StressTest 7 pool = Google::Protobuf::DescriptorPool.new 8 pool.build do 9 add_message "TestMessage" do 10 optional :a, :int32, 1 11 repeated :b, :message, 2, "M" 12 end 13 add_message "M" do 14 optional :foo, :string, 1 15 end 16 end 17 18 TestMessage = pool.lookup("TestMessage").msgclass 19 M = pool.lookup("M").msgclass 20 21 class StressTest < Test::Unit::TestCase 22 def get_msg 23 TestMessage.new(:a => 1000, 24 :b => [M.new(:foo => "hello"), 25 M.new(:foo => "world")]) 26 end 27 def test_stress 28 m = get_msg 29 data = TestMessage.encode(m) 30 100_000.times do 31 mnew = TestMessage.decode(data) 32 mnew = mnew.dup 33 assert_equal mnew.inspect, m.inspect 34 assert TestMessage.encode(mnew) == data 35 end 36 end 37 end 38 end 39