Testing Clients Concurrently

In concurrent testing, Silk Test Classic executes one function on two or more clients at the same time. This topic demonstrates one way to perform the same tests concurrently on multiple clients.

For example, suppose you want to initiate two concurrent database transactions on the same record, and then test how well the server performs. To accomplish this, you need to change the script presented in Testing Clients Plus Server Serially to look like this:
testcase TestConcurrently ()
  Connect ("server")
  Connect ("client1")
  Connect ("client2")
  DoSomeSetup ("server")    // initialize server first
  Disconnect ("server")     // testcase is thru with server
  
  spawn                     // start thread for client1
    UpdateDatabase ("client1")
  spawn                     // start thread for client2
    UpdateDatabase ("client2")
  
  rendezvous                // synchronize
  Disconnect ("client1")
  Disconnect ("client2")
  
  DoSomeSetup (STRING sMachine)   // define server setup
    HTIMER hTimer
    hTimer = TimerCreate ()
    TimerStart (hTimer)
    SetMachine (sMachine)
    // code to do server setup goes here
    TimerStop (hTimer)
    Print ("Time on {sMachine} is: {TimerStr (hTimer)}")
    TimerDestroy (hTimer)

  UpdateDatabase (STRING sMachine)   // define update test
    HTIMER hTimer
    hTimer = TimerCreate ()
    TimerStart (hTimer)
    SetMachine (sMachine)
    // code to update database goes here
    TimerStop (hTimer)
    Print ("Time on {sMachine} is: {TimerStr (hTimer)}")
    TimerDestroy (hTimer)
An alternative but equivalent approach is to use the parallel statement in place of the spawn and rendezvous:
testcase TestConcurrently2 ()
  Connect ("server")
  Connect ("client1")
  Connect ("client2")
  
  DoSomeSetup ("server")
  Disconnect ("server")

  parallel                     // automatic synchronization
    UpdateDatabase ("client1") // thread for client1
    UpdateDatabase ("client2") // thread for client2
                           
  Disconnect ("client1")
  Disconnect ("client2")

  DoSomeSetup (STRING sMachine)
    HTIMER hTimer
    hTimer = TimerCreate ()
    TimerStart (hTimer)
    SetMachine (sMachine)
    // code to do server setup goes here
    TimerStop (hTimer)
    Print ("Time on {sMachine} is: {TimerStr (hTimer)}")
    TimerDestroy (hTimer)

  UpdateDatabase (STRING sMachine)
    HTIMER hTimer
    hTimer = TimerCreate ()
    TimerStart (hTimer)
    SetMachine (sMachine)
    // code to update database goes here
    TimerStop (hTimer)
    Print ("Time on {sMachine} is: {TimerStr (hTimer)}")
    TimerDestroy (hTimer)

If you use variables to specify different database records for each client’s database transactions, you can use the above techniques to guarantee parallel execution without concurrent database accesses.