Skip to content

Commit addb25c

Browse files
author
Dimitar Tasev
committed
Don't use length of list, check for presence in list
1 parent 0f98739 commit addb25c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mantidimaging/core/parallel/test/utility_test.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import numpy as np
66
import SharedArray as sa
77

8-
from mantidimaging.core.parallel.utility import (create_array, execute_impl, free_all_owned_by_this_instance,
9-
multiprocessing_necessary)
8+
from mantidimaging.core.parallel.utility import (create_array, create_shared_name, execute_impl,
9+
free_all_owned_by_this_instance, multiprocessing_necessary)
1010

1111

1212
def test_correctly_chooses_parallel():
@@ -42,19 +42,21 @@ def test_execute_impl_par(mock_pool):
4242

4343

4444
def test_free_all_owned_by_this_instance():
45-
create_array((10, 10), np.float32, random_name=True)
46-
create_array((10, 10), np.float32, random_name=True)
47-
create_array((10, 10), np.float32, random_name=True)
45+
name1 = create_shared_name()
46+
name2 = create_shared_name()
47+
name3 = create_shared_name()
48+
create_array((10, 10), np.float32, name=name1)
49+
create_array((10, 10), np.float32, name=name2)
50+
create_array((10, 10), np.float32, name=name3)
4851

4952
temp_name = "not_this_instance"
5053
sa.create("not_this_instance", (10, 10))
5154

52-
# these tests run in parallel, this should avoid some race conditions at least
53-
initial = len(sa.list())
54-
# frees the 3 allocated above
5555
free_all_owned_by_this_instance()
56-
expected = initial - 3
57-
assert len(sa.list()) == expected
56+
assert name1 not in [arr.name.decode("utf-8") for arr in sa.list()]
57+
assert name2 not in [arr.name.decode("utf-8") for arr in sa.list()]
58+
assert name3 not in [arr.name.decode("utf-8") for arr in sa.list()]
59+
assert temp_name in [arr.name.decode("utf-8") for arr in sa.list()]
5860
sa.delete(temp_name)
5961

6062

0 commit comments

Comments
 (0)