summaryrefslogtreecommitdiff
path: root/source/Test/Unit/Store.hs
diff options
context:
space:
mode:
Diffstat (limited to 'source/Test/Unit/Store.hs')
-rw-r--r--source/Test/Unit/Store.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/Test/Unit/Store.hs b/source/Test/Unit/Store.hs
index 9f25a3b..e2896c3 100644
--- a/source/Test/Unit/Store.hs
+++ b/source/Test/Unit/Store.hs
@@ -21,6 +21,7 @@ import Felix.Store qualified as Store
import Provers qualified
import Syntax.Interface qualified as Syntax
+import Control.Concurrent (threadDelay)
import Control.Exception qualified as Exception
import Data.ByteString qualified as ByteString
import Data.ByteString.Char8 qualified as ByteString.Char8
@@ -33,6 +34,7 @@ import System.FilePath.Posix qualified as Posix
import System.IO.Temp qualified as Temp
import Test.Tasty
import Test.Tasty.HUnit
+import UnliftIO.Async (concurrently)
unitTests :: TestTree
@@ -40,6 +42,8 @@ unitTests =
testGroup "SQLite store"
[ testCase "initializes and reopens the current schema"
initializesAndReopensCurrentSchema
+ , testCase "serializes invocation-local coordinator access"
+ serializesCoordinatorAccess
, testCase "rejects incompatibility without configuring the store"
rejectsIncompatibilityWithoutConfiguration
, testCase "rejects malformed compatibility metadata"
@@ -80,6 +84,28 @@ unitTests =
doesNotFallBackAfterFatalStartup
]
+serializesCoordinatorAccess :: Assertion
+serializesCoordinatorAccess = do
+ coordinator <- Store.newStoreCoordinator
+ active <- IORef.newIORef (0 :: Int)
+ maximumActive <- IORef.newIORef (0 :: Int)
+ let operation =
+ Store.withStoreCoordinator coordinator
+ (Exception.bracket_
+ (IORef.atomicModifyIORef' active
+ (\current ->
+ let next = current + 1
+ in (next, ())))
+ (IORef.atomicModifyIORef' active
+ (\current -> (current - 1, ())))
+ (do
+ current <- IORef.readIORef active
+ IORef.atomicModifyIORef' maximumActive
+ (\observed -> (max current observed, ()))
+ threadDelay 50000))
+ void (concurrently operation operation)
+ IORef.readIORef maximumActive >>= assertEqual "maximum owner count" 1
+
roundTripsExactParsedArtifacts :: Assertion
roundTripsExactParsedArtifacts =
withStoreFixture "felix-store-parsed" \path theory _fixture -> do