1919from __future__ import division
2020from __future__ import print_function
2121
22- import contextlib
2322import os
2423import pytest
2524import random
26- import shutil
2725import signal
2826import sys
29- import subprocess
30- import tempfile
31- import time
3227
3328import numpy as np
3429import pyarrow as pa
@@ -106,76 +101,6 @@ def assert_get_object_equal(unit_test, client1, client2, object_id,
106101 assert plasma .buffers_equal (metadata , client1_metadata )
107102
108103
109- @contextlib .contextmanager
110- def start_plasma_store (plasma_store_memory = DEFAULT_PLASMA_STORE_MEMORY ,
111- use_valgrind = False , use_profiler = False ,
112- use_one_memory_mapped_file = False ,
113- plasma_directory = None , use_hugepages = False ):
114- """Start a plasma store process.
115- Args:
116- use_valgrind (bool): True if the plasma store should be started inside
117- of valgrind. If this is True, use_profiler must be False.
118- use_profiler (bool): True if the plasma store should be started inside
119- a profiler. If this is True, use_valgrind must be False.
120- stdout_file: A file handle opened for writing to redirect stdout to. If
121- no redirection should happen, then this should be None.
122- stderr_file: A file handle opened for writing to redirect stderr to. If
123- no redirection should happen, then this should be None.
124- use_one_memory_mapped_file: If True, then the store will use only a
125- single memory-mapped file.
126- Return:
127- A tuple of the name of the plasma store socket and the process ID of
128- the plasma store process.
129- """
130- if use_valgrind and use_profiler :
131- raise Exception ("Cannot use valgrind and profiler at the same time." )
132-
133- tmpdir = tempfile .mkdtemp (prefix = 'test_plasma-' )
134- try :
135- plasma_store_name = os .path .join (tmpdir , 'plasma.sock' )
136- plasma_store_executable = os .path .join (pa .__path__ [0 ], "plasma_store" )
137- command = [plasma_store_executable ,
138- "-s" , plasma_store_name ,
139- "-m" , str (plasma_store_memory )]
140- if use_one_memory_mapped_file :
141- command += ["-f" ]
142- if plasma_directory :
143- command += ["-d" , plasma_directory ]
144- if use_hugepages :
145- command += ["-h" ]
146- stdout_file = None
147- stderr_file = None
148- if use_valgrind :
149- command = ["valgrind" ,
150- "--track-origins=yes" ,
151- "--leak-check=full" ,
152- "--show-leak-kinds=all" ,
153- "--leak-check-heuristics=stdstring" ,
154- "--error-exitcode=1" ] + command
155- proc = subprocess .Popen (command , stdout = stdout_file ,
156- stderr = stderr_file )
157- time .sleep (1.0 )
158- elif use_profiler :
159- command = ["valgrind" , "--tool=callgrind" ] + command
160- proc = subprocess .Popen (command , stdout = stdout_file ,
161- stderr = stderr_file )
162- time .sleep (1.0 )
163- else :
164- proc = subprocess .Popen (command , stdout = stdout_file ,
165- stderr = stderr_file )
166- time .sleep (0.1 )
167- rc = proc .poll ()
168- if rc is not None :
169- raise RuntimeError ("plasma_store exited unexpectedly with "
170- "code %d" % (rc ,))
171-
172- yield plasma_store_name , proc
173- finally :
174- if proc .poll () is None :
175- proc .kill ()
176- shutil .rmtree (tmpdir )
177-
178-
179104@pytest .mark .plasma
180105class TestPlasmaClient (object ):
181106
@@ -185,7 +110,8 @@ def setup_method(self, test_method):
185110
186111 import pyarrow .plasma as plasma
187112 # Start Plasma store.
188- self .plasma_store_ctx = start_plasma_store (
113+ self .plasma_store_ctx = plasma .start_plasma_store (
114+ plasma_store_memory = DEFAULT_PLASMA_STORE_MEMORY ,
189115 use_valgrind = USE_VALGRIND ,
190116 use_one_memory_mapped_file = use_one_memory_mapped_file )
191117 plasma_store_name , self .p = self .plasma_store_ctx .__enter__ ()
@@ -839,8 +765,10 @@ def test_object_id_equality_operators():
839765 reason = "requires hugepage support" )
840766def test_use_huge_pages ():
841767 import pyarrow .plasma as plasma
842- with start_plasma_store (plasma_directory = "/mnt/hugepages" ,
843- use_hugepages = True ) as (plasma_store_name , p ):
768+ with plasma .start_plasma_store (
769+ plasma_store_memory = DEFAULT_PLASMA_STORE_MEMORY ,
770+ plasma_directory = "/mnt/hugepages" ,
771+ use_hugepages = True ) as (plasma_store_name , p ):
844772 plasma_client = plasma .connect (plasma_store_name , "" , 64 )
845773 create_object (plasma_client , 100000000 )
846774
@@ -852,7 +780,9 @@ def test_use_huge_pages():
852780def test_plasma_client_sharing ():
853781 import pyarrow .plasma as plasma
854782
855- with start_plasma_store () as (plasma_store_name , p ):
783+ with plasma .start_plasma_store (
784+ plasma_store_memory = DEFAULT_PLASMA_STORE_MEMORY ) \
785+ as (plasma_store_name , p ):
856786 plasma_client = plasma .connect (plasma_store_name , "" , 64 )
857787 object_id = plasma_client .put (np .zeros (3 ))
858788 buf = plasma_client .get (object_id )
0 commit comments