我正在开发Rails 3.2.9应用程序。在这里,我们必须执行选定的测试用例。它通过调用一个名为execute_testcases的动作来完成。互斥用于避免不同执行中的冲突。但是突然执行已经停止工作,它只是弹出一个cmd窗口n关闭它(打开cmd是代码的一部分,但是一旦执行完毕就会关闭它)。有时在浏览器中我收到此错误
Attempt to unlock a mutex which is locked by another thread
WEBrick/1.3.1 (Ruby/1.9.3/2012-11-10) at localhost:3000
当我追踪执行代码时,我看到它在第1点或第2点停止(在下面的代码中引用) 所以我只添加了所需的代码供您参考。如果您需要更多代码请告诉我..
相同的代码在其他机器上工作正常..只是在我的机器上我得到这个错误。请帮我解决这个错误
accountcontroller.rb:
@@lock = Mutex.new
@@another_test_running = false
def execute_testcases
file_names = []
originalfile_filewithtime = []
original_file_map = {}
originalfile_filewithtime = params[:excelfile]
for value in originalfile_filewithtime
original_file, file_with_time = value.split(',')
original_file_map[file_with_time] = original_file
file_names << file_with_time
end
copy_selected_excel_sheets_to_isaf(file_names)
i = 0
while(@@another_test_running && i < MAX_TIMEOUT) do
sleep 1
i = i + 1
end
@@another_test_running = true
puts "STARTED EXECUTING #{file_names}"
@@lock.synchronize do ###### POINT 1
update_master_suite_file(file_names)
Dir.chdir(SAF_DIR)
system("START cmd /C ant ^| tee #{self.current_user.username}.log 2>&1")
sleep 15 #To avoid collision with other SAF executions
@@another_test_running = false
end
wait_for_test_execution_to_complete(900) ###### POINT 2
show_output(file_names, original_file_map)
render :update do |page|
page.replace_html :subject_list, :partial => 'show_output', :locals => {:new_file_map => @new_file_map}
page.visual_effect :highlight, 'subject_list', :duration => 2
end
end
def wait_for_test_execution_to_complete(timeout)
test_exec_log_file = SAF_DIR + self.current_user.username + ".log"
i = 0
text = File.exist?(test_exec_log_file)? File.read(test_exec_log_file) : ""
while(!text.include?("stop-server:") && i < timeout)#### POINT 2
sleep 2
i = i + 2
text = File.exist?(test_exec_log_file)? File.read(test_exec_log_file) : ""
end
#Further, wait to see BUILD SUCCESSFUL or FAILED message
j = 0
while(!(text.include?("BUILD SUCCESSFUL") || text.include?("BUILD FAILED")) && j < 30 )
sleep 2
j = j + 2
text = File.exist?(test_exec_log_file)? File.read(test_exec_log_file) : ""
end
#delete the log file
File.delete(test_exec_log_file)
end