<commit_before>require 'spec_helper'

module ZK::ZKEventMachine
  describe 'EventHandlerEM' do
    include EventedSpec::SpecHelper
    default_timeout 2.0

    before do
      @zk = ::ZK.new
      @base_path = '/zk-em-testing'
      @zk.rm_rf(@base_path)
      @zk.mkdir_p(@base_path)
      @zkem = ZK::ZKEventMachine::Client.new('localhost:2181')
    end

    after do
      mute_logger do
        @zk.rm_rf(@base_path)
        @zk.close!
      end
    end

    # this is a test of event delivery in general, not just of the
    # EventHandlerEM implementation

    describe 'data event' do
      include EventedSpec::EMSpec

      before do
        @path = "#{@base_path}/blah"
        @data = "this is data"
        @new_data = "this is other data"

        @child_path = [@path, 'child'].join('/')
      end

      it %[should call the callback when the data of a watched node changes] do
        @zkem.connect do
          @zkem.event_handler.register(@path) do |event|
            EM.reactor_thread?.should be_true
            event.should be_node_changed
            @zkem.close! { done }
          end

          common_eb = lambda { |exc| raise exc }

          @zkem.create(@path, @data) do |exc,path|
            raise exc if exc

            @zkem.stat(@path, :watch => true) do |e,*a| 
              raise e if e

              @zkem.set(@path, @new_data) { |e| raise e if e }
            end
          end
        end
      end

      it %[should call the callback when the children of the watched node change] do
        @zkem.connect do
          @zkem.event_handler.register(@path) do |event|
            EM.reactor_thread?.should be_true
            event.should be_node_child
            @zkem.close! { done }
          end

          eb_raise = lambda { |e| raise e if e }

          @zkem.create(@path, @data).callback { |*|
            @zkem.children(@path, :watch => true).callback { |ary,stat|<commit_msg>fix failing spec under 1.8.7<commit_after>require 'spec_helper'

module ZK::ZKEventMachine
  describe 'EventHandlerEM' do
    include EventedSpec::SpecHelper
    default_timeout 2.0

    before do
      @zk = ::ZK.new
      @base_path = '/zk-em-testing'
      @zk.rm_rf(@base_path)
      @zk.mkdir_p(@base_path)
      @zkem = ZK::ZKEventMachine::Client.new('localhost:2181')
    end

    after do
      mute_logger do
        @zk.rm_rf(@base_path)
        @zk.close!
      end
    end

    # this is a test of event delivery in general, not just of the
    # EventHandlerEM implementation

    describe 'data event' do
      include EventedSpec::EMSpec

      before do
        @path = "#{@base_path}/blah"
        @data = "this is data"
        @new_data = "this is other data"

        @child_path = [@path, 'child'].join('/')
      end

      it %[should call the callback when the data of a watched node changes] do
        @zkem.connect do
          @zkem.event_handler.register(@path) do |event|
            EM.reactor_thread?.should be_true
            event.should be_node_changed
            @zkem.close! { done }
          end

          common_eb = lambda { |exc| raise exc }

          @zkem.create(@path, @data) do |exc,path|
            raise exc if exc

            @zkem.stat(@path, :watch => true) do |e,*a| 
              raise e if e

              @zkem.set(@path, @new_data) do |e,*a|
                raise e if e
              end
            end
          end
        end
      end

      it %[should call the callback when the children of the watched node change] do
        @zkem.connect do
          @zkem.event_handler.register(@path) do |event|
            EM.reactor_thread?.should be_true
            event.should be_node_child
            @zkem.close! { done }
          end

          eb_raise = lambda { |e| raise e if e }

          @zkem.create(@path, @data).callback { |*|
            @zkem.children(@path, :watch => true).callback { |ary,stat|
{'fraction_non_alphanumeric': 0.10590943975441289, 'fraction_numerical': 0.003837298541826554, 'mean_word_length': 1.851932895696572, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1366065', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1195, 'n_words': 337}