<commit_before>
require 'spec_helper'

require 'poll_shared'


describe ZMQ::PollInterruptible do
  
  let(:poll_class) { ZMQ::PollInterruptible }
  
  it_behaves_like "a poll class"
  
  let!(:never_sock) { ZMQ::Socket.new(ZMQ::PULL) } # A socket never used
  subject { poll_class.new never_sock }
  
  around { |test| Timeout.timeout(1) {test.run} } # Timeout after 1 second
  
  it "can be interrupted" do
    subject
    
    Thread.new { subject.run }.tap { subject.interrupt.should eq true }.join
    Thread.new { subject.run }.tap { subject.interrupt.should eq true }.join
  end
  
  it "can be killed" do
    subject
    subject.dead?.should eq false
    
    Thread.new { subject.run }.tap { subject.kill.should eq true }.join
    
    # Poll is now dead<commit_msg>Test values yielded to run block by PollInterruptible<commit_after>
require 'spec_helper'

require 'poll_shared'


describe ZMQ::PollInterruptible do
  
  let(:poll_class) { ZMQ::PollInterruptible }
  
  it_behaves_like "a poll class"
  
  let!(:never_sock) { ZMQ::Socket.new(ZMQ::PULL) } # A socket never used
  subject { poll_class.new never_sock }
  
  around { |test| Timeout.timeout(1) {test.run} } # Timeout after 1 second
  
  it "can be interrupted" do
    subject
    
    Thread.new {
      subject.run { |sock,evts| sock.should eq nil; evts.should eq nil }
    }.tap { subject.interrupt.should eq true }.join
    
    Thread.new { subject.run }.tap { subject.interrupt.should eq true }.join
    Thread.new { subject.run }.tap { subject.interrupt.should eq true }.join
  end
  
  it "can be killed" do
    subject
    subject.dead?.should eq false
    
    Thread.new {
      subject.run { |sock,evts| sock.should eq nil; evts.should eq nil }
    }.tap { subject.kill.should eq true }.join
    
    # Poll is now dead
{'fraction_non_alphanumeric': 0.1076581576026637, 'fraction_numerical': 0.0022197558268590455, 'mean_word_length': 2.9366812227074237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3605345', 'n_tokens_mistral': 636, 'n_tokens_neox': 609, 'n_words': 171}