Re-initialising Facilita Virtual Users

This article will explain how to gracefully re-use Facilita Forecast Virtual Users that exit in the initial workflow stages. The main notable benefit being you can better utilise the licensed capacity of your virtual users.  You may run into a situation where you encounter a decision that  is dependant on actions your script performed in Initial Phase of work-flow. An example of which would be that of a user losing a session (for whatever reason) while iterating, you would then like to note this error but would still like to use the user for rest of the test, by recreating the session.

Here are couple of possible solutions that come to mind (from worst to best):

  1. Increasing VU count higher than needed. By doing this you are planning for some users failing. This isn’t an ideal solution, as you would need to estimate how many users would fail before starting the test. This is not utilising the allocated amount of the licensed VU’s, so it also isn’t ideal.
  2. Inserting code that recreates a session in places where user may fail. This may be a solution if the code required to recreate a session is trivial. But this solution is not ideal for the following reasons:
    • Ignoring DRY principle;
    • The required amount of actions can be substantial, which will in turn increase code complexity.
  3. Moving initial scripts to the iteration phase and creating a flag for the VU that controls which part of scripts should be executed on every iteration.

I will elaborate more on the  3rd option.

The first thing we need to do is create a boolean indicates if the initial script is required to run again. Add this boolean to the VirtualUser.h, as we want this value to stay the same between scripts.  The following lines are required:

/** * Get if we should repeat initial sequence of workflow */
bool isInitialRun()
{ return _initialRun; }
/** * Set if we should repeat initial sequence of workflow */
void setInitialRun(const bool & initialRun)
{ _initialRun = initialRun; }
private: bool _initialRun; 

We will assume that our original workflow consists of the following scripts:

Initial scripts: Login, Select_Admin_Menu;
Repeated scripts: Create_User; Validate_Creation;
Final scripts: Logout;

The first thing we do is move all scripts to Buy Cialis repeated scripts, but preserve the order, so after move our workflow should look something like this:
Initial scripts: ;
Repeated scripts: Login, Select_Admin_Menu, Create_User; Validate_Creation;
Final scripts: Logout;

Next we add the check to see if we need to run this script in the initial scripts (Login and Select_Admin_Menu). We add this to void script() function in all initial scripts.

public: void script()
if (getVU().isInitialRun() == false) return; // Not running this script if we don’t need to.
// This 'script' method is the main method executed by the runtime engine.

This now checks if we need to run this “initial script” now, and if not it will continue with next script (exiting this script). Remember we need to add getVU() in front of our call because the function is located inside VirtualUser, so it is not directly accessible. Or you could add an intermediary function to the VirtualUserScript.

The flag now needs to be set to false after the initial sequence. We do this in the first script in the iterated phase: using the above example this would be  Create_User.

public: void script()
getVU().setInitialRun(false); // We are done with initial scripts.
// This 'script' method is the main method executed by the runtime engine.

The last thing we need to do is change how errors are  handled. In any place you would expect a possible error, you need to do this:

 * Something that may not work and would break the VU, 
 * and the possible solution is to run initial sequence of scripts again.
 * Log this error with either error(..) or writeMessage(..) if you wish.
getVU().setInitialRun(true); // We need to run initial scripts again.
nextIteration(); // If nothing else is to be done here, start initial scripts again.

That’s it!  When a script now encounters an error it will reset itself and re-use the same VU. This has a particular benefit when  you are running tests over long durations (hours or even days) and want your virtual users to be resilient.  This strategy is important if you wish to utilise all your VUs and don’t want them to exit if encountering a minor issues on the system.

Does anyone else  have any other solutions to this problem?

One thought on “Re-initialising Facilita Virtual Users

  1. Great article Aigars.

    A similar requirement is to run scripts or code on every Nth iteration.
    For this you can use getIteration() in an expression.

        if (getIteration()%10 == 0)
            // Only execute on the first and every 10th iteration

    If you want interactive control, then use a Shared Data Server value that you change from the Shared Data Server UI while a test is running. Of course this technique allows you to set any number of values for interactive control of a running test.

Leave a Reply

Your email address will not be published. Required fields are marked *