pull/639/head
Piero Toffanin 2019-04-02 15:09:11 -04:00
rodzic 133c382a77
commit fad0070b61
3 zmienionych plików z 49 dodań i 5 usunięć

Wyświetl plik

@ -112,7 +112,6 @@ class GrassContext:
}
def cleanup(self):
return
if os.path.exists(self.get_cwd()):
shutil.rmtree(self.get_cwd())

Wyświetl plik

@ -95,7 +95,7 @@ class TestPlugins(BootTestCase):
grass_scripts_dir = os.path.join(cwd, "grass_scripts")
ctx = grass.create_context()
ctx.add_file('test.geojson', """{
points = """{
"type": "FeatureCollection",
"features": [
{
@ -110,7 +110,8 @@ class TestPlugins(BootTestCase):
}
}
]
}""")
}"""
ctx.add_file('test.geojson', points)
ctx.set_location("EPSG:4326")
result = execute_grass_script.delay(
@ -121,6 +122,9 @@ class TestPlugins(BootTestCase):
self.assertTrue(result.get('context') == ctx.serialize())
# Context dir has been cleaned up automatically
self.assertFalse(os.path.exists(ctx.get_cwd()))
error = execute_grass_script.delay(
os.path.join(grass_scripts_dir, "nonexistant_script.grass"),
ctx.serialize()
@ -131,7 +135,23 @@ class TestPlugins(BootTestCase):
with self.assertRaises(GrassEngineException):
ctx.execute(os.path.join(grass_scripts_dir, "nonexistant_script.grass"))
# TODO: verify autocleanup works
ctx = grass.create_context({"auto_cleanup": False})
ctx.add_file('test.geojson', points)
ctx.set_location("EPSG:4326")
result = execute_grass_script.delay(
os.path.join(grass_scripts_dir, "simple_test.grass"),
ctx.serialize()
).get()
self.assertTrue("Number of points: 1" in result.get('output'))
# Path still there
self.assertTrue(os.path.exists(ctx.get_cwd()))
ctx.cleanup()
# Cleanup worked
self.assertFalse(os.path.exists(ctx.get_cwd()))
def test_plugin_datastore(self):
test_plugin = get_plugin_by_name("test")

Wyświetl plik

@ -1,8 +1,12 @@
import os
from stat import ST_ATIME, ST_MTIME
import worker
from app import pending_actions
from app.models import Project
from app.models import Task
from nodeodm.models import ProcessingNode
from webodm import settings
from .classes import BootTestCase
from .utils import start_processing_node
from worker.tasks import redis_client
@ -56,5 +60,26 @@ class TestWorker(BootTestCase):
pnserver.terminate()
# TODO: check tmp directory cleanup
tmpdir = os.path.join(settings.MEDIA_TMP, 'test')
os.mkdir(tmpdir)
# Dir is new and should not be removed
worker.tasks.cleanup_tmp_directory()
self.assertTrue(os.path.exists(tmpdir))
st = os.stat(tmpdir)
atime = st[ST_ATIME] # access time
mtime = st[ST_MTIME] # modification time
new_mtime = mtime - (23 * 3600) # new modification time
os.utime(tmpdir, (atime, new_mtime))
# 23 hours in it should still be there
worker.tasks.cleanup_tmp_directory()
self.assertTrue(os.path.exists(tmpdir))
new_mtime = mtime - (24 * 3600 + 100) # new modification time
os.utime(tmpdir, (atime, new_mtime))
# After 24 hours it should get removed
worker.tasks.cleanup_tmp_directory()
self.assertFalse(os.path.exists(tmpdir))