mirror of
https://github.com/emqx/neuron.git
synced 2026-10-24 10:46:39 +08:00
Merge pull request #1601 from eeff/eeff/dev
test: ft api support restart neuron process
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user