From fce4553353e918fa571df497064ee84b5f19bce1 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 19 Jun 2012 04:50:36 -0500 Subject: [PATCH] Add threading spec. Thanks to @dturnbull for providing these cases in #98. --- spec/threading_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 spec/threading_spec.rb diff --git a/spec/threading_spec.rb b/spec/threading_spec.rb new file mode 100644 index 0000000..e1c891d --- /dev/null +++ b/spec/threading_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe "using v8 from multiple threads" do + + it "creates contexts from within threads" do + 10.times.collect do + Thread.new do + V8::Context.new + end + end.each {|t| t.join} + V8::Context.new + end + + it "executes codes on multiple threads simultaneously" do + 5.times.collect{V8::Context.new}.collect do |ctx| + Thread.new do + ctx['x'] = 99 + while ctx['x'] > 0 + ctx.eval 'for (i=10000;i;i--){};--x' + end + end + end.each {|t| t.join} + end +end \ No newline at end of file