2015-10-05 76 views
0

我設立一個連續傳遞管道其中,執行[等待tomcat7]動作來看,

  1. 創建一個新的AWS實例,
  2. 安裝所有必要的軟件來運行Web應用程序,
  3. 部署web應用到tomcat和
  4. 運行從GitHub的測試回購部署了一些耙測試。

所有的已經很不錯了。我已經建立了詹金斯用下面的命令來執行shell腳本,

sudo knife ec2 server create -r 'recipe[apt],recipe[java],recipe[mysql_install],recipe[tomcat],recipe[deploy_tests_from_github],recipe[configure_db],recipe[deploy-app],recipe[start_tests]' -V 

的部署去罰款。唯一的問題是,當測試開始時,Chef似乎關閉了tomcat,因此Watir無法瀏覽到Web應用程序。

大多數的食譜是由廚師超市直克隆,我使用這個食譜爲Tomcat https://supermarket.chef.io/cookbooks/tomcat

和我start_test食譜很簡單

execute "start_test" do 
    command '/usr/local/bin/rake' 
    cwd '/Watir_tests/test' 
end 

這裏是我的輸出的一部分,

ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0mRecipe: Deploy_App 

::default[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com * service[tomcat7] action stop 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  [32m- stop service service[tomcat7][0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m * execute[wait for tomcat7] action run 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  [32m- execute sleep 5[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m * remote_file[MyApp.war] action create 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  [32m- create new file /var/lib/tomcat7/webapps/MyApp.war[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  [32m- update content in file /var/lib/tomcat7/webapps/MyApp.war from none to cd2ac4[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  [37m(file sizes exceed 10000000 bytes, diff output suppressed)[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m * service[tomcat7] action start 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  [32m- start service service[tomcat7][0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m * execute[wait for tomcat7] action run 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  [32m- execute sleep 5[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0mRecipe: start_tests::default[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com * execute[start_test] action run 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  [0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  ================================================================================[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  [31mError executing action `run` on resource 'execute[start_test]'[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  ================================================================================[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m Mixlib::ShellOut::ShellCommandFailed[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  ------------------------------------[0m 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com  Expected process to exit with [0], but received '1' 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m ---- Begin output of /usr/local/bin/rake ---- 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m STDOUT: Run options: --seed 62510 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m # Running: 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m EEEEEE 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m Finished in 330.793031s, 0.0181 runs/s, 0.0000 assertions/s. 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  
    Error: 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m LogInWithWrongPasswordTest#test_log_in_with_wrong_credentials: 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m **Watir::Exception::UnknownObjectException: unable to locate element, using {:id=>"logInform:userName", :tag_name=>"input or textarea", :type=>"(any text type)"}** 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  /var/lib/gems/1.9.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:533:in `assert_element_found' 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  /var/lib/gems/1.9.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:505:in `assert_exists' 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  /var/lib/gems/1.9.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/user_editable.rb:32:in `clear' 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  /var/lib/gems/1.9.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/user_editable.rb:11:in `set' 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  /Watir_tests/Pages/LogInPage.rb:14:in `login' 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  /Watrit_tests/test/log_in_with_wrong_password_test.rb:15:in `test_log_in_with_wrong_credentials' 
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  
ec2-52-88-49-226.us-west-2.compute.amazonaws.com [0m  

正如你可以看到,的Watir不能因爲Tomcat是不是在那一刻運行找到網頁元素。

有任何人遇到這樣的事情?有解決方案嗎?

也請告知,如果調用刀EC2服務器從詹金斯創建命令是可取的。

謝謝。

+0

這難道不是你的Tomcat啓動時等待,但web應用程序啓動/部署尚未完成? ('睡眠5'不是很長,服務啓動是異步IIRC,我會更好地在catalina.out的尾部循環選擇'服務器啓動',睡眠1米,如果5分鐘後服務器未啓動,可能會失敗) – Tensibai

回答

0

我的評論上面的我會做的長版(未測試的代碼,可以錯字):

bash "Wait tomcat started" do 
    code << -EOH 
    for i in {1..10}; do 
     tail -n 100 /path/to/catalina.out | grep "Server Startup" && exit 0 
     sleep 20 
    done 
    exit 1 
    EOH 
notifies :run,"execute[start_test]", :immediately 
end 

的想法是,檢查服務器已完成啓動(greping啓動行中最後100線如果你的應用程序在日誌中很健談),並通知測試開始如果是,或在200秒後失敗(10次,間隔20秒)

我假設(仍未測試)類似的東西可以做太是清潔:

execute "tail -n 100 /path/to/catalina.out | grep "Server Startup" do 
    retries 10 
    retry_delay 20 
    notifies :run,'execute[start_test]', :immediately 
end 
0

或者你也可以添加測試頁面,當Tomcat已經開始

until (curl http://localhost:8080/status/ | grep "READY") 
    do sleep 10 
done