<commit_before>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

RSpec.describe Resque::Cluster::Member do
  before :all do
    @redis = Redis.new

    Resque::Cluster.config = {
      cluster_name: 'unit-test-cluster',
      environment: 'unit-test',
      local_config_path: File.expand_path(File.dirname(__FILE__) + '/../local_config.yml'),
      global_config_path: File.expand_path(File.dirname(__FILE__) + '/../global_config.yml')
    }
    @pool = Resque::Pool.new({})
    @member = Resque::Cluster.init(@pool)
  end

  after :all do
    Resque::Cluster.member
    Resque::Cluster.config = nil
    Resque::Cluster.member = nil
  end

  context '#cluster_member_settings' do
    before :all do
      @settings_hash = {
        :cluster_maximums => {'foo' => 2, 'bar' => 50, "foo,bar,baz" => 1},
        :host_maximums => {'foo' => 1, 'bar' => 9, "foo,bar,baz" => 1},
        :client_settings => @redis.client.options,
        :rebalance_flag => false,
        :presume_host_dead_after => 120,
        :max_workers_per_host => nil,
        :cluster_name => "unit-test-cluster",
        :environment_name => "unit-test",
        :manage_worker_heartbeats => true
      }
    end
  end

  context '#check_for_worker_count_adjustment' do
    before :all do
      @redis.hset("GRU:unit-test:unit-test-cluster:global:max_workers","bar",2)
      @redis.hset("GRU:unit-test:unit-test-cluster:#{@@hostname}:max_workers","bar",2)
      @redis.hset("GRU:unit-test:unit-test-cluster:global:workers_running","bar",0)
      @redis.hset("GRU:unit-test:unit-test-cluster:#{@@hostname}:workers_running","bar",0)
    end

    it 'adjust worker counts if an adjustment exists on the local command queue' do
      2.times do
        @member.check_for_worker_count_adjustment
        expect(@redis.hget("GRU:unit-test:unit-test-cluster:#{@@hostname}:workers_running", 'foo')).to eq '1'
        expect(@redis.hget("GRU:unit-test:unit-test-cluster:#{@@hostname}:workers_running", 'bar')).to eq '2'
        expect(@member.pool.config['foo']).to eq(1)
        expect(@member.pool.config['bar']).to eq(2)
      end
    end
  end

  after :all do
    @redis.del("GRU:unit-test:unit-test-cluster:global:max_workers")
    @redis.del("GRU:unit-test:unit-test-cluster:global:workers_running")
    @redis.del("GRU:unit-test:unit-test-cluster:heartbeats")
  end

end
<commit_msg>Cleanup after a test cluster member<commit_after>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

RSpec.describe Resque::Cluster::Member do
  before :all do
    @redis = Redis.new

    Resque::Cluster.config = {
      cluster_name: 'unit-test-cluster',
      environment: 'unit-test',
      local_config_path: File.expand_path(File.dirname(__FILE__) + '/../local_config.yml'),
      global_config_path: File.expand_path(File.dirname(__FILE__) + '/../global_config.yml')
    }
    @pool = Resque::Pool.new({})
    @member = Resque::Cluster.init(@pool)
  end

  after :all do
    Resque::Cluster.member
    Resque::Cluster.config = nil
    Resque::Cluster.member = nil
  end

  context '#check_for_worker_count_adjustment' do
    before :all do
      @redis.hset("GRU:unit-test:unit-test-cluster:global:max_workers","bar",2)
      @redis.hset("GRU:unit-test:unit-test-cluster:#{@@hostname}:max_workers","bar",2)
      @redis.hset("GRU:unit-test:unit-test-cluster:global:workers_running","bar",0)
      @redis.hset("GRU:unit-test:unit-test-cluster:#{@@hostname}:workers_running","bar",0)
    end

    it 'adjust worker counts if an adjustment exists on the local command queue' do
      2.times do
        @member.check_for_worker_count_adjustment
        expect(@redis.hget("GRU:unit-test:unit-test-cluster:#{@@hostname}:workers_running", 'foo')).to eq '1'
        expect(@redis.hget("GRU:unit-test:unit-test-cluster:#{@@hostname}:workers_running", 'bar')).to eq '2'
        expect(@member.pool.config['foo']).to eq(1)
        expect(@member.pool.config['bar']).to eq(2)
      end
    end
  end

  after :all do
    binding.pry
    @member.unregister
    @redis.del("GRU:unit-test:unit-test-cluster:global:max_workers")
    @redis.del("GRU:unit-test:unit-test-cluster:global:workers_running")
    @redis.del("GRU:unit-test:unit-test-cluster:heartbeats")
  end

end

{'fraction_non_alphanumeric': 0.1632941176470588, 'fraction_numerical': 0.006588235294117647, 'mean_word_length': 3.8033898305084746, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '2816926', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1469, 'n_words': 218}