Concurrency Test Example Code

The concurrency test example is designed to allow any number of test machines to attempt to access a server database at the same time. This tests for problems with concurrency, such as deadlock or out-of-sequence writes.

This example uses only one application. However, it is coded in the style required by the multi-application environment because you will probably want to use an Agent to start and initialize the server during this type of test. There is no requirement in the client/server environment that you use the single-application style of test case just because you are driving only one application. For consistency of coding style, you will probably find it convenient to always use the multi-application files and functions.

For detailed information on the code example, see Concurrency Test Explained.

const ACCEPT_TIMEOUT = 15
multitestcase MyTest (LIST OF STRING lsMachine)
  STRING sMachine
  INTEGER iSucceed
  STRING sError

  for each sMachine in lsMachine
    SetUpMachine (sMachine, Personnel)
    SetMultiAppStates ()

  /*** HAVE EACH MACHINE EDIT THE SAME EMPLOYEE ***/
  for each sMachine in lsMachine
    spawn
      
      /*** SET THE CURRENT MACHINE FOR THIS THREAD ***/
      SetMachine (sMachine)
      
      /*** EDIT THE EMPLOYEE RECORD "John Doe" ***/
      Personnel.EmployeeList.Select ("John Doe")
      Personnel.Employee.Edit.Pick ()

      /*** CHANGE THE SALARY TO A RANDOM NUMBER BETWEEN 
      50000 AND 70000 ***/
      Employee.Salary.SetText ([STRING] RandInt (50000, 70000))
  rendezvous
  
  /*** ATTEMPT TO HAVE EACH MACHINE SAVE THE EMPLOYEE RECORD ***/
  for each sMachine in lsMachine
    spawn
   
      /*** SET THE CURRENT MACHINE FOR THIS THREAD ***/
      SetMachine (sMachine)

      /*** SELECT THE OK BUTTON ***/
      Employee.OK.Click ()

      /*** CHECK IF THERE IS A MESSAGE BOX ***/
      if (MessageBox.Exists (ACCEPT_TIMEOUT))
        SetMachineData (NULL, "sMessage",
          MessageBox.Message.GetText ())
        MessageBox.OK.Click ()
        Employee.Cancel.Click ()
      else if (Employee.Exists ())
        AppError ("Employee dialog not
          dismissed after {ACCEPT_TIMEOUT} seconds")
  rendezvous

  /*** VERIFY THE OF NUMBER OF MACHINES WHICH SUCCEEDED ***/
  iSucceed = 0
  for each sMachine in lsMachine
    sError = GetMachineData (sMachine, "sMessage")
    if (sMessage == NULL)
      iSucceed += 1
    else
      Print ("Machine {sMachine} got message '{sMessage}'")
  
  Verify (iSucceed, 1, "number of machines that succeeded")