Sha256: a4de737b3acbb1d618658d8c68919e5e4c79a5d1f7cca28e357fd99ea4e6002d

Contents?: true

Size: 1.44 KB

Versions: 15

Compression:

Stored size: 1.44 KB

Contents

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.1)
    elapsed = Time.now - start

    if ServerEngine.windows? && ENV['CI'] == 'True'
      # timer seems low accuracy on Windows CI container, often a bit shorter
      # than expected
      elapsed.should >= 0.1 * 0.95
    else
      elapsed.should >= 0.1
    end
  end

  it 'wait_for_reset timeout' do
    subject.set!

    start = Time.now

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

    if ServerEngine.windows? && ENV['CI'] == 'True'
      # timer seems low accuracy on Windows CI container, often a bit shorter
      # than expected
      elapsed.should >= 0.1 * 0.95
    else
      elapsed.should >= 0.1
    end
  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

Version data entries

15 entries across 15 versions & 5 rubygems

Version Path
serverengine-2.4.0 spec/blocking_flag_spec.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/serverengine-2.3.2/spec/blocking_flag_spec.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/serverengine-2.3.2/spec/blocking_flag_spec.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/serverengine-2.3.2/spec/blocking_flag_spec.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/serverengine-2.3.2/spec/blocking_flag_spec.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/serverengine-2.3.2/spec/blocking_flag_spec.rb
serverengine-2.3.2 spec/blocking_flag_spec.rb
serverengine-2.3.1 spec/blocking_flag_spec.rb
serverengine-2.3.0 spec/blocking_flag_spec.rb
serverengine-2.2.5-x86-mingw32 spec/blocking_flag_spec.rb
serverengine-2.2.5-x64-mingw32 spec/blocking_flag_spec.rb
serverengine-2.2.5 spec/blocking_flag_spec.rb
serverengine-2.2.4-x86-mingw32 spec/blocking_flag_spec.rb
serverengine-2.2.4-x64-mingw32 spec/blocking_flag_spec.rb
serverengine-2.2.4 spec/blocking_flag_spec.rb