aboutsummaryrefslogtreecommitdiffhomepage
path: root/ruby/tests/stress.rb
diff options
context:
space:
mode:
authorGravatar Chris Fallin <cfallin@c1f.net>2014-11-18 14:19:58 -0800
committerGravatar Chris Fallin <cfallin@c1f.net>2014-12-09 16:55:59 -0800
commit973f425725f1cc18211992792f2aed83d3d73831 (patch)
treeda0022d2cbe3a0700c02765a02e1be5a8b0c4f30 /ruby/tests/stress.rb
parenta0d9c59a7604139401cab78a27542b23f5724c19 (diff)
Provide a Ruby extension.
This adds a Ruby extension in ruby/ that is based on the 'upb' library (now included as a submodule), and adds support for Ruby code generation to the protoc compiler.
Diffstat (limited to 'ruby/tests/stress.rb')
-rw-r--r--ruby/tests/stress.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/ruby/tests/stress.rb b/ruby/tests/stress.rb
new file mode 100644
index 00000000..cc4bbf5c
--- /dev/null
+++ b/ruby/tests/stress.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/ruby
+
+require 'protobuf'
+require 'test/unit'
+
+module StressTest
+ pool = Google::Protobuf::DescriptorPool.new
+ pool.build do
+ add_message "TestMessage" do
+ optional :a, :int32, 1
+ repeated :b, :message, 2, "M"
+ end
+ add_message "M" do
+ optional :foo, :string, 1
+ end
+ end
+
+ TestMessage = pool.lookup("TestMessage").msgclass
+ M = pool.lookup("M").msgclass
+
+ 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)
+ mnew = mnew.dup
+ assert mnew.inspect == m.inspect
+ assert TestMessage.encode(mnew) == data
+ end
+ end
+ end
+end