background image
<< Client/Server Testing - Using 4Test's parallel processing features | Client/Server Testing - The parallel statement >>
Client/Server Testing - Threads and concurrent programming
<< Client/Server Testing - Using 4Test's parallel processing features | Client/Server Testing - The parallel statement >>
366
User's Guide
21 I
MPLEMENTING
C
LIENT
/S
ERVER
T
ESTING
Using 4Test's parallel processing features
Threads and
concurrent
programming
In the 4Test environment, a thread is a mechanism for interleaving the
execution of blocks of client code assigned to different Agents so that one
script can drive multiple client applications simultaneously. A thread is part
of the script that starts it; a thread is not a separate script. Each thread has its
own call stack and data stack. However, all the threads that a script spawns
share access to the same global variables, function arguments, and data types.
A file that one thread opens is accessible to any thread in that script.
While the creation of a thread carries no requirement that you use it to submit
operations to a client application, the normal reason for creating a
multithread script is so that each thread can drive test functions for one client,
which allows multiple client application operations to execute in parallel.
When a script connects to a machine, any thread in that script is also
connected to the machine. Therefore you must direct the testing operations in
a thread to a particular Agent machine. The following sections, in particular
"Specifying the target" provide more details.
Note Threads interleave at the machine instruction level, therefore
no single 4Test statement is atomic with respect to a statement in
another thread.
Parallel processing
statements
You create and manage multiple threads using combinations of the 4Test
statements parallel, spawn, rendezvous, and critical:
·
A spawn statement begins execution of the specified statement or block
of statements in a new thread. Since the purpose of spawn is to initiate
concurrent test operations on multiple machines, the structure of a block
of spawned code is typically:
a
A SetMachine command, which directs subsequent machine
operations to the specified Agent.
b
A set of machine operations to drive the application.
c
A verification of the results of the machine operations.
·
A rendezvous statement blocks execution of the calling thread until all
threads that were spawned by the calling thread have completed. When
the last child thread exits, it unblocks the parent thread. The rendezvous
statement is unnecessary if it is the last statement at the end of the
testcase. If the calling thread has no child threads, rendezvous does
nothing.
·
A parallel statement spawns a statement for each machine specified and
blocks the calling thread until the threads it spawns have all completed. It
condenses the actions of spawn and rendezvous and can make code
more readable.