Merge pull request #1601 from eeff/eeff/dev

test: ft api support restart neuron process
This commit is contained in:
fengzeroz
2023-10-23 16:20:12 +08:00
committed by GitHub
2 changed files with 24 additions and 3 deletions
+4 -3
View File
@@ -39,9 +39,10 @@ def compare_float(v1, v2, delta=0.001):
@pytest.fixture(autouse=True, scope='class')
def class_setup_and_teardown():
process.remove_persistence()
p = process.start_neuron()
yield
process.stop_neuron(p)
p = process.NeuronProcess()
p.start()
yield p
p.stop()
@pytest.fixture(autouse=True, scope='function')
+20
View File
@@ -9,6 +9,21 @@ def remove_persistence(dir='build/'):
os.system("mkdir -p " + dir + "/persistence")
class NeuronProcess:
def __init__(self, dir='build/'):
self.dir = dir
def start(self):
self.p = start_neuron(self.dir)
def restart(self):
self.p = restart_neuron(self.p, self.dir)
def stop(self):
stop_neuron(self.p)
self.p = None
def start_neuron(dir='build/'):
process = subprocess.Popen(
['./neuron'], stderr=subprocess.PIPE, cwd=dir)
@@ -17,6 +32,11 @@ def start_neuron(dir='build/'):
return process
def restart_neuron(process, dir='build/'):
stop_neuron(process)
return start_neuron(dir)
def stop_neuron(process):
result = process.terminate()
stderr = process.stderr.read().decode()