test: CRCFail frame, CheckpointSync complete
authorMax Voit <max.voit+gtdv@with-eyes.net>
Thu, 23 Jul 2015 13:10:14 +0000 (15:10 +0200)
committerMax Voit <max.voit+gtdv@with-eyes.net>
Thu, 23 Jul 2015 13:10:14 +0000 (15:10 +0200)
acid-state-dist.cabal
test/CRCFail.hs [new file with mode: 0644]
test/CheckpointSync.hs [new file with mode: 0644]
test/readme.md

index 0635f5e..d21ccbd 100644 (file)
@@ -91,12 +91,8 @@ test-suite Simple
   hs-source-dirs:   test
   ghc-options:      -Wall -threaded
   default-language: Haskell2010
-  build-depends:    base,
-                    directory,
-                    mtl,
-                    safecopy,
-                    acid-state,
-                    acid-state-dist
+  build-depends:    base, directory, mtl,
+                    safecopy, acid-state, acid-state-dist
 
 test-suite SlaveUpdates
   main-is:          SlaveUpdates.hs
@@ -104,9 +100,14 @@ test-suite SlaveUpdates
   hs-source-dirs:   test
   ghc-options:      -Wall -threaded
   default-language: Haskell2010
-  build-depends:    base,
-                    directory,
-                    mtl,
-                    safecopy,
-                    acid-state,
-                    acid-state-dist
+  build-depends:    base, directory, mtl,
+                    safecopy, acid-state, acid-state-dist
+
+test-suite CheckpointSync
+  main-is:          CheckpointSync.hs
+  type:             exitcode-stdio-1.0
+  hs-source-dirs:   test
+  ghc-options:      -Wall -threaded
+  default-language: Haskell2010
+  build-depends:    base, directory, mtl,
+                    safecopy, acid-state, acid-state-dist
diff --git a/test/CRCFail.hs b/test/CRCFail.hs
new file mode 100644 (file)
index 0000000..9e1e6d4
--- /dev/null
@@ -0,0 +1,42 @@
+{-# LANGUAGE TypeFamilies #-}
+
+import Data.Acid
+import Data.Acid.Centered
+
+import Control.Monad (void, when)
+import Control.Concurrent (threadDelay, forkIO)
+import System.Exit (exitSuccess, exitFailure)
+import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
+
+-- state structures
+import IntCommon
+
+-- helpers
+delaySec :: Int -> IO ()
+delaySec n = threadDelay $ n*1000*1000
+
+cleanup :: FilePath -> IO ()
+cleanup path = do
+    sp <- doesDirectoryExist path
+    when sp $ removeDirectoryRecursive path
+
+-- actual test
+slave :: IO ()
+slave = do
+    acid <- enslaveStateFrom "state/CRCFail/s1" "localhost" 3333 (IntState 23)
+    -- TODO: at this point happens the crc fail - we need to check for an
+    -- exception and thereby determine whether the test was successful
+    delaySec 5
+    val <- query acid GetState
+    closeAcidState acid
+    when (val /= 23) $ putStrLn "Slave hasn't got value." >> exitFailure
+
+main :: IO ()
+main = do
+    cleanup "state/CRCFail"
+    acid <- openMasterStateFrom "state/CRCFail/m" "127.0.0.1" 3333 (IntState 0)
+    void $ forkIO slave
+    delaySec 10
+    closeAcidState acid
+    exitSuccess
+
diff --git a/test/CheckpointSync.hs b/test/CheckpointSync.hs
new file mode 100644 (file)
index 0000000..4107555
--- /dev/null
@@ -0,0 +1,42 @@
+{-# LANGUAGE TypeFamilies #-}
+
+import Data.Acid
+import Data.Acid.Centered
+
+import Control.Monad (void, when)
+import Control.Concurrent (threadDelay, forkIO)
+import System.Exit (exitSuccess, exitFailure)
+import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
+
+-- state structures
+import IntCommon
+
+-- helpers
+delaySec :: Int -> IO ()
+delaySec n = threadDelay $ n*1000*1000
+
+cleanup :: FilePath -> IO ()
+cleanup path = do
+    sp <- doesDirectoryExist path
+    when sp $ removeDirectoryRecursive path
+
+-- actual test
+slave :: IO ()
+slave = do
+    acid <- enslaveStateFrom "state/CheckpointSync/s1" "localhost" 3333 (IntState 23)
+    delaySec 5
+    val <- query acid GetState
+    closeAcidState acid
+    when (val /= 1) $ putStrLn "Slave hasn't got value." >> exitFailure
+
+main :: IO ()
+main = do
+    cleanup "state/CheckpointSync"
+    acid <- openMasterStateFrom "state/CheckpointSync/m" "127.0.0.1" 3333 (IntState 0)
+    update acid IncrementState
+    createCheckpoint acid
+    void $ forkIO slave
+    delaySec 10
+    closeAcidState acid
+    exitSuccess
+
index 6c6d81d..33c0cb7 100644 (file)
@@ -15,4 +15,8 @@ Do Master and other Slaves get the update?
 
 For diverged state the CRC check must fail (unless Checkpoints were replicated).
 
+# CheckpointSync
+
+A diverged state must be the same after sync-replicating a Checkpoint (i.e.
+Slave joins only after generating the checkpoint).