Class: BeanstalkIntegrationTest

Inherits:
MiniTest::Should::TestCase
  • Object
show all
Includes:
Timeout
Defined in:
lib/beanstalk_integration_tests/test_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Timeout

#timeout

Constructor Details

#initializeBeanstalkIntegrationTest

Returns a new instance of BeanstalkIntegrationTest.



94
95
96
97
98
# File 'lib/beanstalk_integration_tests/test_helper.rb', line 94

def initialize(*)
  @tubes = []
  @clients = []
  super
end

Class Method Details

.address(custom_address = '0.0.0.0') ⇒ Object



37
38
39
# File 'lib/beanstalk_integration_tests/test_helper.rb', line 37

def address(custom_address = '0.0.0.0')
  return @address ||= custom_address
end

Instance Method Details

#addressObject



58
59
60
# File 'lib/beanstalk_integration_tests/test_helper.rb', line 58

def address
  return self.class.address
end

#build_clientObject



62
63
64
65
66
# File 'lib/beanstalk_integration_tests/test_helper.rb', line 62

def build_client
  new_client = Beaneater::Connection.new(address)
  @clients << new_client
  return new_client
end

#cleanup_tubesObject



68
69
70
71
72
73
74
75
# File 'lib/beanstalk_integration_tests/test_helper.rb', line 68

def cleanup_tubes
  @pool = Beaneater::Pool.new([address])
  @tubes.each do |tube_name|
    @pool.tubes.find(tube_name).clear
  end
  @pool.close
  @tubes.clear
end

#clientObject



77
78
79
# File 'lib/beanstalk_integration_tests/test_helper.rb', line 77

def client
  @client ||= build_client
end

#create_buried_jobs(buried_count = 5) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/beanstalk_integration_tests/test_helper.rb', line 81

def create_buried_jobs(buried_count = 5)
  job_ids = []
  buried_count.times do
    message = uuid
    client.transmit("put 0 0 120 #{message.bytesize}\r\n#{message}")
    timeout(1) do
      job_ids << client.transmit('reserve')[:id]
    end
    client.transmit("bury #{job_ids.last} 0")
  end
  return job_ids
end

#generate_tube_nameObject



100
101
102
103
104
# File 'lib/beanstalk_integration_tests/test_helper.rb', line 100

def generate_tube_name
  tube = uuid
  @tubes << tube
  return tube
end

#tube_nameObject



106
107
108
# File 'lib/beanstalk_integration_tests/test_helper.rb', line 106

def tube_name
  return @tube_name ||= generate_tube_name
end

#uuidObject



110
111
112
# File 'lib/beanstalk_integration_tests/test_helper.rb', line 110

def uuid
  SecureRandom.uuid
end