Hi all,
I have a Watir 1.4.1 script driving a performance test against one of my servers, and wanted to multithread it to allow multiple browsers to run against the server from the same client machine.
I have a data file 'user.dat' containing username and password information that I read in and then insert into the appropriate text fields on the start up page.
I have a synchronization block around the access to the username password information as well as one around where the information is placed into the text_fields.
When I run this script I see the following behavior, I do not get logins occuring consistantly, usually with a complaint that the username/password information is incorrect.
When I printed out the username and passwords that were being used it looked as if the synchronized block was not being honored.
The console out put from the code below is
username: SMYTH1230 password: SMYTH1230
username: SMYTH2367 password: SMYTH2367
username: SMYTH2394 password: SMYTH2394
SMYTH1230
SMYTH2394
SMYTH2367
The user name and password are correct BUT there was a context switch within the synchronized block which switched the password before the block was completed.
I would have expected to see
username: SMYTH1230 password: SMYTH1230
SMYTH1230
username: SMYTH2367 password: SMYTH2367
SMYTH2367
username: SMYTH2394 password: SMYTH2394
SMYTH2394
Can someone help me with the source of this problem, is this a problem with Watir or in my use of synchronization within Ruby?
I appreciate any help you can give me.
Program:
require 'monitor'
require 'watir'
require 'logger'
include Watir
class User_credentials
include MonitorMixin
def initialize(user_file)
@file = File.new(user_file, 'r')
super()
end
def get_credentials
synchronize {
line = @file.gets
@credentials = Hash.new
@credentials['username'], @credentials['password'], @credentials['index'] = line.split(',')
return @credentials
}
end
end
def think (enabled, time)
if enabled : sleep time end
end
class My_load_test
include MonitorMixin
def initialize(log, user_info)
@log = log
@user_info = user_info
super()
end
def load_test
sleep_enabled = true
standard_thinktime = 1
server_name = myserver.ibm.com/loginPage'
# Get a browser instance
ie=IE.new
for i in 1..3
# Go to the default Portal page
ie.goto(server_name)
@log.info("Go to #{server_name}, #{ie.down_load_time}")
# Enter username and password and login
username = ''
synchronize do
user_credential = @user_info.get_credentials
username = user_credential['username']
ie.textField(:id, 'userID').set(username)
puts "username: #{username} password: #{user_credential['password']}"
ie.textField(:id, 'password').set(user_credential['password'])
puts user_credential['password']
end
ie.button(:value, 'Log in').click
@log.info("#{username}, Login , #{ie.down_load_time}")
end
# Logout
ie.link(:text, 'Log Out').click
@log.info("#{username}, Logout, #{ie.down_load_time}")
end
ie.close
end
end
threads = []
user_cred = User_credentials.new('user.dat')
data_log = Logger.new('datalog.log', 5, 10 *1024*1024)
3.times do |i|
threads[i] = Thread.new do
my_load_test = My_load_test.new(data_log, user_cred)
my_load_test.load_test
end
end
threads.each { |t| t.join }
Thanks,
Scott Snyder
Senior Performance Analyst
IBM Corporation
"The supreme misfortune is when theory outstrips performance."
"There are three classes of people.
Those who see;
those who see when they are shown;
those who do not see."
- Leonardo da Vinci
_______________________________________________ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general