简体   繁体   中英

Accessing App.Config Connection Strings in Load Test Plugin

I'm currently developing my first load test ever, so please bear with me ~

The load test itself is running a set of unit tests that POST different requests to an HTTP Handler. Depending on which agent the load test is running on, the requests themselves are made against dev/staging environments, and then passed to a downstream service that 'handles' the request, and executes INSERT statements against a couple of databases. I wanted to build and include a simple plugin that implements ILoadTestPlugin and provides it's own set of instructions for the LoadTestCompleted event handler. This plugin is currently contained within a separate Class Library project that is included in the same solution that is housing the load test itself.

Before I get into describing the problem, I'd like to point out that I am currently running the load test locally against the same handler that I've set up in IIS.

I'm running into an issue when the event fires, and my method attempts to establish an entity connection to the target database context (currently using Entity Framework 4). It appears that the plugin code is failing to find the app.config contained within the load test project. The exception message / stack trace points out that the connection string is invalid, but I have a hankering that the issue is that it cannot find it. On top of that, this same connection string is used throughout our code base in numerous places.

I can rule out the chance of my connection strings being invalid, because if I create a simple unit test method that uses the same configuration file to execute the same code, it works just fine. This is a given because the load test agent is contained in a different directory than that of the project, so it isn't having a problem locating the config file.

I've also tried adding the configuration file copied to the start-up project's output directory as a deployment item in my .testsettings file. No bueno. I've also created an app config file in the plug-in project that is an exact copy of that which I'm trying to use to see if that worked. Still no bueno.

Has anyone run into this problem? If you're trying to use <connectionString> sections in your config file, how can you get the load test plugin to find/use them?

I was going to attempt to use reflection and the good ole' ConfigurationManager to try and make a call into the assembly to find the path (and ultimately, the ProjectName.dll.config file), but wanted to ask the pros on StackOverflow for a little advice before moving forward.

Also, I'd provide code examples if this weren't such straight-forward EF code (or if it was getting past the point of: var dbContext = new dbContext( myConnectionString ); )

Any help / feedback is much appreciated.

Although I did not figure out how to use the application's configuration file within the load test plugin, because the load test & any corresponding plugin(s) run in the QTAgent.exe directory, I was able to implement my post-load test Database clean-up step in two ways.

  1. Using Context Parameters that contained the unique elements of the connection string based on the environment (Run Setting), such that the unique elements of connection string itself (eg - DataSource, etc...) were programatically available to my plug-in.

  2. In my Unit Test class that issued requests against the endpoint, I created a static method which was flagged with the [ClassCleanup] attribute. This gets executed when the Test Mix containing unit tests from that class are finished running. The test class is contained within the project's out directory and has access to the app's .config file with the entity connection string:

[TestClass]
public class MyEndpointUnitTests()
{
   [TestMethod]
   public void SubmitRequestType1()
   {
       //DoStuff for request type 1
   }

   [TestMethod]
   public void SubmitRequestType2()
   {
       //DoStuff for request type 2
   }

   [ClassCleanup]
   public static void Cleanup()
   {
       EndpointLoadTestCleanup.DoCleanup( dbContext = new DbContext( ) );
   }
}

You can create a custom Load Test Plug-in, in Initialize method you can grab the connection string from some xml/app.config file add it into context object will use it in your unit test project. it will be more robust and easy to maintain down the road.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM