Jump to content
WAPT Forum
Sign in to follow this  
Guest Siegfried Goeschl

How to do "traditional" logging in WAPT Pro 2.1

Recommended Posts

Guest Siegfried Goeschl

I have long-running performance test up to 24 hours and a hundreds of users - one thing being tested is account creation. SInce this is a formal test I need to provide the list of accounts I created during the performance test and match those accounts with the accounts actually found in the database. Therefore it is critical to write all created accounts into a logfile.

 

I tried the following options

 

+) using the "log" object provided does not help me for various reasons - it would be spread across all of my users and reporting is becoming unstable in my case (getting socket problems while downloading/parsing the logs)

+) using JavaScript (see the code below) does not work under high load because the Windows Scripting stuff throws exceptions - I think that concurrently writing to the same file causes the issue

 

Any other ideas?

 

Thanks in advance

 

Siegfried Goeschl

 

 

 

=== Start of Script ===

 

/**

* Logs to the given file and prepends a timestamp. If the file does not exist it will be created.

*/

function logToFile(fileName, line)

{

var date = new Date();

var timestamp = null;

var minuteString = null;

var secondString = null;

 

var hourString = (date.getHours() < 10) ? "0" + date.getHours() : date.getHours();

var minuteString = (date.getMinutes() < 10) ? "0" + date.getMinutes() : date.getMinutes();

var secondString = (date.getSeconds() < 10) ? "0" + date.getSeconds() : date.getSeconds();

var timestamp = hourString + ":" + minuteString + ":" + secondString;

var lineWritten = timestamp + ";" + line;

 

var fso = null;

var fh = null;

 

try

{

fso = new ActiveXObject("Scripting.FileSystemObject");

fh = fso.OpenTextFile(fileName, 8, true);

fh.WriteLine(lineWritten);

}

catch(e)

{

log.error("Unable to append to the logfile : " + lineWritten);

}

finally

{

if(fh != null)

{

fh.Close();

}

}

}

 

=== End Of Script ===

Share this post


Link to post
Share on other sites

Use an unique file name for each virtual user (for example, use $UserID for file name) and merge files after test completion.

Share this post


Link to post
Share on other sites
Guest Siegfried Goeschl

Hi Sergei,

 

there are many ways to skin the cat .... :-)

 

I implemented that in the mean time and need to test it but I think that better logging support would be a valuable addition to WAPT - image what my customer says if I try to explain why I need to write to 500 individual logfiles ... :-(

Share this post


Link to post
Share on other sites
Guest Siegfried Goeschl

I tested the solution using a single file for each virtual user and it does not work - when I have more virtual users trying to log causes an Exception saying "Object error".

 

For the records the script I'm using

 

/**

* Logs to the given file and prepends a timestamp. If the file does not exist it will be created.

*/

function logToCsv(baseFileName, line)

{

var date = new Date();

var fileName = baseFileName + "." + context.userId + ".csv";

 

var hourString = (date.getHours() < 10) ? "0" + date.getHours() : date.getHours();

var minuteString = (date.getMinutes() < 10) ? "0" + date.getMinutes() : date.getMinutes();

var secondString = (date.getSeconds() < 10) ? "0" + date.getSeconds() : date.getSeconds();

var timestamp = hourString + ":" + minuteString + ":" + secondString;

var lineWritten = timestamp + ";" + line;

 

var fso = null;

var fh = null;

 

try

{

fso = new ActiveXObject("Scripting.FileSystemObject");

 

if (fso.FileExists(fileName))

{

fh = fso.OpenTextFile(fileName, 8, true);

}

else

{

fh = fso.CreateTextFile(fileName, true);

}

 

fh.WriteLine(lineWritten);

}

catch(e)

{

log.error("Unable to append to the logfile : " + lineWritten);

log.error("Root Cause : " + e);

}

finally

{

if(fh != null)

{

fh.Close();

}

}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×