8
8
{-# LANGUAGE RankNTypes #-}
9
9
{-# LANGUAGE TypeApplications #-}
10
10
11
- module AutomatedTestRunner (Example , getGenesisConfig , loadNKeys , doUpdate , onStartup , on , getScript , runScript , NodeType (.. ), startNode ) where
11
+ module AutomatedTestRunner (Example , getGenesisConfig , loadNKeys , doUpdate , onStartup , on , getScript , runScript , NodeType (.. ), startNode , stopNode , NodeHandle ) where
12
12
13
13
import Brick hiding (on )
14
14
import Brick.BChan
@@ -35,7 +35,7 @@ import Options.Applicative (Parser, execParser, footerDoc, fullDesc,
35
35
header , help , helper , info , infoOption , long , progDesc )
36
36
import Paths_cardano_sl (version )
37
37
import PocMode (AuxxContext (AuxxContext , acRealModeContext ),
38
- AuxxMode , realModeToAuxx )
38
+ PocMode , realModeToAuxx )
39
39
import Pos.Chain.Block (LastKnownHeaderTag )
40
40
import Pos.Chain.Genesis as Genesis
41
41
(Config (configGeneratedSecrets , configProtocolMagic ),
@@ -69,11 +69,13 @@ import Pos.Util (lensOf, logException)
69
69
import Pos.Util.CompileInfo (CompileTimeInfo (ctiGitRevision ),
70
70
HasCompileInfo , compileInfo , withCompileInfo )
71
71
import Pos.Util.UserSecret (readUserSecret , usKeys , usPrimKey , usVss )
72
- import Pos.Util.Wlog (LoggerName )
72
+ import Pos.Util.Wlog (LoggerName , logWarning )
73
73
import Pos.WorkMode (EmptyMempoolExt , RealMode )
74
74
import Prelude (show )
75
75
import Text.PrettyPrint.ANSI.Leijen (Doc )
76
76
import Universum hiding (on , show , state , when )
77
+ import System.Process
78
+ import System.Posix.Signals
77
79
78
80
class TestScript a where
79
81
getScript :: a -> Script
@@ -97,7 +99,7 @@ data Script = Script
97
99
, startupActions :: [ SlotTrigger ]
98
100
} deriving (Show , Generic )
99
101
100
- data SlotTrigger = SlotTrigger (Dict HasConfigurations -> Diffusion AuxxMode -> AuxxMode () )
102
+ data SlotTrigger = SlotTrigger (Dict HasConfigurations -> Diffusion PocMode -> PocMode () )
101
103
102
104
instance Show SlotTrigger where
103
105
show _ = " IO ()"
@@ -115,8 +117,6 @@ instance HasEpochSlots => TestScript (Example a) where
115
117
instance TestScript Script where
116
118
getScript = identity
117
119
118
- data NodeHandle = NodeHandle (Async () )
119
-
120
120
data EpochSlots = EpochSlots { epochSlots :: SlotCount , config :: Config }
121
121
type HasEpochSlots = Given EpochSlots
122
122
@@ -196,34 +196,34 @@ runWithConfig ScriptRunnerOptions{srCommonNodeArgs,srPeers} inputParams genesisC
196
196
thing3 :: (TestScript a , HasCompileInfo , HasConfigurations ) => Config -> TxpConfiguration -> InputParams2 a -> NodeResources () -> IO ()
197
197
thing3 genesisConfig txpConfig inputParams nr = do
198
198
let
199
- toRealMode :: AuxxMode a -> RealMode EmptyMempoolExt a
199
+ toRealMode :: PocMode a -> RealMode EmptyMempoolExt a
200
200
toRealMode auxxAction = do
201
201
realModeContext <- ask
202
202
lift $ runReaderT auxxAction $ AuxxContext { acRealModeContext = realModeContext }
203
203
thing2 :: Diffusion (RealMode () ) -> RealMode EmptyMempoolExt ()
204
204
thing2 diffusion = toRealMode (thing5 (hoistDiffusion realModeToAuxx toRealMode diffusion))
205
- thing5 :: Diffusion AuxxMode -> AuxxMode ()
205
+ thing5 :: Diffusion PocMode -> PocMode ()
206
206
thing5 = runNode genesisConfig txpConfig nr thing4
207
- thing4 :: [ (Text , Diffusion AuxxMode -> AuxxMode () ) ]
207
+ thing4 :: [ (Text , Diffusion PocMode -> PocMode () ) ]
208
208
thing4 = workers genesisConfig inputParams
209
209
runRealMode updateConfiguration genesisConfig txpConfig nr thing2
210
210
211
- workers :: (HasConfigurations , TestScript a ) => Genesis. Config -> InputParams2 a -> [ (Text , Diffusion AuxxMode -> AuxxMode () ) ]
211
+ workers :: (HasConfigurations , TestScript a ) => Genesis. Config -> InputParams2 a -> [ (Text , Diffusion PocMode -> PocMode () ) ]
212
212
workers genesisConfig InputParams2 {ip2EventChan,ip2Script,ip2ReplyChan} =
213
213
[ ( T. pack " worker1" , worker1 genesisConfig ip2Script ip2EventChan)
214
214
, ( " worker2" , worker2 ip2EventChan)
215
215
, ( " brick reply worker" , brickReplyWorker ip2ReplyChan)
216
216
]
217
217
218
- brickReplyWorker :: HasConfigurations => BChan Reply -> Diffusion AuxxMode -> AuxxMode ()
218
+ brickReplyWorker :: HasConfigurations => BChan Reply -> Diffusion PocMode -> PocMode ()
219
219
brickReplyWorker replyChan diffusion = do
220
220
reply <- liftIO $ readBChan replyChan
221
221
case reply of
222
222
TriggerShutdown -> do
223
223
triggerShutdown
224
224
brickReplyWorker replyChan diffusion
225
225
226
- worker2 :: HasConfigurations => BChan CustomEvent -> Diffusion AuxxMode -> AuxxMode ()
226
+ worker2 :: HasConfigurations => BChan CustomEvent -> Diffusion PocMode -> PocMode ()
227
227
worker2 eventChan diffusion = do
228
228
localTip <- getTipHeader
229
229
headerRef <- view (lensOf @ LastKnownHeaderTag )
@@ -238,20 +238,20 @@ worker2 eventChan diffusion = do
238
238
threadDelay 100000
239
239
worker2 eventChan diffusion
240
240
241
- worker1 :: (HasConfigurations , TestScript a ) => Genesis. Config -> a -> BChan CustomEvent -> Diffusion (AuxxMode ) -> AuxxMode ()
241
+ worker1 :: (HasConfigurations , TestScript a ) => Genesis. Config -> a -> BChan CustomEvent -> Diffusion (PocMode ) -> PocMode ()
242
242
worker1 genesisConfig script eventChan diffusion = do
243
243
let
244
- handler :: SlotId -> AuxxMode ()
244
+ handler :: SlotId -> PocMode ()
245
245
handler slotid = do
246
246
liftIO $ writeBChan eventChan $ CESlotStart $ SlotStart (getEpochIndex $ siEpoch slotid) (getSlotIndex $ siSlot slotid)
247
247
case Map. lookup slotid (slotTriggers realScript) of
248
248
Just (SlotTrigger act) -> runAction act
249
249
Nothing -> pure ()
250
250
pure ()
251
251
realScript = getScript script
252
- errhandler :: Show e => e -> AuxxMode ()
252
+ errhandler :: Show e => e -> PocMode ()
253
253
errhandler e = print e
254
- runAction :: (Dict HasConfigurations -> Diffusion AuxxMode -> AuxxMode () ) -> AuxxMode ()
254
+ runAction :: (Dict HasConfigurations -> Diffusion PocMode -> PocMode () ) -> PocMode ()
255
255
runAction act = do
256
256
act Dict diffusion `catch` errhandler @ SomeException
257
257
realWorker = do
@@ -314,7 +314,7 @@ getGenesisConfig = sbGenesisConfig <$> get
314
314
data SlotCreationFailure = SlotCreationFailure { msg :: Text , slotsInEpoch :: SlotCount } deriving Show
315
315
instance Exception SlotCreationFailure where
316
316
317
- onStartup :: (Dict HasConfigurations -> Diffusion AuxxMode -> AuxxMode () ) -> Example ()
317
+ onStartup :: (Dict HasConfigurations -> Diffusion PocMode -> PocMode () ) -> Example ()
318
318
onStartup action = do
319
319
oldsb <- get
320
320
let
@@ -328,7 +328,7 @@ onStartup action = do
328
328
put newsb
329
329
pure ()
330
330
331
- on :: (Word64 , Word16 ) -> (Dict HasConfigurations -> Diffusion AuxxMode -> AuxxMode () ) -> Example ()
331
+ on :: (Word64 , Word16 ) -> (Dict HasConfigurations -> Diffusion PocMode -> PocMode () ) -> Example ()
332
332
on (epoch, slot) action = do
333
333
oldsb <- get
334
334
let
@@ -349,7 +349,7 @@ on (epoch, slot) action = do
349
349
}
350
350
put newsb
351
351
352
- doUpdate :: HasConfigurations => Diffusion AuxxMode -> Config -> Int -> BlockVersion -> SoftwareVersion -> BlockVersionModifier -> AuxxMode ()
352
+ doUpdate :: HasConfigurations => Diffusion PocMode -> Config -> Int -> BlockVersion -> SoftwareVersion -> BlockVersionModifier -> PocMode ()
353
353
doUpdate diffusion genesisConfig keyIndex blockVersion softwareVersion blockVersionModifier = do
354
354
let
355
355
-- tag = SystemTag "win64"
@@ -379,12 +379,12 @@ doUpdate diffusion genesisConfig keyIndex blockVersion softwareVersion blockVers
379
379
putText (sformat (" Update proposal submitted along with votes, upId: " % hashHexF% " \n " ) upid)
380
380
print updateProposal
381
381
382
- loadNKeys :: Integer -> AuxxMode ()
382
+ loadNKeys :: Integer -> PocMode ()
383
383
loadNKeys n = do
384
384
let
385
385
fmt :: Format r (Integer -> r )
386
386
fmt = " ../state-demo/generated-keys/rich/" % int % " .key"
387
- loadKey :: Integer -> AuxxMode ()
387
+ loadKey :: Integer -> PocMode ()
388
388
loadKey x = do
389
389
secret <- readUserSecret (T. unpack $ sformat fmt x)
390
390
let
@@ -394,14 +394,30 @@ loadNKeys n = do
394
394
addSecretKey $ noPassEncrypt primSk
395
395
mapM_ loadKey (range (0 ,n - 1 ))
396
396
397
+ data NodeHandle = NodeHandle (Async () ) ProcessHandle
398
+
397
399
startNode :: NodeType -> IO NodeHandle
398
400
startNode (Core idx) = do
401
+ stdout <- openFile (" poc-state/core-stdout-" <> show idx) WriteMode
399
402
let
400
- _params = [ " --configuration-file" , " ../lib/configuration.yaml"
403
+ params = [ " --configuration-file" , " ../lib/configuration.yaml"
401
404
, " --system-start" , " 1543100429"
402
405
, " --db-path" , " poc-state/core" <> (show idx) <> " -db"
403
406
, " --keyfile" , " poc-state/secret" <> (show idx) <> " .key"
404
407
]
408
+ pc :: CreateProcess
409
+ pc = (proc " cardano-node-simple" params) { std_out = UseHandle stdout }
410
+ (stdin, stdout, stderr, ph) <- createProcess pc
405
411
later <- async $ do
412
+ waitForProcess ph
406
413
pure ()
407
- pure $ NodeHandle later
414
+ pure $ NodeHandle later ph
415
+
416
+ stopNode :: NodeHandle -> IO ()
417
+ stopNode (NodeHandle async ph) = do
418
+ maybePid <- getPid ph
419
+ case maybePid of
420
+ Just pid -> do
421
+ signalProcess sigINT pid
422
+ Nothing -> do
423
+ logWarning " node already stopped when trying to stop it"
0 commit comments