我正在开发 Rails 3.2.9 app 。在这里,我们必须执行选定的测试用例。这是通过调用一个名为 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 点(在下面的代码中提到)所以我只添加了所需的代码供您参考。如果您需要更多代码,请告诉我..
相同的代码在其他机器上也能正常工作。就在我的机器上,我得到了这个错误。请帮我解决这个错误
帐户控制器.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