Sha256: 4e08f14810747760d08f76b23030059419f9a3709009f24e85f780e1ac87f7d0

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require "spec_helper"

describe Agent::Notifier do
  before do
    @notifier = Agent::Notifier.new
  end

  it "should notify using a payload" do
    @notifier.notify(1)
    @notifier.payload.should == 1
  end

  it "should acknowledge notification" do
    @notifier.should_not be_notified
    @notifier.notify(1)
    @notifier.should be_notified
  end

  it "should only notify once" do
    @notifier.notify(1)
    @notifier.notify(2)
    @notifier.payload.should == 1
  end

  it "should return nil when notified for the first time" do
    @notifier.notify(1).should be_nil
  end

  it "should return an error when notified more than once" do
    @notifier.notify(1)
    @notifier.notify(2).should be_message("already notified")
  end

  it "should allow waiting on a notification and should signal when it is notified" do
    ack = channel!(Integer)
    go!{ @notifier.wait; ack.send(@notifier.payload) }
    sleep 0.1 # make sure the notifier in the goroutine is waiting
    @notifier.notify(1)
    payload, _ = ack.receive
    payload.should == 1
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
agent-0.10.0 spec/notifier_spec.rb
agent-0.9.1 spec/notifier_spec.rb
agent-0.9.0 spec/notifier_spec.rb