background image
<< Client/Server - the Edit.FindChange menu item | Configuring SilkTest for Client/Server Testing >>
Client/Server - the spawn statement
<< Client/Server - the Edit.FindChange menu item | Configuring SilkTest for Client/Server Testing >>
350
User's Guide
19 I
NTRODUCTION
TO
C
LIENT
/S
ERVER
T
ESTING
Concurrent programming issues
In code fragment [A], the six operations defined by the function
SixOpsFunction are executed simultaneously on all machines in a previously
defined list of Agent names. After the parallel operation, the script waits for
all the machines to complete; on completion, they will present a message box
(unless the application fails). In code fragment [B], the message box is
dismissed. By putting the message dismissal operation into its own parallel
statement block instead of adding it to the SixOpsFunction, you are able to
synchronize and all machines "click" at almost the same instant.
In order to specify that a set of machines should execute concurrently, you
use a 4Test command that starts concurrent threads. In the fragments above,
the spawn statement starts a thread for each machine. Threads and the 4Test
constructs that generate them are discussed in detail in section "Using 4Test's
parallel processing features" on page 365.
Global variables
Suppose the code for each machine is counting instances of some event. You
want a single count for the whole test and so each machine adds its count to a
global variable. When you are executing the code for all your machines in
parallel, two instances of the statement
iGlobal = iGlobal + iCount
could be executing in parallel. Since the instructions that implement this
statement would then be interleaved, you could get erroneous results. To
prevent this problem you can declare a variable shareable. When you do so,
you can use the access statement to gain exclusive access to the shared
variable for the duration of the block of code following the access statement.
Make variables shareable whenever the potential for conflict exists.