Sha256: ec2d63852ad78baa57f673fcdc4c1200c8fa0482161eef0a540ee81bec42e8a3

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'
require 'h8'

describe 'threading' do
  before do
    @counter_script = <<-End
            var count = 0;
            var endTime = end*1000 + 150;
            while( new Date().getTime() < endTime ) count++;
            (count);
    End
    @context         = H8::Context.new
    @context[:print] = -> (*args) {
      puts "D: #{args.join(',')}"
    }
    Thread.pass
    @end_time      = Time.now.to_i + 1
    @context[:end] = @end_time
  end

  it 'should run JS/ruby threads in parallel' do
    cnt2 = 0
    Thread.start {
      cnt2 += 1 while Time.now.to_i < @end_time
    }
    res  = @context.eval @counter_script, timeout: 5000
    cnt  = cnt2
    fail "JS thread does not run in parallel" if res < 1
    fail "JS thread does not run in parallel" if cnt < 1
    (res / cnt).should < 16
  end


  it 'should run JS callables in threads in parallel' do
    fn = @context.eval "res = function (end) { #{@counter_script} return count; }"
    cnt2 = 0
    Thread.start {
      cnt2 += 1 while Time.now.to_i < @end_time
    }
    res  = fn.call(@end_time)
    cnt  = cnt2
    fail "JS thread does not run in parallel" if res < 1
    fail "JS thread does not run in parallel" if cnt < 1
    (res / cnt).should < 16
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
h8-0.5.5 spec/threading_spec.rb
h8-0.5.4 spec/threading_spec.rb
h8-0.5.2 spec/threading_spec.rb
h8-0.5.1 spec/threading_spec.rb
h8-0.5.0 spec/threading_spec.rb
h8-0.4.11 spec/threading_spec.rb
h8-0.4.10 spec/threading_spec.rb
h8-0.4.8 spec/threading_spec.rb
h8-0.4.5 spec/threading_spec.rb
h8-0.4.0 spec/threading_spec.rb
h8-0.3.0 spec/threading_spec.rb
h8-0.2.5 spec/threading_spec.rb
h8-0.2.4 spec/threading_spec.rb
h8-0.2.3 spec/threading_spec.rb
h8-0.2.2 spec/threading_spec.rb