<commit_before>package com.themillhousegroup.gatsby.stubby

import org.specs2.mutable.Specification
import org.specs2.mock.Mockito
import org.apache.commons.lang3.time.StopWatch
import scala.concurrent.{ Future, Await }
import scala.concurrent.duration.Duration

class MutualExclusionSpec extends Specification with Mockito {

  val maxWait = Duration(5, "seconds")

  class TestMutex extends EnforcesMutualExclusion with HasLogger {}

  "EnforcesMutualExclusion trait" should {

    "Allow direct access when there is no contention for the locked resource" in {

      val t = new TestMutex()

      val hadToWait = t.acquireLock("direct")

      t.currentLockHolder must beSome("direct")

      val hadToWaitForLock = Await.result(hadToWait, maxWait)

      t.releaseLock("direct")

      t.currentLockHolder must beNone

      hadToWaitForLock must beFalse
    }

    "Force the second in line to wait" in {

      val t = new TestMutex()

      val firstLock = t.acquireLock("1")<commit_msg>Change order of test assertions to make them more reliable<commit_after>package com.themillhousegroup.gatsby.stubby

import org.specs2.mutable.Specification
import org.specs2.mock.Mockito
import org.apache.commons.lang3.time.StopWatch
import scala.concurrent.{ Future, Await }
import scala.concurrent.duration.Duration

class MutualExclusionSpec extends Specification with Mockito {

  val maxWait = Duration(5, "seconds")

  class TestMutex extends EnforcesMutualExclusion with HasLogger {}

  "EnforcesMutualExclusion trait" should {

    "Allow direct access when there is no contention for the locked resource" in {

      val t = new TestMutex()

      val hadToWait = t.acquireLock("direct")

      val hadToWaitForLock = Await.result(hadToWait, maxWait)

      t.currentLockHolder must beSome("direct")

      t.releaseLock("direct")

      t.currentLockHolder must beNone

      hadToWaitForLock must beFalse
    }

    "Force the second in line to wait" in {

      val t = new TestMutex()

      val firstLock = t.acquireLock("1")
{'fraction_non_alphanumeric': 0.07665847665847667, 'fraction_numerical': 0.004914004914004914, 'mean_word_length': 3.80188679245283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2656296', 'n_tokens_mistral': 619, 'n_tokens_neox': 589, 'n_words': 172}