1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/bootstraptest/test_fiber.rb
Koichi Sasada 603ab70961 support concurrent btest execution
* `-j` option for concurrent test with threads
  * `-jN` uses N threads
  * `-j` uses nproc/2 threads
* Introduce `BT` struct to manage configurations
* Introduce `Assertion` to manage all assertions
* Remove all toplevel instance variables
* Show elapsed seconds at last

```
$ time make btest
...
real    0m37.319s
user    0m26.221s
sys     0m16.534s

$ time make btest TESTOPTS=-j
...
real    0m11.812s
user    0m36.667s
sys     0m21.872s
```
2022-02-06 03:05:47 +09:00

39 lines
697 B
Ruby

show_limit %q{
fibers = []
begin
fiber = Fiber.new{Fiber.yield}
fiber.resume
fibers << fiber
raise Exception, "skipping" if fibers.count >= 10_000
rescue Exception => error
puts "Fiber count: #{fibers.count} (#{error})"
break
end while true
}
assert_equal %q{ok}, %q{
Fiber.new{
}.resume
:ok
}
assert_equal %q{ok}, %q{
100.times.collect{Fiber.new{}}
:ok
}
assert_equal %q{ok}, %q{
fibers = 1000.times.collect{Fiber.new{Fiber.yield}}
fibers.each(&:resume)
fibers.each(&:resume)
:ok
}
assert_normal_exit %q{
at_exit { Fiber.new{}.resume }
}
assert_normal_exit %q{
Fiber.new(&Object.method(:class_eval)).resume("foo")
}, '[ruby-dev:34128]'