2012-11-05 35 views
0

我已經構建了一個webtest。vs2012負載測試不會啓動很多線程

其中我添加了寫入文件。

我用5個只運行上述webtest的虛擬用戶創建了loadtest。

Graph view我看到有5 Users load

最後我看到只有一行寫入文件。

我是否需要以某種特殊的方式定義分佈?

我認爲設置虛擬用戶數量就夠了。沒有?

btw,什麼會導致我的負載測試在每次運行中精確運行10分鐘?

我不記得它限制在10分鐘

這是我的測試代碼:

公共類Settings_CacheExplosion:WebTest的 {// 私人靜態只讀的ILog activityLog = LogManager.GetLogger(「活動「);

private static int _ctidsCounter { get; set; } 

    public static int CtidsCounter 
    { 
     get 
     { 
      if (_ctidsCounter == 2000) 
      { 
       _ctidsCounter = 1000; 
      } 
      return _ctidsCounter++; 
     } 
     set 
     { 
      _ctidsCounter = value; 
     } 
    } 

    public Settings_CacheExplosion() 
    { 
     this.PreAuthenticate = true; 

     CtidsCounter = 1000; 

     //log4net.Config.XmlConfigurator.Configure(); 
    } 


    public override IEnumerator<WebTestRequest> GetRequestEnumerator() 
    { 
     WebTestRequest request1 = new WebTestRequest("http://clientservice.mam.qasite-services.com/settings"); 

     request1.Method = "POST"; 

     Debug.WriteLine(string.Format("ctid={0}", CtidsCounter)); 

     request1.QueryStringParameters.Add("ctid", CtidsCounter.ToString(), false, false); 
     StringHttpBody request1Body = new StringHttpBody(); 
     request1Body.ContentType = ""; 
     request1Body.InsertByteOrderMark = false; 
     request1Body.BodyString = ""; 
     request1.Body = request1Body; 

     string path = @"Settings_CacheExplosion_log.txt"; 
     // This text is added only once to the file. 
     if (!File.Exists(path)) 
     { 
      // Create a file to write to. 
      using (StreamWriter sw = File.CreateText(path)) 
      { 
       sw.WriteLine(string.Format("ctid={0}", CtidsCounter)); 
      } 
     } 

     // This text is always added, making the file longer over time 
     // if it is not deleted. 
     using (StreamWriter sw = File.AppendText(path)) 
     { 
      sw.WriteLine(string.Format("ctid={0}", CtidsCounter)); 
     } 


     yield return request1; 
     request1 = null; 
    } 
} 
+0

做了新的行覆蓋或追加到文件? – mcalex

+0

我認爲你的測試正好運行10分鐘(默認負載測試持續時間),因爲你有[Use Test Iterations](http://msdn.microsoft.com/en-us/library/ff406976.aspx#loadtestrunsettingproperties_testiterations)'False '。將此屬性設置爲'True'以根據測試迭代運行,而不是測試持續時間 – Schaliasos

+0

@mcalex這確實是問題 –

回答

0

檢查您的書寫方法是否覆蓋現有條目。如果文件中已有文本,則需要使用附加選項。

+0

你是對的。但它說5個用戶加載並在我的日誌文件中超過30行(一些重複行) –

+0

您是否在每次測試之間刪除文件中的條目? – mcalex

+0

是的。從新開始,仍然 –