Class SerialRunLock

java.lang.Object
dev.galasa.framework.spi.utils.SerialRunLock

public class SerialRunLock extends Object
The lock which stops two runs of the same test class running at the same time, for test classes which are annotated with @DoNotRunInParallel. The lock is a key in the "framework" DSS namespace, holding the name of the run which owns it:
 dss.framework.locks.isSerial.<bundleName>/<className> = <runName>
 
The lock is claimed by the scheduler just before it allocates the run. It must be released by whatever stops the run being active. Only runs which are serial (see IRun.isSerial()) hold the lock. If the release was missed (the owner's run record is gone, or the owner is finished), the lock is stale. A claim takes over a stale lock, so a missed release can't block the test class for ever.
  • Method Details

    • claimIfSerial

      public static boolean claimIfSerial(IDynamicStatusStoreKeyAccess dss, IRun run) throws DynamicStatusStoreException
      Claims the lock for the run's test class if the run is serial. Only one run can own the lock at a time. A run which already owns the lock is treated as having claimed it. That happens when a scheduler claimed the lock but failed before it could allocate the run, so the run is still queued. A lock owned by a run which is no longer active (its run record is gone, or it is finished) is taken over.
      Parameters:
      dss - the DSS in the "framework" namespace.
      run - the run which wants to own the lock.
      Returns:
      true if the run is not serial, or now owns the lock. False if another run owns the lock.
      Throws:
      DynamicStatusStoreException - if the DSS could not be updated.
    • releaseIfSerial

      public static void releaseIfSerial(IDynamicStatusStoreKeyAccess dss, IRun run)
      Releases the lock for the run's test class if the run is serial, but only if the run owns it. A run which does not own the lock (it never claimed it, or already released it) leaves the lock untouched, so a run can never release a lock which another run holds. If the DSS fails, the failure is logged and not thrown. The caller has already changed the run's status, and must not fail because of the lock. A lock left held by a finished run is taken over by the next claim.
      Parameters:
      dss - the DSS in the "framework" namespace.
      run - the run which may own the lock.