@@ -31,6 +31,9 @@ def tearDown(self):
3131 def test_main (self ):
3232 command = ["smart_worker.py" , self .command_manager ._commands_filename , self .logs_dir ]
3333 assert_equal (call (command ), 0 )
34+ # Simulate a resume, i.e. re-run the command, the output/error should be concatenated.
35+ self .command_manager .set_commands_to_run (self .commands )
36+ assert_equal (call (command ), 0 )
3437
3538 # Check output logs
3639 filenames = os .listdir (self .logs_dir )
@@ -41,13 +44,29 @@ def test_main(self):
4144 uid = os .path .splitext (os .path .basename (log_filename ))[0 ]
4245 executed_command = self .commands [self .commands_uid .index (uid )]
4346
44- # First line is the executed command in comment
45- header = logfile .readline ().strip ()
46- assert_equal (header , "# " + executed_command )
47+ # Since the command was run twice.
48+ for i in range (2 ):
49+ # First line is the datetime of the executed command in comment.
50+ line = logfile .readline ().strip ()
51+
52+ if i == 0 :
53+ assert_true ("Started" in line )
54+ else :
55+ assert_true ("Resumed" in line )
56+
57+ assert_true (line .startswith ("## SMART_DISPATCH" ))
58+ assert_true (time .strftime ("%Y-%m-%d %H:%M:" ) in line ) # Don't check seconds.
59+
60+ # Second line is the executed command in comment.
61+ line = logfile .readline ().strip ()
62+ assert_true (executed_command in line )
4763
48- # Next should be the command's output
49- output = logfile .readline ().strip ()
50- assert_equal (output , executed_command [- 1 ]) # We know those are 'echo' of a digit
64+ # Next should be the command's output
65+ line = logfile .readline ().strip ()
66+ assert_equal (line , executed_command [- 1 ]) # We know those are 'echo' of a digit
67+
68+ # Empty line
69+ assert_equal (logfile .readline ().strip (), "" )
5170
5271 # Log should be empty now
5372 assert_equal ("" , logfile .read ())
@@ -60,9 +79,25 @@ def test_main(self):
6079 uid = os .path .splitext (os .path .basename (log_filename ))[0 ]
6180 executed_command = self .commands [self .commands_uid .index (uid )]
6281
63- # First line is the executed command in comment
64- header = logfile .readline ().strip ()
65- assert_equal (header , "# " + executed_command )
82+ # Since the command was run twice.
83+ for i in range (2 ):
84+ # First line is the datetime of the executed command in comment.
85+ line = logfile .readline ().strip ()
86+
87+ if i == 0 :
88+ assert_true ("Started" in line )
89+ else :
90+ assert_true ("Resumed" in line )
91+
92+ assert_true (line .startswith ("## SMART_DISPATCH" ))
93+ assert_true (time .strftime ("%Y-%m-%d %H:%M:" ) in line ) # Don't check seconds.
94+
95+ # Second line is the executed command in comment.
96+ line = logfile .readline ().strip ()
97+ assert_true (executed_command in line )
98+
99+ # Empty line
100+ assert_equal (logfile .readline ().strip (), "" )
66101
67102 # Log should be empty now
68103 assert_equal ("" , logfile .read ())
0 commit comments