Class: TestServer

Inherits:
Object show all
Defined in:
lib/wdd-ruby-ext/utils/test_server.rb

Constant Summary collapse

PORT =
1234
@@logger =
nil
@@server_thread =
nil

Class Method Summary collapse

Class Method Details

.loggerObject



95
96
97
# File 'lib/wdd-ruby-ext/utils/test_server.rb', line 95

def self.logger
  @@logger
end

.logger=(logger) ⇒ Object



99
100
101
# File 'lib/wdd-ruby-ext/utils/test_server.rb', line 99

def self.logger= logger
  @@logger = logger
end

.shutdownObject



119
120
121
122
123
124
125
# File 'lib/wdd-ruby-ext/utils/test_server.rb', line 119

def self.shutdown
  return unless @@server_thread
  @@server_thread.kill
  @@server_thread.join
  logger.info "TestServer stopped."
  @@server_thread = nil
end

.startup(port = PORT, options = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/wdd-ruby-ext/utils/test_server.rb', line 103

def self.startup( port=PORT, options={} )
  @@logger ||= Logger.new(STDOUT)
  @@logger.level = options[:logger_level] || Logger::DEBUG
  @@multi_threaded = options[:multi_threaded] || false
  return if @@server_thread
  @@server_thread = Thread.new do 
    begin
      EM.run do
        EM.start_server "0.0.0.0", port, TestServerModule
      end
    rescue Interrupt
    end
  end
  logger.info "TestServer listening on port #{port}."
end