background image
<< Client/Server Testing - Threads and concurrent programming | Client/Server Testing - Specifying the target >>
Client/Server Testing - The parallel statement
<< Client/Server Testing - Threads and concurrent programming | Client/Server Testing - Specifying the target >>
User's Guide
367
21 I
MPLEMENTING
C
LIENT
/S
ERVER
T
ESTING
Using 4Test's parallel processing features
·
A critical statement guarantees that no other thread will execute until the
specified statement or indented block of code has executed and passed
control to the next statement at the level of the critical statement. Only
one thread can have "critical" status at any time.
In 4Test, all running threads (those not blocked) have the same priority with
respect to one another. 4Test executes one instruction for a thread, then passes
control to the next thread. The first thread called is the first run, and so on.
All threads run to completion unless they are deadlocked. 4Test will detect a
script deadlock and raise an exception (see "How 4Test handles script
deadlock" on page 372). Not
e that the 4Test exit statement terminates all
threads immediately when it is executed by one thread.
The parallel statement
The parallel statement executes a single statement for each thread. Thus if
you wish to run complete tests in parallel threads, use the invocation of a test
function (which may execute many statements) with the parallel statement,
or use a block of statements with spawn and rendezvous.
To use the parallel statement, you have to specify the machines for which
threads are to be started. You can follow the parallel keyword with a list of
statements, each of which specifies a different Agent name. For example:
parallel
DoSomething ("Client1")
DoSomething ("Client2")
The DoSomething function then typically issues a SetMachine(sMachine)
call to direct its machine operations to the proper Agent.
The spawn statement
You can use spawn to start a single thread for one machine, and then use
successive spawn statements to start threads for other machines being tested.
SilkTest scans for all spawn statements preceding a rendezvous statement
and starts all the threads at the same time. However, the typical use of spawn
is in a loop, as follows:
for each sMachine in lsMachine
spawn
// start thread for each sMachine
SetMachine (sMachine)
DoSomething ()
rendezvous
The above example could achieve the same result when written as follows:
for each sMachine in lsMachine
spawn
[sMachine]DoSomething ()
rendezvous