Skip to content

Commit 28c1be3

Browse files
committed
Fix resource (worker processes) leaks at least when tests pass
1 parent 3023a96 commit 28c1be3

7 files changed

Lines changed: 38 additions & 19 deletions

File tree

src/tests/compile_tests/async_implementation/test_async.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ def test30(self):
647647
self.assertEqual(request.result(), numpy.arange(1, 11) | units.m)
648648
t2 = time.time()
649649
self.assertGreater(t2-t1, 1.)
650+
instance1.stop()
650651

651652
def test31(self):
652653
""" test a grid attribute request, subgrids """
@@ -662,6 +663,7 @@ def test31(self):
662663
self.assertEqual(request2.result(), numpy.arange(6, 11) | units.m)
663664
t2 = time.time()
664665
self.assertGreater(t2-t1, 1.)
666+
instance1.stop()
665667

666668
def test32(self):
667669
""" test a grid attribute request setter """
@@ -681,6 +683,7 @@ def test32(self):
681683
self.assertEqual(instance1.grid.x, (11.+numpy.arange(1, 11)) | units.m)
682684
t2 = time.time()
683685
self.assertLess(t2-t1, 0.5)
686+
instance1.stop()
684687

685688
def test33(self):
686689
""" test a grid attribute request, subgrids """
@@ -697,13 +700,15 @@ def test33(self):
697700
self.assertGreater(t2-t1, 1.)
698701
self.assertEqual(instance1.grid.x[::2], (11.+numpy.arange(1, 11, 2)) | units.m)
699702
self.assertEqual(instance1.grid.x[1::2], (numpy.arange(2, 11, 2)) | units.m)
703+
instance1.stop()
700704

701705
def test34(self):
702706
""" test a grid attribute request, subgrids """
703707
instance1 = ForTesting(self.exefile, redirection="none")
704708
grid = instance1.grid.copy()
705709
request = instance1.grid.request.x
706710
self.assertEqual(request.result(), numpy.arange(1, 11) | units.m)
711+
instance1.stop()
707712

708713
def test35(self):
709714
""" test a grid attribute request setter with state"""
@@ -729,6 +734,7 @@ def test35(self):
729734
self.assertEqual(instance1.grid.x, (12. + numpy.arange(1, 11)) | units.m)
730735
t2 = time.time()
731736
self.assertLess(t2-t1, 0.5)
737+
instance1.stop()
732738

733739
def test36(self):
734740
""" more state tests"""
@@ -741,6 +747,7 @@ def test36(self):
741747
self.assertEqual(instance1.get_name_of_current_state(), '2')
742748
# ie state changes upon completion of call at wait. This is
743749
# sort of ok, alternatively state could be changed immediately...
750+
instance1.stop()
744751

745752

746753
class TestASyncDistributed(TestASync):

src/tests/compile_tests/c_implementation/test_c_implementation.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,34 +93,28 @@ def test7(self):
9393

9494
def test7b(self):
9595
instance = ForTestingInterface(self.exefile)
96-
9796
out, error = instance.echo_int(numpy.arange(2000000))
97+
instance.stop()
9898

9999
self.assertEqual(error, [0]*2000000)
100100
self.assertEqual(out, numpy.arange(2000000))
101101

102-
instance.stop()
103-
104102
def test7c(self):
105103
instance = ForTestingInterface(self.exefile)
106-
107104
out, error = instance.echo_string(["abc"]*10)
105+
instance.stop()
108106

109107
self.assertEqual(error, [0]*10)
110108
self.assertEqual(out, ["abc"]*10)
111109

112-
instance.stop()
113-
114110
def test7d(self):
115111
instance = ForTestingInterface(self.exefile)
116-
117112
out, error = instance.echo_string(["abc"]*100000)
113+
instance.stop()
118114

119115
self.assertEqual(error, [0]*100000)
120116
self.assertEqual(out, ["abc"]*100000)
121117

122-
instance.stop()
123-
124118
def test8(self):
125119
instance = ForTestingInterface(self.exefile)
126120
out1, out2, error = instance.echo_strings("abc", "def")
@@ -386,6 +380,8 @@ def test29(self):
386380
request2.wait()
387381
port_id1, error1 = request1.result()
388382
port_id2, error2 = request2.result()
383+
instance1.stop()
384+
instance2.stop()
389385
self.assertTrue(port_id1 >= 0)
390386
self.assertTrue(port_id2 >= 0)
391387
self.assertEqual(error1, 0)

