dep-protobuf/ruby/tests/stress.rb
Jason Lunn bb38ba5575 Fix separate issues in JRuby's "native" dup and inspect methods. (#15265)
Update the stress test to exercise `proto3_optional` fields.

Closes #15265

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15265 from protocolbuffers:fix_jruby_proto3_optional 4040e13a7b
PiperOrigin-RevId: 596028361
2024-01-05 10:41:01 -08:00

30 lines
767 B
Ruby
Executable file

#!/usr/bin/ruby
require 'google/protobuf'
require 'stress_pb'
require 'test/unit'
module StressTest
TestMessage = StressTestProtos::TestMessage
M = StressTestProtos::M
class StressTest < Test::Unit::TestCase
def get_msg
TestMessage.new(:a => 1000,
:b => [M.new(:foo => "hello"),
M.new(:foo => "world")])
end
def test_stress
m = get_msg
data = TestMessage.encode(m)
100_000.times do
mnew = TestMessage.decode(data)
mnew2 = mnew.dup
assert_equal m.inspect, mnew.inspect
assert_equal data, TestMessage.encode(mnew)
assert_equal m.inspect, mnew2.inspect
assert_equal data, TestMessage.encode(mnew2)
end
end
end
end