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
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), {
'images': [image1, image2],
'name': 'test_task_no_orthophoto',

Wyświetl plik

@ -16,11 +16,11 @@ from webodm import settings
logger = logging.getLogger('app.logger')
@contextmanager
def start_processing_node(*args):
def start_processing_node(args = []):
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"))
time.sleep(2) # Wait for the server to launch
time.sleep(3) # Wait for the server to launch
yield node_odm
node_odm.terminate()
time.sleep(1) # Wait for the server to stop

Wyświetl plik

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

Wyświetl plik

@ -4,13 +4,14 @@ from datetime import timedelta, datetime
import requests
from django.test import TestCase
from django.utils import six
import subprocess, time
import time
from django.utils import timezone
from os import path
from pyodm import Node
from pyodm.exceptions import NodeConnectionError, NodeServerError, NodeResponseError
from webodm import settings
from app.tests.utils import start_processing_node
from .models import ProcessingNode
from . import status_codes
@ -23,14 +24,11 @@ class TestClientApi(TestCase):
@classmethod
def setUpClass(cls):
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
def tearDownClass(cls):
super(TestClientApi, cls).tearDownClass()
cls.node_odm.terminate()
def setUp(self):
self.api_client = Node("localhost", 11223)
@ -44,16 +42,19 @@ class TestClientApi(TestCase):
self.assertRaises(NodeConnectionError, api.options)
def test_info(self):
with start_processing_node():
info = self.api_client.info()
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(info.max_images is None, "Found task max images")
def test_options(self):
with start_processing_node():
options = self.api_client.options()
self.assertTrue(len(options) > 0, "Found options")
def test_online_processing_node(self):
with start_processing_node():
online_node = ProcessingNode.objects.get(pk=1)
self.assertTrue(str(online_node) == "localhost:11223", "Formatting string works")
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")
def test_auto_update_node_info(self):
with start_processing_node():
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)")
@ -96,6 +98,7 @@ class TestClientApi(TestCase):
self.assertTrue(False, error_description)
return False
with start_processing_node():
api = Node("localhost", 11223)
online_node = ProcessingNode.objects.get(pk=1)
@ -167,6 +170,7 @@ class TestClientApi(TestCase):
self.assertEqual(sslApi.url('/info'), 'https://localhost/info?token=abc')
def test_find_best_available_node_and_is_online(self):
with start_processing_node():
# Fixtures are all offline
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)
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"):
retries = 0
while True:
@ -219,7 +218,8 @@ class TestClientApi(TestCase):
self.assertTrue(False, error_description)
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)
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")
online_node.token = "test_token"
self.assertTrue(online_node.remove_task(uuid))
node_odm.terminate()