More resilient tests

pull/1086/head
Piero Toffanin 2021-11-05 15:54:19 -04:00
rodzic 53943c3f69
commit 69f80b320e
4 zmienionych plików z 172 dodań i 174 usunięć

Wyświetl plik

@ -870,7 +870,7 @@ class TestApiTask(BootTransactionTestCase):
# Restart node-odm as to not generate orthophotos # Restart node-odm as to not generate orthophotos
testWatch.clear() testWatch.clear()
with start_processing_node("--test_skip_orthophotos"): with start_processing_node(["--test_skip_orthophotos"]):
res = client.post("/api/projects/{}/tasks/".format(project.id), { res = client.post("/api/projects/{}/tasks/".format(project.id), {
'images': [image1, image2], 'images': [image1, image2],
'name': 'test_task_no_orthophoto', 'name': 'test_task_no_orthophoto',

Wyświetl plik

@ -16,11 +16,11 @@ from webodm import settings
logger = logging.getLogger('app.logger') logger = logging.getLogger('app.logger')
@contextmanager @contextmanager
def start_processing_node(*args): def start_processing_node(args = []):
current_dir = os.path.dirname(os.path.realpath(__file__)) current_dir = os.path.dirname(os.path.realpath(__file__))
node_odm = subprocess.Popen(['node', 'index.js', '--port', '11223', '--test'] + list(args), shell=False, node_odm = subprocess.Popen(['node', 'index.js', '--port', '11223', '--test'] + args, shell=False,
cwd=os.path.join(current_dir, "..", "..", "nodeodm", "external", "NodeODM")) cwd=os.path.join(current_dir, "..", "..", "nodeodm", "external", "NodeODM"))
time.sleep(2) # Wait for the server to launch time.sleep(3) # Wait for the server to launch
yield node_odm yield node_odm
node_odm.terminate() node_odm.terminate()
time.sleep(1) # Wait for the server to stop time.sleep(1) # Wait for the server to stop

Wyświetl plik

@ -29,7 +29,7 @@
"available_options": {}, "available_options": {},
"hostname": "localhost", "hostname": "localhost",
"last_refreshed": null, "last_refreshed": null,
"port": 11224, "port": 11223,
"queue_count": 0, "queue_count": 0,
"token": "test_token" "token": "test_token"
}, },

Wyświetl plik

@ -4,13 +4,14 @@ from datetime import timedelta, datetime
import requests import requests
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
import subprocess, time import time
from django.utils import timezone from django.utils import timezone
from os import path from os import path
from pyodm import Node from pyodm import Node
from pyodm.exceptions import NodeConnectionError, NodeServerError, NodeResponseError from pyodm.exceptions import NodeConnectionError, NodeServerError, NodeResponseError
from webodm import settings from webodm import settings
from app.tests.utils import start_processing_node
from .models import ProcessingNode from .models import ProcessingNode
from . import status_codes from . import status_codes
@ -23,14 +24,11 @@ class TestClientApi(TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestClientApi, cls).setUpClass() super(TestClientApi, cls).setUpClass()
cls.node_odm = subprocess.Popen(['node', 'index.js', '--port', '11223', '--test'], shell=False, cwd=path.join(current_dir, "external", "NodeODM"))
time.sleep(2) # Wait for the server to launch
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
super(TestClientApi, cls).tearDownClass() super(TestClientApi, cls).tearDownClass()
cls.node_odm.terminate()
def setUp(self): def setUp(self):
self.api_client = Node("localhost", 11223) self.api_client = Node("localhost", 11223)
@ -44,16 +42,19 @@ class TestClientApi(TestCase):
self.assertRaises(NodeConnectionError, api.options) self.assertRaises(NodeConnectionError, api.options)
def test_info(self): def test_info(self):
with start_processing_node():
info = self.api_client.info() info = self.api_client.info()
self.assertTrue(isinstance(info.version, six.string_types), "Found version string") self.assertTrue(isinstance(info.version, six.string_types), "Found version string")
self.assertTrue(isinstance(info.task_queue_count, int), "Found task queue count") self.assertTrue(isinstance(info.task_queue_count, int), "Found task queue count")
self.assertTrue(info.max_images is None, "Found task max images") self.assertTrue(info.max_images is None, "Found task max images")
def test_options(self): def test_options(self):
with start_processing_node():
options = self.api_client.options() options = self.api_client.options()
self.assertTrue(len(options) > 0, "Found options") self.assertTrue(len(options) > 0, "Found options")
def test_online_processing_node(self): def test_online_processing_node(self):
with start_processing_node():
online_node = ProcessingNode.objects.get(pk=1) online_node = ProcessingNode.objects.get(pk=1)
self.assertTrue(str(online_node) == "localhost:11223", "Formatting string works") self.assertTrue(str(online_node) == "localhost:11223", "Formatting string works")
self.assertTrue(online_node.last_refreshed == None, "Last refreshed not yet set") self.assertTrue(online_node.last_refreshed == None, "Last refreshed not yet set")
@ -76,6 +77,7 @@ class TestClientApi(TestCase):
self.assertTrue(offline_node.api_version == "", "API version is not set") self.assertTrue(offline_node.api_version == "", "API version is not set")
def test_auto_update_node_info(self): def test_auto_update_node_info(self):
with start_processing_node():
online_node = ProcessingNode.objects.create(hostname="localhost", port=11223) online_node = ProcessingNode.objects.create(hostname="localhost", port=11223)
self.assertTrue(online_node.last_refreshed != None, "Last refreshed info is here (update_node_info() was called)") self.assertTrue(online_node.last_refreshed != None, "Last refreshed info is here (update_node_info() was called)")
@ -96,6 +98,7 @@ class TestClientApi(TestCase):
self.assertTrue(False, error_description) self.assertTrue(False, error_description)
return False return False
with start_processing_node():
api = Node("localhost", 11223) api = Node("localhost", 11223)
online_node = ProcessingNode.objects.get(pk=1) online_node = ProcessingNode.objects.get(pk=1)
@ -167,6 +170,7 @@ class TestClientApi(TestCase):
self.assertEqual(sslApi.url('/info'), 'https://localhost/info?token=abc') self.assertEqual(sslApi.url('/info'), 'https://localhost/info?token=abc')
def test_find_best_available_node_and_is_online(self): def test_find_best_available_node_and_is_online(self):
with start_processing_node():
# Fixtures are all offline # Fixtures are all offline
self.assertTrue(ProcessingNode.find_best_available_node() is None) self.assertTrue(ProcessingNode.find_best_available_node() is None)
@ -198,11 +202,6 @@ class TestClientApi(TestCase):
self.assertTrue(ProcessingNode.find_best_available_node().id == pnode.id) self.assertTrue(ProcessingNode.find_best_available_node().id == pnode.id)
def test_token_auth(self): def test_token_auth(self):
node_odm = subprocess.Popen(
['node', 'index.js', '--port', '11224', '--token', 'test_token', '--test'], shell=False,
cwd=path.join(current_dir, "external", "NodeODM"))
time.sleep(2)
def wait_for_status(api, uuid, status, num_retries=10, error_description="Failed to wait for status"): def wait_for_status(api, uuid, status, num_retries=10, error_description="Failed to wait for status"):
retries = 0 retries = 0
while True: while True:
@ -219,7 +218,8 @@ class TestClientApi(TestCase):
self.assertTrue(False, error_description) self.assertTrue(False, error_description)
return False return False
api = Node("localhost", 11224, "test_token") with start_processing_node(['--token', 'test_token']):
api = Node("localhost", 11223, "test_token")
online_node = ProcessingNode.objects.get(pk=3) online_node = ProcessingNode.objects.get(pk=3)
self.assertTrue(online_node.update_node_info(), "Could update info") self.assertTrue(online_node.update_node_info(), "Could update info")
@ -294,5 +294,3 @@ class TestClientApi(TestCase):
self.assertRaises(NodeResponseError, online_node.remove_task, "invalid token") self.assertRaises(NodeResponseError, online_node.remove_task, "invalid token")
online_node.token = "test_token" online_node.token = "test_token"
self.assertTrue(online_node.remove_task(uuid)) self.assertTrue(online_node.remove_task(uuid))
node_odm.terminate()