spec/selector_spec.rb in agent-0.9.0 vs spec/selector_spec.rb in agent-0.9.1

- old
+ new

@@ -25,10 +25,27 @@ r.first.should == :timeout (Time.now.to_f - now).should be_within(0.05).of(0.1) end + it "should not raise an error when a block is missing on default" do + lambda { + select! do |s| + s.default + end + }.should_not raise_error(Agent::Errors::BlockMissing) + end + + it "should not raise an error when a block is missing on timeout" do + lambda { + select! do |s| + s.timeout(1) + s.default + end + }.should_not raise_error(Agent::Errors::BlockMissing) + end + context "with unbuffered channels" do before do @c = channel!(Integer) end @@ -36,32 +53,31 @@ @c.close unless @c.closed? end it "should evaluate select statements top to bottom" do select! do |s| - s.case(@c, :send, 1) {} - s.case(@c, :receive) {} - s.default {} + s.case(@c, :send, 1) + s.case(@c, :receive) + s.default s.cases.size.should == 3 end end - it "should raise an error when a block is missing on receive" do + it "should not raise an error when a block is missing on receive" do lambda { select! do |s| s.case(@c, :receive) + s.default end - }.should raise_error(Agent::Errors::BlockMissing) + }.should_not raise_error(Agent::Errors::BlockMissing) end it "should not raise an error when a block is missing on send" do lambda { - go!{ @c.receive } - select! do |s| s.case(@c, :send, 1) - s.cases.size.should == 0 + s.default end }.should_not raise_error(Agent::Errors::BlockMissing) end it "should scan all cases to identify available actions and execute first available one" do @@ -96,11 +112,11 @@ go!{ sleep 0.25; @c.close } lambda { select! do |s| s.case(@c, :send, 1) - s.case(@c, :receive){} + s.case(@c, :receive) end }.should raise_error(Agent::Errors::ChannelClosed) end context "select immediately available channel" do @@ -166,11 +182,11 @@ # brittle.. counting on select to execute within 0.5s now = Time.now.to_f go!{sleep(0.2); c.receive[0].should == 2 } select! do |s| - s.case(c, :send, 2) {} + s.case(c, :send, 2) end (Time.now.to_f - now).should be_within(0.1).of(0.2) c.close end @@ -221,30 +237,30 @@ @c.close unless @c.closed? end it "should evaluate select statements top to bottom" do select! do |s| - s.case(@c, :send, 1) {} - s.case(@c, :receive) {} + s.case(@c, :send, 1) + s.case(@c, :receive) s.cases.size.should == 2 end end - it "should raise an error when a block is missing on receive" do + it "should not raise an error when a block is missing on receive" do lambda { select! do |s| s.case(@c, :receive) - s.cases.size.should == 0 + s.default end - }.should raise_error(Agent::Errors::BlockMissing) + }.should_not raise_error(Agent::Errors::BlockMissing) end it "should not raise an error when a block is missing on send" do lambda { select! do |s| s.case(@c, :send, 1) - s.cases.size.should == 0 + s.default end }.should_not raise_error(Agent::Errors::BlockMissing) end it "should scan all cases to identify available actions and execute first available one" do @@ -281,11 +297,11 @@ go!{ sleep 0.25; @c.close } lambda { select! do |s| s.case(@c, :send, 1) - s.case(@c, :send, 2){} + s.case(@c, :send, 2) end }.should raise_error(Agent::Errors::ChannelClosed) end context "select immediately available channel" do @@ -346,10 +362,10 @@ # brittle.. counting on select to execute within 0.5s now = Time.now.to_f go!{sleep(0.2); c.receive } select! do |s| - s.case(c, :send, 2) {} + s.case(c, :send, 2) end c.receive[0].should == 2 (Time.now.to_f - now).should be_within(0.1).of(0.2) c.close