4

Webサービスの負荷テストを試みています。

Webサービスに送信されて応答を返す2つのパラメーターを受け取る単純なメソッドがあり、このメソッドから単体テストを作成しました。

サービスを効果的にテストするには、さまざまな入力をテストする必要があるため 、単体テストのデータソースとして最大1000行のCSVを設定します。

この1つの単体テストを実行すると、すべての行が回転し、さまざまな値でWebサービスが順番に呼び出されます。

しかし、これは私が必要としているものではありません。負荷テスト構成を使用して思考時間を含め、ステップ負荷でユーザーを増やし、テストミックス構成などを使用して、各行を異なるスレッドの異なるユーザーに対応させる必要があります。

これは、単体テストと値のハードコーディングからデータソースを削除することで実現できますが、これは根本的に欠陥のあるテストです。Webサービスを実際にテストするには、各ユーザーが異なる値を送信し、異なる結果を取得する必要があります。 。

..。

では、データソースを負荷テストにフックして、その負荷テストで各ユーザーの単体テストのインスタンスを異なる値で開始するにはどうすればよいでしょうか。

4

3 に答える 3

4

この回答をガイドとして使用することになりました: https://stackoverflow.com/a/7813465/237723

コンソール アプリ メソッドから単体テストを作成し、その単体テストの負荷テストを行うのではなく、入力を受け取って Web サービスを呼び出す単純な ASP.NET Web フォームを作成しました。

この新しいフォームを使用して Web パフォーマンス テストを記録し、その WPTest を実行する負荷テストを作成しました。


  1. テストを記録した後、CSV を DataSource としてこのテストに追加しました。

  2. 最初の GET とその後の POST の 2 つの「リクエスト」が記録されました。必ず両方を残してください。favicon.ico リクエストが存在しなかったため削除しました。(これらの予防策は回避できる場合があります)

  3. POST リクエストを展開して、2 つの Web サービス入力に対応する TextBox パラメーターのプロパティを変更し、CSV の適切な列から値を取得しました。

  4. DataSource アクセス方法を「カーソルを自動的に移動しない」に変更しました (DataSource をテーブルに展開し、右クリック/F4 でプロパティを編集する必要があります)。

  5. 次に、実行中の UserID (int) に従ってカーソルを手動で移動する WebTestPlugin (リンクされた回答から) を作成しました。これは、ロード テストがステップ プランに従ってスピンアップするユーザー インスタンスに対応します。このクラスを作成したら、プロジェクトをビルドして Web パフォーマンス テストに追加します。


public class webtestplugin : WebTestPlugin
{
    public override void PreWebTest(object sender, PreWebTestEventArgs e)
    {
        base.PreWebTest(sender, e);
        e.WebTest.MoveDataTableCursor("DataSource1", "addresses#csv", e.WebTest.Context.WebTestUserId);                        
    }
}
于 2012-10-04T14:12:21.753 に答える
3

Just to answer your question, i'm pretty sure this can't be done out of the box of MSTest and NUnit (this approach won't stick in this scenario).


But, IMHO, just don't go there... From my experience, simulating ~1000 users out of a single machine will produce bad results, because the test will encounter all sorts of client limits - thread pool issues, outgoing and incoming traffic issues, etc. I'm not saying this can't be overcome, but it's twisted enough to consider a different approach.

I actually don't recommend using load test tools (there are many of them out there) in this case, as it is simple enough to write a little tool of your own and skip the configuration problems and learning curves of a 3rd party.

What I do recommend, is writing a tool of your own, and running it from seperate machines. It doesn't have to be run by a testing framework (I can't get myself to call it a unit test, because it's not), a console app will do the trick. Here's some code to get you started:

private ConcurrentBag<string> logs = new ConcurrentBag<string>();

public void GetLoad(int numberOfUsers, List<string> myParams)
{
    var users = new string[numberOfUsers];
    for (int i = 0; i < numberOfUsers; i++)
    {
        users[i] = string.Format("LoadTest{0}", i + 1);
    }

    var userThreads = new List<Thread>();
    for (int i = 0; i < numberOfUsers; i++)
    {
        int index = i;
        userThreads.Add(new Thread(()=> CallWebService(users[index], myParams[index])));
    }

    Parallel.ForEach(userThreads, thread=>thread.Start());
    foreach (var userThread in userThreads)
    {
        userThread.Join();
    }
    var outputFilename = string.Format("LoadTest.{0}Users.txt", numberOfUsers);
    File.AppendAllLines(outputFilename, logs);
}
于 2012-10-04T06:13:31.910 に答える