LoadTestGoalBasedLoadProfile Class
The document is archived and information here might be outdated

LoadTestGoalBasedLoadProfile Class

Represents the load profile of a load test that has a goal-based load pattern.

Namespace:  Microsoft.VisualStudio.TestTools.LoadTesting
Assembly:  Microsoft.VisualStudio.QualityTools.LoadTestFramework (in Microsoft.VisualStudio.QualityTools.LoadTestFramework.dll)

[SerializableAttribute]
public class LoadTestGoalBasedLoadProfile : LoadTestLoadProfile

In the following example, a Load Test Plugin constructs a GoadBasedLoadProfile object and assigns it to the LoadTestScenario. It also assigns a value for DelayBetweenIterations to the LoadTestScenario in the Initialize() method.

using Microsoft.VisualStudio.TestTools.LoadTesting;
public class LoadTestPluginInitChangeProfile : ILoadTestPlugin
{
    public void Initialize(LoadTest loadTest)
    {
        LoadTestGoalBasedLoadProfile goalLoadProfile = new LoadTestGoalBasedLoadProfile();
        goalLoadProfile.MachineName = Environment.MachineName;
        goalLoadProfile.CategoryName = "Processor";
        goalLoadProfile.CounterName = "% Processor Time";
        goalLoadProfile.InstanceName = "_Total";
        goalLoadProfile.InitialUserCount = 5;
        goalLoadProfile.MinUserCount = 1;
        goalLoadProfile.MaxUserCount = 100;
        goalLoadProfile.MaxUserCountIncrease = 10;
        goalLoadProfile.MaxUserCountDecrease = 5;
        goalLoadProfile.MinTargetValue = 20;
        goalLoadProfile.MaxTargetValue = 25;
        // This example assumes that there is only one scenario
        loadTest.Scenarios[0].LoadProfile = goalLoadProfile;

        loadTest.Scenarios[0].DelayBetweenIterations = 5;
    }
}

In the following example, a Load Test Plugin modifies selected properties of a GoalBasedLoadProfile in the HeartbeatEvent handler. This approach works only if the load profile specified in the .loadtest file is a Goal Based Load Pattern.

using Microsoft.VisualStudio.TestTools.LoadTesting;

public class LoadTestPluginChangeGoal : ILoadTestPlugin
{
    private LoadTest m_loadTest;
    private LoadTestScenario m_scenario1;
    private bool m_goalChanged;

    public void Initialize(LoadTest loadTest)
    {
        m_loadTest = loadTest;
        // This example assume there is only one scenario
        m_scenario1 = loadTest.Scenarios[0];
        m_loadTest.Heartbeat += new   EventHandler<HeartbeatEventArgs>(m_loadTest_Heartbeat);
    }

    void m_loadTest_Heartbeat(object sender, HeartbeatEventArgs e)
    {
        if (e.ElapsedSeconds >= 60 && !m_goalChanged)
        {
            LoadTestGoalBasedLoadProfile goalLoadProfile = 
m_scenario1.LoadProfile.Copy() as    LoadTestGoalBasedLoadProfile;
            goalLoadProfile.MinTargetValue = 50;
            goalLoadProfile.MaxTargetValue = 60;
            m_scenario1.LoadProfile = goalLoadProfile;
            m_goalChanged = true;
        }
    }
}

System.Object
  Microsoft.VisualStudio.TestTools.LoadTesting.LoadTestLoadProfile
    Microsoft.VisualStudio.TestTools.LoadTesting.LoadTestGoalBasedLoadProfile

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2016 Microsoft