Skip to content

Commit 0305930

Browse files
committed
Added threads unit test back in
1 parent f0a3889 commit 0305930

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

nipype/pipeline/plugins/tests/test_multiproc.py

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -181,56 +181,56 @@ def find_metrics(nodes, last_node):
181181
# os.remove(LOG_FILENAME)
182182
#
183183
#
184-
#def test_do_not_use_more_threads_then_specified():
185-
# LOG_FILENAME = 'callback.log'
186-
# my_logger = logging.getLogger('callback')
187-
# my_logger.setLevel(logging.DEBUG)
188-
#
189-
# # Add the log message handler to the logger
190-
# handler = logging.FileHandler(LOG_FILENAME)
191-
# my_logger.addHandler(handler)
192-
#
193-
# max_threads = 10
194-
# pipe = pe.Workflow(name='pipe')
195-
# n1 = pe.Node(interface=TestInterfaceSingleNode(), name='n1')
196-
# n2 = pe.Node(interface=TestInterfaceSingleNode(), name='n2')
197-
# n3 = pe.Node(interface=TestInterfaceSingleNode(), name='n3')
198-
# n4 = pe.Node(interface=TestInterfaceSingleNode(), name='n4')
199-
#
200-
# n1.interface.num_threads = 1
201-
# n2.interface.num_threads = 1
202-
# n3.interface.num_threads = 10
203-
# n4.interface.num_threads = 1
204-
#
205-
# pipe.connect(n1, 'output1', n2, 'input1')
206-
# pipe.connect(n1, 'output1', n3, 'input1')
207-
# pipe.connect(n2, 'output1', n4, 'input1')
208-
# pipe.connect(n3, 'output1', n4, 'input2')
209-
# n1.inputs.input1 = 10
210-
# pipe.config['execution']['poll_sleep_duration'] = 1
211-
# pipe.run(plugin='MultiProc', plugin_args={'n_procs': max_threads,
212-
# 'status_callback': log_nodes_cb})
213-
#
214-
# nodes = draw_gantt_chart.log_to_dict(LOG_FILENAME)
215-
# last_node = nodes[-1]
216-
# #usage in every second
217-
# memory, threads = find_metrics(nodes, last_node)
218-
#
219-
# result = True
220-
# for t in threads:
221-
# if t > max_threads:
222-
# result = False
223-
# break
224-
#
225-
# yield assert_equal, result, True, "using more threads than specified"
226-
#
227-
# max_memory = get_system_total_memory_gb()
228-
# result = True
229-
# for m in memory:
230-
# if m > max_memory:
231-
# result = False
232-
# break
233-
# yield assert_equal, result, True,\
234-
# "using more memory than system has (memory is not specified by user)"
235-
#
236-
# os.remove(LOG_FILENAME)
184+
def test_do_not_use_more_threads_then_specified():
185+
LOG_FILENAME = 'callback.log'
186+
my_logger = logging.getLogger('callback')
187+
my_logger.setLevel(logging.DEBUG)
188+
189+
# Add the log message handler to the logger
190+
handler = logging.FileHandler(LOG_FILENAME)
191+
my_logger.addHandler(handler)
192+
193+
max_threads = 4
194+
pipe = pe.Workflow(name='pipe')
195+
n1 = pe.Node(interface=TestInterfaceSingleNode(), name='n1')
196+
n2 = pe.Node(interface=TestInterfaceSingleNode(), name='n2')
197+
n3 = pe.Node(interface=TestInterfaceSingleNode(), name='n3')
198+
n4 = pe.Node(interface=TestInterfaceSingleNode(), name='n4')
199+
200+
n1.interface.num_threads = 1
201+
n2.interface.num_threads = 1
202+
n3.interface.num_threads = 4
203+
n4.interface.num_threads = 1
204+
205+
pipe.connect(n1, 'output1', n2, 'input1')
206+
pipe.connect(n1, 'output1', n3, 'input1')
207+
pipe.connect(n2, 'output1', n4, 'input1')
208+
pipe.connect(n3, 'output1', n4, 'input2')
209+
n1.inputs.input1 = 4
210+
pipe.config['execution']['poll_sleep_duration'] = 1
211+
pipe.run(plugin='MultiProc', plugin_args={'n_procs': max_threads,
212+
'status_callback': log_nodes_cb})
213+
214+
nodes = draw_gantt_chart.log_to_dict(LOG_FILENAME)
215+
last_node = nodes[-1]
216+
#usage in every second
217+
memory, threads = find_metrics(nodes, last_node)
218+
219+
result = True
220+
for t in threads:
221+
if t > max_threads:
222+
result = False
223+
break
224+
225+
yield assert_equal, result, True, "using more threads than specified"
226+
227+
max_memory = get_system_total_memory_gb()
228+
result = True
229+
for m in memory:
230+
if m > max_memory:
231+
result = False
232+
break
233+
yield assert_equal, result, True,\
234+
"using more memory than system has (memory is not specified by user)"
235+
236+
os.remove(LOG_FILENAME)

0 commit comments

Comments
 (0)