src/tests/compile_tests/c_implementation/test_c_implementation_simplified.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ def test29(self):
341341
request2.wait()
342342
port_id1, error1 = request1.result()
343343
port_id2, error2 = request2.result()
344+
instance1.stop()
345+
instance2.stop()
344346
self.assertTrue(port_id1 >= 0)
345347
self.assertTrue(port_id2 >= 0)
346348
self.assertEqual(error1, 0)

src/tests/compile_tests/fortran_implementation/test_fortran_implementation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def define_methods(self, object):
2626
units.m,
2727
object.ERROR_CODE,
2828
)
29-
)
29+
)
3030
"""
3131

3232

@@ -196,11 +196,13 @@ def test16(self):
196196
def test16b(self):
197197
instance = ForTesting(self.exefile)
198198
output = instance.echo_logical([True, True, False, True, False]*256)
199+
instance.stop()
199200
self.assertEqual(output, [True, True, False, True, False]*256)
200201

201202
def test16c(self):
202203
instance = ForTesting(self.exefile, redirection="none")
203204
output = instance.echo_logical2([True, True, False, True, False]*1024)
205+
instance.stop()
204206
self.assertEqual(output, [True, True, False, True, False]*1024)
205207

206208
def xtest20(self):
@@ -296,6 +298,8 @@ def test19(self):
296298
request2.wait()
297299
port_id1, error1 = request1.result()
298300
port_id2, error2 = request2.result()
301+
instance1.stop()
302+
instance2.stop()
299303
self.assertTrue(port_id1 >= 0)
300304
self.assertTrue(port_id2 >= 0)
301305
self.assertEqual(error1, 0)

src/tests/compile_tests/fortran_implementation/test_fortran_sockets_implementation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,13 @@ def test16(self):
187187
def test16b(self):
188188
instance = ForTesting(self.exefile, channel_type="sockets")
189189
output = instance.echo_logical([True, True, False, True, False])
190+
instance.stop()
190191
self.assertEqual(output, [True, True, False, True, False])
191192

192193
def test16c(self):
193194
instance = ForTesting(self.exefile, redirection="none")
194195
output = instance.echo_logical2([True, True, False, True, False]*1024)
196+
instance.stop()
195197
self.assertEqual(output, [True, True, False, True, False]*1024)
196198

197199
def xtest20(self):

src/tests/compile_tests/test_python_implementation.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ def test02(self):
468468
output_message = python_code.ClientSideMPIMessage(0, 10, 1)
469469

470470
x.handle_message(input_message, output_message)
471+
del x
471472

472473
self.assertEqual(len(output_message.ints), 1)
473474
self.assertEqual(len(output_message.doubles), 1)
@@ -485,6 +486,7 @@ def test03(self):
485486
output_message = python_code.ClientSideMPIMessage(0, 10, 1)
486487

487488
x.handle_message(input_message, output_message)
489+
del x
488490

489491
self.assertEqual(len(output_message.ints), 1)
490492
self.assertEqual(len(output_message.doubles), 0)
@@ -502,6 +504,7 @@ def test04(self):
502504
output_message = python_code.ClientSideMPIMessage(0, 10, 4)
503505

504506
x.handle_message(input_message, output_message)
507+
del x
505508

506509
self.assertEqual(len(output_message.ints), 4)
507510
self.assertEqual(len(output_message.doubles), 0)
@@ -536,8 +539,6 @@ def test06(self):
536539
self.assertEqual(answer[1], 11.0)
537540
x.stop()
538541

539-
x.stop()
540-
541542
def test07(self):
542543
x = self.ForTestingInterface()
543544

@@ -546,8 +547,6 @@ def test07(self):
546547
self.assertEqual(int_out, 20)
547548
x.stop()
548549

549-
x.stop()
550-
551550
def test08(self):
552551
implementation = ForTestingImplementation()
553552
x = python_code.PythonImplementation(implementation, ForTestingInterface)
@@ -559,53 +558,55 @@ def test08(self):
559558

560559
x.handle_message(input_message, output_message)
561560

561+
del x
562+
562563
self.assertEqual(len(output_message.ints), 2)
563564
self.assertEqual(output_message.ints[0], 0)
564565
self.assertEqual(output_message.ints[1], 20)
565566

566567
def test09(self):
567568
x = self.ForTestingInterface()
568569
string_out, error = x.echo_string("1234567")
570+
x.stop()
569571
self.assertEqual(error, 0)
570572
self.assertEqual(string_out, "1234567")
571-
x.stop()
572573

573574
def test10(self):
574575
x = self.ForTestingInterface()
575576
string_out, error = x.echo_string(["aaaaa", "bbbb"])
577+
x.stop()
576578
self.assertEqual(error[0], 0)
577579
self.assertEqual(len(string_out), 2)
578580
self.assertEqual(string_out[0], "aaaaa")
579581
self.assertEqual(string_out[1], "bbbb")
580-
x.stop()
581582

582583
def test11(self):
583584
x = self.ForTestingInterface()
584585
string_out, error = x.echo_string(["", "bbbb"])
586+
x.stop()
585587
self.assertEqual(error[0], 0)
586588
self.assertEqual(len(string_out), 2)
587589
self.assertEqual(string_out[0], "")
588590
self.assertEqual(string_out[1], "bbbb")
589-
x.stop()
590591

591592
def test12(self):
592593
x = self.ForTestingInterface()
593594
str1_out, str2_out, error = x.echo_strings("abc", "def")
595+
x.stop()
594596
self.assertEqual(error, 0)
595597
self.assertEqual(str1_out, "cba")
596598
self.assertEqual(str2_out, "fed")
597-
x.stop()
598599

599600
def test13(self):
600601
x = self.ForTestingInterface()
601602
str1_out, str2_out, error = x.echo_strings(["abc", "def"], ["ghi", "jkl"])
603+
x.stop()
602604
self.assertEqual(error[0], 0)
603605
self.assertEqual(error[1], 0)
604606
self.assertEqual(str1_out[0], "cba")
605607
self.assertEqual(str1_out[1], "fed")
606608
self.assertEqual(str2_out[0], "ihg")
607609
self.assertEqual(str2_out[1], "lkj")
608-
x.stop()
609610

610611
def test14(self):
611612
x = self.ForTestingInterface()
@@ -946,6 +947,8 @@ def test26(self):
946947
request2.wait()
947948
port_id1, error1 = request1.result()
948949
port_id2, error2 = request2.result()
950+
instance1.stop()
951+
instance2.stop()
949952
self.assertTrue(port_id1 >= 0)
950953
self.assertTrue(port_id2 >= 0)
951954
self.assertEqual(error1, 0)
@@ -1057,6 +1060,7 @@ def test30(self):
10571060
self.assertAlmostRelativeEquals(output, [6.0, 7.0, 8.0])
10581061
output = instance.sum_doubles(5, input)
10591062
self.assertAlmostRelativeEquals(output, [6.0, 7.0, 8.0])
1063+
instance.stop()
10601064

10611065
def test31(self):
10621066
x = self.ForTesting()

src/tests/compile_tests/test_python_sockets_implementation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def test2(self):
5353
output_message = python_code.SocketMessage(0, 10, 1)
5454

5555
x.handle_message(input_message, output_message)
56+
del implementation
5657

5758
self.assertEqual(len(output_message.ints), 1)
5859
self.assertEqual(len(output_message.doubles), 1)
@@ -75,6 +76,7 @@ def test3(self):
7576
self.assertEqual(len(output_message.doubles), 0)
7677
self.assertEqual(output_message.ints[0], 0)
7778
self.assertEqual(implementation.masses[1], 12.0)
79+
del implementation
7880

7981
def test4(self):
8082
implementation = test_python_implementation.ForTestingImplementation()
@@ -96,6 +98,7 @@ def test4(self):
9698
self.assertEqual(implementation.masses[2], 13.0)
9799
self.assertEqual(implementation.masses[3], 14.0)
98100
self.assertEqual(implementation.masses[4], 15.0)
101+
del implementation
99102

100103
def test8(self):
101104
implementation = test_python_implementation.ForTestingImplementation()
@@ -107,6 +110,7 @@ def test8(self):
107110
output_message = python_code.SocketMessage(0, 10, 1)
108111

109112
x.handle_message(input_message, output_message)
113+
del implementation
110114

111115
self.assertEqual(len(output_message.ints), 2)
112116
self.assertEqual(output_message.ints[0], 0)

0 commit comments

Comments
 (0)