Extracted Instiki start/stop code in the Watir test suite (hairy Win32 incantations) into a class of its own.
This commit is contained in:
parent
57e4c725e9
commit
33ae92a332
1 changed files with 46 additions and 32 deletions
|
@ -8,28 +8,10 @@ require(File.expand_path(File.dirname(__FILE__) + "/../../config/environment"))
|
||||||
INSTIKI_PORT = 2501
|
INSTIKI_PORT = 2501
|
||||||
HOME = "http://localhost:#{INSTIKI_PORT}"
|
HOME = "http://localhost:#{INSTIKI_PORT}"
|
||||||
|
|
||||||
class Win32API
|
|
||||||
# FIXME this should raise an error whenever an API call returns an error
|
|
||||||
# alias __original_call call
|
|
||||||
# def call(*args)
|
|
||||||
# __original_call(*args)
|
|
||||||
# last_error = Win32API.new('kernel32.dll', 'GetLastError', '', 'L').__original_call()
|
|
||||||
# raise "Win32API call to #{args.inspect} has failed with error code #{last_error}" if last_error
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
|
|
||||||
class E2EInstikiTest < Test::Unit::TestCase
|
class E2EInstikiTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def startup
|
def startup
|
||||||
|
@@instiki = InstikiController.start
|
||||||
createProcess =
|
|
||||||
startup_info = [68].pack('lx64')
|
|
||||||
@@instiki = [0, 0, 0, 0].pack('llll')
|
|
||||||
Win32API.new('kernel32.dll', 'CreateProcess', 'pplllllppp', 'L').call(
|
|
||||||
nil,
|
|
||||||
"ruby #{RAILS_ROOT}/instiki.rb --storage #{prepare_storage} " +
|
|
||||||
" --port #{INSTIKI_PORT} --environment development",
|
|
||||||
0, 0, 1, 0, 0, '.', startup_info, @@instiki)
|
|
||||||
|
|
||||||
sleep 5
|
sleep 5
|
||||||
@@ie = Watir::IE.start(HOME)
|
@@ie = Watir::IE.start(HOME)
|
||||||
|
@ -41,13 +23,8 @@ class E2EInstikiTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.shutdown
|
def self.shutdown
|
||||||
process_id = @@instiki.unpack('llll')[2]
|
|
||||||
right_to_terminate_process = 1
|
|
||||||
handle = Win32API.new('kernel32.dll', 'OpenProcess', 'lil', 'l').call(
|
|
||||||
right_to_terminate_process, 0, process_id)
|
|
||||||
Win32API.new('kernel32.dll', 'TerminateProcess', 'll', 'L').call(handle, 0)
|
|
||||||
|
|
||||||
@@ie.close if defined? @@ie
|
@@ie.close if defined? @@ie
|
||||||
|
@@instiki.stop
|
||||||
end
|
end
|
||||||
|
|
||||||
def ie
|
def ie
|
||||||
|
@ -70,13 +47,6 @@ class E2EInstikiTest < Test::Unit::TestCase
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def prepare_storage
|
|
||||||
storage_path = INSTIKI_ROOT + '/storage/e2e'
|
|
||||||
FileUtils.rm_rf(storage_path) if File.exists? storage_path
|
|
||||||
FileUtils.mkdir_p(storage_path)
|
|
||||||
storage_path
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup_web
|
def setup_web
|
||||||
assert_equal 'Wiki', ie.textField(:name, 'web_name').value
|
assert_equal 'Wiki', ie.textField(:name, 'web_name').value
|
||||||
assert_equal 'wiki', ie.textField(:name, 'web_address').value
|
assert_equal 'wiki', ie.textField(:name, 'web_address').value
|
||||||
|
@ -102,6 +72,50 @@ class E2EInstikiTest < Test::Unit::TestCase
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class InstikiController
|
||||||
|
|
||||||
|
attr_reader :process_id
|
||||||
|
|
||||||
|
def self.start
|
||||||
|
startup_info = [68].pack('lx64')
|
||||||
|
process_info = [0, 0, 0, 0].pack('llll')
|
||||||
|
|
||||||
|
startup_command =
|
||||||
|
"ruby #{RAILS_ROOT}/instiki.rb --storage #{prepare_storage} " +
|
||||||
|
" --port #{INSTIKI_PORT} --environment development"
|
||||||
|
|
||||||
|
result = Win32API.new('kernel32.dll', 'CreateProcess', 'pplllllppp', 'L').call(
|
||||||
|
nil,
|
||||||
|
startup_command,
|
||||||
|
0, 0, 1, 0, 0, '.', startup_info, process_info)
|
||||||
|
|
||||||
|
# TODO print the error code, or better yet a text message
|
||||||
|
raise "Failed to start Instiki." if result == 0
|
||||||
|
|
||||||
|
process_id = process_info.unpack('llll')[2]
|
||||||
|
return self.new(process_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.prepare_storage
|
||||||
|
storage_path = INSTIKI_ROOT + '/storage/e2e'
|
||||||
|
FileUtils.rm_rf(storage_path) if File.exists? storage_path
|
||||||
|
FileUtils.mkdir_p(storage_path)
|
||||||
|
storage_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(pid)
|
||||||
|
@process_id = pid
|
||||||
|
end
|
||||||
|
|
||||||
|
def stop
|
||||||
|
right_to_terminate_process = 1
|
||||||
|
handle = Win32API.new('kernel32.dll', 'OpenProcess', 'lil', 'l').call(
|
||||||
|
right_to_terminate_process, 0, @process_id)
|
||||||
|
Win32API.new('kernel32.dll', 'TerminateProcess', 'll', 'L').call(handle, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'test/unit/ui/console/testrunner'
|
require 'test/unit/ui/console/testrunner'
|
||||||
Test::Unit::UI::Console::TestRunner.new(E2EInstikiTest.suite).start
|
Test::Unit::UI::Console::TestRunner.new(E2EInstikiTest.suite).start
|
||||||
|
|
Loading…
Add table
Reference in a new issue