Rails 3.2.9 app に取り組んでいます。ここでは、選択したテスト ケースを実行する必要があります。実行するには、execute_testcases というアクションを呼び出します。Mutex は、異なる実行での衝突を避けるために使用されます。しかし、突然実行が停止し、cmdウィンドウをポップして閉じます(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