mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-29 02:08:10 +00:00
Test the stop method
This commit is contained in:
parent
6bb2b88f1a
commit
3abcac43ab
@ -208,7 +208,7 @@ class VPCSDevice(BaseVM):
|
||||
else:
|
||||
self._process.terminate()
|
||||
|
||||
self._process.wait()
|
||||
yield from self._process.wait()
|
||||
|
||||
self._process = None
|
||||
self._started = False
|
||||
|
@ -153,7 +153,7 @@ class Server:
|
||||
self._loop.run_until_complete(self._run_application(app))
|
||||
self._signal_handling()
|
||||
|
||||
#FIXME: remove it in production
|
||||
#FIXME: remove it in production or in tests
|
||||
self._loop.call_later(1, self._reload_hook)
|
||||
try:
|
||||
self._loop.run_forever()
|
||||
|
@ -22,7 +22,7 @@ from tests.utils import asyncio_patch
|
||||
#Move loop to util
|
||||
from tests.api.base import loop
|
||||
from asyncio.subprocess import Process
|
||||
from unittest.mock import patch, Mock
|
||||
from unittest.mock import patch, MagicMock
|
||||
from gns3server.modules.vpcs.vpcs_device import VPCSDevice
|
||||
from gns3server.modules.vpcs.vpcs_error import VPCSError
|
||||
|
||||
@ -46,8 +46,18 @@ def test_vm_invalid_vpcs_path(tmpdir):
|
||||
assert vm.id == 42
|
||||
|
||||
def test_start(tmpdir, loop):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=Mock()):
|
||||
vm = VPCSDevice("test", 42, working_dir=str(tmpdir), path="/bin/test_fake")
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
vm = VPCSDevice("test", 42, working_dir=str(tmpdir), path="/bin/test")
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
assert vm.is_running() == True
|
||||
|
||||
def test_stop(tmpdir, loop):
|
||||
process = MagicMock()
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||
vm = VPCSDevice("test", 42, working_dir=str(tmpdir), path="/bin/test")
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
assert vm.is_running() == True
|
||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
||||
assert vm.is_running() == False
|
||||
process.terminate.assert_called_with()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user