test: Simple refined, SlaveUpdates added
authorMax Voit <max.voit+gtdv@with-eyes.net>
Thu, 23 Jul 2015 10:16:28 +0000 (12:16 +0200)
committerMax Voit <max.voit+gtdv@with-eyes.net>
Thu, 23 Jul 2015 10:16:28 +0000 (12:16 +0200)
acid-state-dist.cabal
makefile [new file with mode: 0644]
test/Simple.hs [new file with mode: 0644]
test/SlaveUpdates [new file with mode: 0755]
test/SlaveUpdates.hs [new file with mode: 0644]
test/readme.md [new file with mode: 0644]
test/simple.hs [deleted file]

index 0a3ccaa..4c0a7e4 100644 (file)
@@ -82,13 +82,29 @@ library
   -- Base language which the package is written in.
   default-language:    Haskell2010
 
-test-suite simple
-  main-is:          simple.hs
+----------------------------------------------------------------------
+-- Tests
+test-suite Simple
+  main-is:          Simple.hs
   type:             exitcode-stdio-1.0
   hs-source-dirs:   test
-  ghc-options:      -Wall
+  ghc-options:      -Wall -threaded
   default-language: Haskell2010
   build-depends:    base,
+                    directory,
+                    mtl,
+                    safecopy,
+                    acid-state,
+                    acid-state-dist
+
+test-suite SlaveUpdates
+  main-is:          SlaveUpdates.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,
diff --git a/makefile b/makefile
new file mode 100644 (file)
index 0000000..e99dd07
--- /dev/null
+++ b/makefile
@@ -0,0 +1,8 @@
+all-test:
+       cabal clean
+       cabal configure --enable-test
+       cabal build
+       cabal test
+
+clean-all-state:
+       find . -name state -type d -exec rm -rf {} \;
diff --git a/test/Simple.hs b/test/Simple.hs
new file mode 100644 (file)
index 0000000..803955e
--- /dev/null
@@ -0,0 +1,40 @@
+{-# LANGUAGE TypeFamilies #-}
+
+import Data.Acid
+import Data.Acid.Centered
+
+import Control.Monad (void, when)
+import Control.Concurrent (threadDelay)
+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/Simple/s1" "localhost" 3333 (IntState 0)
+    delaySec 5
+    val <- query acid GetState
+    closeAcidState acid
+    when (val /= 23) $ putStrLn "Slave hasn't got value." >> exitFailure
+
+main :: IO ()
+main = do
+    cleanup "state/Simple"
+    acid <- openMasterStateFrom "state/Simple/m" "127.0.0.1" 3333 (IntState 0)
+    update acid (SetState 23)
+    slave
+    closeAcidState acid
+    exitSuccess
+
diff --git a/test/SlaveUpdates b/test/SlaveUpdates
new file mode 100755 (executable)
index 0000000..ad63fb7
Binary files /dev/null and b/test/SlaveUpdates differ
diff --git a/test/SlaveUpdates.hs b/test/SlaveUpdates.hs
new file mode 100644 (file)
index 0000000..56969cf
--- /dev/null
@@ -0,0 +1,52 @@
+{-# LANGUAGE TypeFamilies #-}
+
+import Data.Acid
+import Data.Acid.Centered
+
+import Control.Monad (void, when)
+import Control.Concurrent (threadDelay)
+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
+slave1 :: IO ()
+slave1 = do
+    acid <- enslaveStateFrom "state/SlaveUpdates/s1" "localhost" 3333 (IntState 0)
+    update acid (SetState 23)
+    val <- query acid GetState
+    closeAcidState acid
+    when (val /= 23) $ putStrLn "Slave 1 hasn't got value." >> exitFailure
+
+slave2 :: IO ()
+slave2 = do
+    acid <- enslaveStateFrom "state/SlaveUpdates/s2" "localhost" 3333 (IntState 0)
+    delaySec 5
+    val <- query acid GetState
+    closeAcidState acid
+    when (val /= 23) $ putStrLn "Slave 2 hasn't got value." >> exitFailure
+
+main :: IO ()
+main = do
+    cleanup "state/SlaveUpdates"
+
+    acid <- openMasterStateFrom "state/SlaveUpdates/m" "127.0.0.1" 3333 (IntState 0)
+    slave1
+    slave2
+    val <- query acid GetState
+    closeAcidState acid
+    when (val /= 23) $ putStrLn "Master hasn't got value." >> exitFailure
+
+    exitSuccess
+
diff --git a/test/readme.md b/test/readme.md
new file mode 100644 (file)
index 0000000..ef19506
--- /dev/null
@@ -0,0 +1,22 @@
+This directory contains test cases to verify functionality.
+
+# Simple
+
+A test for simple replication. Change initial state by master, check whether
+state replicated to Slave.
+
+# SlaveUpdates
+
+Can Slaves request Updates successfully?
+Do they also get the transaction result (not only updated state)?
+Do Master and other Slaves get the update?
+
+# CRCSuccess
+
+Is a changed state from Master replicated by Slaves and CRC check successful?
+
+# CRCFail
+
+For diverged state the CRC check must fail (unless Checkpoints were replicated).
+
+
diff --git a/test/simple.hs b/test/simple.hs
deleted file mode 100644 (file)
index fccabbf..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-{-# LANGUAGE TypeFamilies #-}
-
-import Data.Acid
-import Data.Acid.Centered
---import Data.SafeCopy
---import Data.Typeable
-
-import Control.Monad (void)
-import Control.Concurrent
-import System.Exit
-
--- state structures
-import IntCommon
-
-delaySec :: Int -> IO ()
-delaySec n = threadDelay $ n*1000*1000
-
--- actual test
-master :: IO ()
-master = do
-    acid <- openMasterStateFrom "state/simple/m" "127.0.0.1" 3333 (IntState 0)
-    update acid (SetState 23)
-    delaySec 10
-    closeAcidState acid
-
-slave :: IO ()
-slave = do
-    acid <- enslaveStateFrom "state/simple/s1" "localhost" 3333 (IntState 0)
-    delaySec 2
-    val <- query acid GetState
-    closeAcidState acid
-    if val == 23 then
-        exitSuccess
-    else
-        exitFailure
-
-main :: IO ()
-main = do
-    void $ forkIO master
-    delaySec 1
-    slave
-    exitSuccess
-