forked from rubinius/rubinius
/
thread_spec.rb
53 lines (42 loc) · 1.14 KB
/
thread_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require File.dirname(__FILE__) + '/spec_helper'
load_extension("thread")
describe "CApiThreadSpecs" do
before :each do
@t = CApiThreadSpecs.new
ScratchPad.clear
end
describe "rb_thread_select" do
it "returns true if an fd is ready to read" do
read, write = IO.pipe
@t.rb_thread_select_fd(read.to_i, 0).should == false
write << "1"
@t.rb_thread_select_fd(read.to_i, 0).should == true
end
it "does not block all threads" do
t = Thread.new do
sleep 0.25
ScratchPad.record :inner
end
Thread.pass while t.status and t.status != "sleep"
@t.rb_thread_select(500_000)
t.alive?.should be_false
ScratchPad.recorded.should == :inner
t.join
end
end
describe "rb_thread_alone" do
it "returns 0" do
@t.rb_thread_alone.should == 0
end
end
describe "rb_thread_current" do
it "equals Thread.current" do
@t.rb_thread_current.should == Thread.current
end
end
describe "rb_thread_blocking_region" do
it "runs a C function with the global lock unlocked" do
@t.rb_thread_blocking_region.should be_true
end
end
end