2015-07-13 98 views
3

我有一個事務控制器,它在我的Jmeter測試計劃中有一個http請求。交易名稱和網址來自CSV文件。最後,執行總計分爲5個不同的交易。如何在指定的線程數量失敗後停止Jmeter測試

TestPlan中:

TestPlan中 -Thread組 - 用戶定義的變量

總樣品執行將是8000-10000。現在我想要的,如果總樣本失敗達到100,我的JMeter測試應該停止測試執行。

我已經添加了用戶定義的變量名「thread」並且值爲「0」。我在Beanshell中添加了以下代碼後處理器

int count= Integer.parseInt(vars.get("thread")); 
if (prev.getErrorCount()==1){ 
count++; 
System.out.println(count); 
vars.put("thread",Integer.toString(count)); 
} 

if (count==100){ 

System.out.println("Reached to max number of errors in load test, stopping test"); 
log.info ("Reached to max number of errors in load test, stopping test"); 
prev.setStopTestNow(true); 

} 

某種程度上代碼不能按預期工作。當錯誤計數達到100時,Jmeter測試不會停止。當錯誤計數達到130時停止測試。我不確定誰來修復上面的代碼。

有人能讓我知道上面的代碼中有什麼問題嗎?

+0

您是否有嵌套樣本? – Ross

+0

如果我爲單個用戶運行它,並保持錯誤計數限制爲3,它工作正常。 3名失敗者後停止測試。但是,當我運行5個用戶,最大錯誤數爲3,8次失敗後停止測試。 它是簡單的腳本。沒有嵌套樣本。 – user1169236

+0

您是否嘗試過使用道具而不是'vars'? – Ross

回答

2

變量是特定於1個線程,而屬性由所有線程共享。

參見:

確保你同步訪問

另一種選擇是使用自定義的Java類作爲一個Singleton和增加其值。

這裏使用的BeanShell(身高JSR223 + Groovy的演出)的範例:

  • setupThreadGroup上測試啓動計數器復位:enter image description here

  • BeanshellPostProcessor的更新計數器:enter image description here

請注意,當您調用setStopTestNow時,測試線程會中斷b除非你有一些定時器(通常是這種情況),否則不要完全停止。

prev.setStopTestNow(true);

+0

是的,我正在努力。但看起來我做錯了什麼。我已經添加聲明爲屬性,但仍面臨同樣的問題String count1 = props.setProperty(「abc」,「0」); String thread = props.getProperty(「abc」); int count = Integer.parseInt(vars.get(「thread」));如果(prev.getErrorCount()== 1){count = 0; System.out.println(count); vars.put(「thread」,Integer.toString(count)); } 如果(計數== 3){ 的System.out.println( 「達到在負載測試錯誤的最大數量,停止測試」); log.info(「達到負載測試中的最大錯誤數,停止測試」); prev.setStopTestNow(true); } – user1169236

+0

非常感謝您的幫助。以上解決方案我已經嘗試過,它的工作:)。我感謝您的幫助。 – user1169236

相關問題