2import ProjectM36.Client
3import ProjectM36.Relation
4import qualified Data.Set as S
5import TutorialD.Interpreter.TestBase
10import Control.Exception.Base
12{-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}
15 tcounts <- runTestTT testList
16 if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
19testList = TestList [testAutomergeSuccess,
21 testAutomergeReconnect]
23checkEither :: IO (Either RelationalError a) -> IO a
27 Left err -> assertFailure (show err) >> undefined
30testAutomergeSuccess :: Test
31testAutomergeSuccess = TestCase $ do
32 --create two sessions, diverge from the head, and automerge back
33 (sessionId, conn) <- dateExamplesConnection emptyNotificationCallback
35 sessionPastId <- checkEither $ createSessionAtHead conn headn
36 executeTutorialD sessionId conn "insert s relation{tuple{city \"New City\", s# \"S6\", sname \"Samuels\", status 50}}"
37 checkEither $ commit sessionId conn
39 executeTutorialD sessionPastId conn "insert s relation{tuple{city \"Merge City\", s# \"S7\", sname \"Mr. Merge\", status 60}}"
41 checkEither $ autoMergeToHead sessionPastId conn UnionMergeStrategy headn
43 --validate that both tuples are now in the head transaction
46 eqAttr key = AttributeEqualityPredicate "s#" (NakedAtomExpr (TextAtom key))
47 result <- checkEither $ executeRelationalExpr sessionPastId conn (Project (AttributeNames S.empty) (Restrict (predi "S6") (RelationVariable "s" ())))
48 assertEqual "new S6" relationTrue result
50 result' <- checkEither $ executeRelationalExpr sessionPastId conn (Project (AttributeNames S.empty) (Restrict (predi "S7") (RelationVariable "s" ())))
52 assertEqual "new S7" relationTrue result'
54 eHeadName <- headName sessionPastId conn
55 assertEqual "back on master" (Right "master") eHeadName
57testAutomergeFailure :: Test
58testAutomergeFailure = TestCase $ do
59 --create two sessions, diverge from the head, but create a union merge strategy failure
60 (sessionId, conn) <- dateExamplesConnection emptyNotificationCallback
62 sessionPastId <- checkEither $ createSessionAtHead conn headn
63 executeTutorialD sessionId conn "insert s relation{tuple{city \"New City\", s# \"S6\", sname \"Samuels\", status 50}}"
64 checkEither $ commit sessionId conn
66 --reuse the same id, violating the uniqueness constraint
67 executeTutorialD sessionPastId conn "insert s relation{tuple{city \"Merge City\", s# \"S6\", sname \"Mr. Merge\", status 60}}"
69 --validate that both tuples are now in the head transaction
71 mergeRes <- autoMergeToHead sessionPastId conn UnionMergeStrategy headn
73 _ <- checkEither $ executeRelationalExpr sessionPastId conn (RelationVariable "s" ())
75 assertEqual "merge failure" (Left (InclusionDependencyCheckError "s_pkey")) mergeRes
78testAutomergeReconnect :: Test
79testAutomergeReconnect = TestCase $ withSystemTempDirectory "m36testdb" $ \tempdir -> do
81 conn <- unsafeLeftCrash =<< connectProjectM36 (InProcessConnectionInfo (CrashSafePersistence (tempdir </> "test.db")) emptyNotificationCallback [])
82 sess <- unsafeLeftCrash =<< createSessionAtHead conn "master"
83 autoMergeToHead sess conn UnionMergeStrategy "master"
86 unsafeLeftCrash :: Show e => Either e a -> IO a
87 unsafeLeftCrash = either (throwIO . userError . show) pure
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list