background image
<< Multi-Application - rendezvous statement | Multi-Application - Code for notification example >>
Multi-Application - if-else construct
<< Multi-Application - rendezvous statement | Multi-Application - Code for notification example >>
394
User's Guide
22 M
ULTI
-A
PPLICATION
T
ESTING
Concurrency test explained
Now that all the clients are ready to write to the database, the script creates a
thread for each client, in which each attempts to save the same employee
record at the same time. There is only one operation for each Agent to
execute: Employee.OK.Click, which clicks the OK button to commit the edit
performed in the previous thread.
The test expects the application to report the concurrency conflict with
message boxes for all but one client and for that client to close its dialog box
within 15 seconds. The if-else construct saves the text of the message in the
error message box by means of the SetMachineData function. It then closes
the message box and the Employee window so that the recovery system will
not report that it had to close windows. This is good practice because it
means fewer messages to interpret in the results file.
The "else if" section of the if-else checks to see whether the Employee
window remains open (presumably because it is held by a deadlock
condition); this is a testcase failure. In this case, the AppError function places
the string "***ERROR:" in front of the descriptive error message and raises
an exception; all Agents terminate their threads and the testcase exits.
iSucceed = 0
for each sMachine in lsMachine
sMessage = GetMachineData (sMachine, "sMessage")
if (sMessage == NULL)
iSucceed += 1
else
Print ("Machine {sMachine} got
message '{sMessage}'")
Verify (iSucceed, 1, "number of machines
that succeeded")
The last section of code evaluates the results of the concurrency test in the
event that all threads completed. If more than one client successfully wrote to
the database, the test actually failed.
GetMachineData retrieves the message box message (if any) associated with
each machine. If there was no message, iSucceed is incremented; it holds the
count of "successes." The Print function writes the text of the message box to
the results file for each machine that had a message box. You can read the
results file to verify that the correct message was reported. Alternatively, you
could modify the test to automatically verify the message text.
The Verify function verifies that one and only one machine succeeded. If the
comparison in the Verify function fails, Verify raises an exception. All
exceptions are listed in the results file.