File: blocking_flag_spec.rb

package info (click to toggle)
ruby-serverengine 2.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 404 kB
  • sloc: ruby: 3,444; makefile: 3
file content (59 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download
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
54
55
56
57
58
59

describe ServerEngine::BlockingFlag do
  subject { BlockingFlag.new }

  it 'set and reset' do
    should_not be_set
    subject.set!
    should be_set
    subject.reset!
    should_not be_set
  end

  it 'set! and reset! return whether it toggled the state' do
    subject.reset!.should == false
    subject.set!.should == true
    subject.set!.should == false
    subject.reset!.should == true
  end

  it 'wait_for_set timeout' do
    start = Time.now

    subject.wait_for_set(0.01)
    elapsed = Time.now - start

    elapsed.should >= 0.01
  end

  it 'wait_for_reset timeout' do
    subject.set!

    start = Time.now

    subject.wait_for_reset(0.01)
    elapsed = Time.now - start

    elapsed.should >= 0.01
  end

  it 'wait' do
    start = Time.now
    elapsed = nil

    started = BlockingFlag.new
    t = Thread.new do
      started.set!
      Thread.pass
      subject.wait_for_set(1)
      elapsed = Time.now - start
    end
    started.wait_for_set

    subject.set!
    t.join

    elapsed.should_not be_nil
    elapsed.should < 0.5
  end
end