@@ 168-201 (lines=34) @@ | ||
165 | nb_job_commands_files = len(os.listdir(path_job_commands)) |
|
166 | assert_equal(nb_job_commands_files-nb_commands_files, len(commands[1::2])) |
|
167 | ||
168 | def test_main_resume_by_expanding_pool(self): |
|
169 | # Create SMART_DISPATCH_LOGS structure. |
|
170 | call(self.launch_command, shell=True) |
|
171 | batch_uid = os.listdir(self.logs_dir)[0] |
|
172 | ||
173 | # Simulate that some commands are in the running state. |
|
174 | nb_commands_files = 2 # 'commands.txt' and 'running_commands.txt' |
|
175 | path_job_commands = os.path.join(self.logs_dir, batch_uid, "commands") |
|
176 | pending_commands_file = pjoin(path_job_commands, "commands.txt") |
|
177 | running_commands_file = pjoin(path_job_commands, "running_commands.txt") |
|
178 | commands = open(pending_commands_file).read().strip().split("\n") |
|
179 | with open(running_commands_file, 'w') as running_commands: |
|
180 | running_commands.write("\n".join(commands[::2]) + "\n") |
|
181 | with open(pending_commands_file, 'w') as pending_commands: |
|
182 | pending_commands.write("\n".join(commands[1::2]) + "\n") |
|
183 | ||
184 | # Remove PBS files so we can check that new ones are going to be created. |
|
185 | for f in os.listdir(path_job_commands): |
|
186 | if f.startswith('job_commands_') and f.endswith('.sh'): |
|
187 | os.remove(pjoin(path_job_commands, f)) |
|
188 | ||
189 | # Should NOT move running commands back to pending but should add new workers. |
|
190 | nb_workers_to_add = 3 |
|
191 | command_line = self.resume_command.format(batch_uid) |
|
192 | command_line += " --expandPool {}".format(nb_workers_to_add) |
|
193 | exit_status = call(command_line, shell=True) |
|
194 | ||
195 | # Test validation |
|
196 | assert_equal(exit_status, 0) |
|
197 | assert_equal(len(open(running_commands_file).readlines()), len(commands[::2])) |
|
198 | assert_equal(len(open(pending_commands_file).readlines()), len(commands[1::2])) |
|
199 | ||
200 | nb_job_commands_files = len(os.listdir(path_job_commands)) |
|
201 | assert_equal(nb_job_commands_files-nb_commands_files, nb_workers_to_add) |
|
202 | ||
@@ 134-166 (lines=33) @@ | ||
131 | assert_equal(len(open(running_commands_file).readlines()), 0) |
|
132 | assert_equal(len(open(pending_commands_file).readlines()), len(commands)) |
|
133 | ||
134 | def test_main_resume_by_expanding_pool_default(self): |
|
135 | # Create SMART_DISPATCH_LOGS structure. |
|
136 | call(self.launch_command, shell=True) |
|
137 | batch_uid = os.listdir(self.logs_dir)[0] |
|
138 | ||
139 | # Simulate that some commands are in the running state. |
|
140 | nb_commands_files = 2 # 'commands.txt' and 'running_commands.txt' |
|
141 | path_job_commands = os.path.join(self.logs_dir, batch_uid, "commands") |
|
142 | pending_commands_file = pjoin(path_job_commands, "commands.txt") |
|
143 | running_commands_file = pjoin(path_job_commands, "running_commands.txt") |
|
144 | commands = open(pending_commands_file).read().strip().split("\n") |
|
145 | with open(running_commands_file, 'w') as running_commands: |
|
146 | running_commands.write("\n".join(commands[::2]) + "\n") |
|
147 | with open(pending_commands_file, 'w') as pending_commands: |
|
148 | pending_commands.write("\n".join(commands[1::2]) + "\n") |
|
149 | ||
150 | # Remove PBS files so we can check that new ones are going to be created. |
|
151 | for f in os.listdir(path_job_commands): |
|
152 | if f.startswith('job_commands_') and f.endswith('.sh'): |
|
153 | os.remove(pjoin(path_job_commands, f)) |
|
154 | ||
155 | # Should NOT move running commands back to pending but should add new workers. |
|
156 | command_line = self.resume_command.format(batch_uid) |
|
157 | command_line += " --expandPool" |
|
158 | exit_status = call(command_line, shell=True) |
|
159 | ||
160 | # Test validation |
|
161 | assert_equal(exit_status, 0) |
|
162 | assert_equal(len(open(running_commands_file).readlines()), len(commands[::2])) |
|
163 | assert_equal(len(open(pending_commands_file).readlines()), len(commands[1::2])) |
|
164 | ||
165 | nb_job_commands_files = len(os.listdir(path_job_commands)) |
|
166 | assert_equal(nb_job_commands_files-nb_commands_files, len(commands[1::2])) |
|
167 | ||
168 | def test_main_resume_by_expanding_pool(self): |
|
169 | # Create SMART_DISPATCH_LOGS structure. |