2021-05-18 20:39:25 +10:00
|
|
|
#!/usr/bin/env python3.9
|
2016-01-21 23:22:42 +00:00
|
|
|
|
|
|
|
|
|
2016-03-09 10:47:09 +00:00
|
|
|
import asyncio
|
2016-01-21 23:22:42 +00:00
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
import tempfile
|
|
|
|
|
import unittest
|
|
|
|
|
|
2018-09-17 23:59:38 +10:00
|
|
|
import eris.tools as tools
|
|
|
|
|
import eris.worker as worker
|
2016-01-21 23:22:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkerTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.temp_dir = tempfile.mkdtemp()
|
|
|
|
|
self.original_working_dir = os.getcwd()
|
|
|
|
|
os.chdir(self.temp_dir)
|
2016-02-24 01:45:31 +00:00
|
|
|
os.mkdir(tools.CACHE_PATH)
|
2016-01-21 23:22:42 +00:00
|
|
|
open("foo", "w").close()
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
|
shutil.rmtree(self.temp_dir)
|
|
|
|
|
os.chdir(self.original_working_dir)
|
|
|
|
|
|
2017-06-23 23:23:32 +01:00
|
|
|
def test_run_job(self):
|
2016-03-09 10:47:09 +00:00
|
|
|
loop = asyncio.get_event_loop()
|
2019-12-04 12:18:00 +10:00
|
|
|
compression = "none"
|
2019-12-21 12:17:13 +10:00
|
|
|
worker_ = worker.Worker(False, compression)
|
2016-03-09 10:47:09 +00:00
|
|
|
loop.run_until_complete(worker_.create_process())
|
2019-12-04 12:18:00 +10:00
|
|
|
worker_.process.stdin.write(f"{compression}\n".encode("utf-8"))
|
2016-03-09 10:47:09 +00:00
|
|
|
future = worker_.run_tool("foo", tools.metadata)
|
|
|
|
|
status = loop.run_until_complete(future)
|
2021-07-20 00:48:18 +10:00
|
|
|
self.assertEqual(status, tools.Status.ok)
|
2016-02-24 01:45:31 +00:00
|
|
|
result_path = os.path.join(tools.CACHE_PATH, "foo-metadata")
|
2016-01-21 23:22:42 +00:00
|
|
|
self.assertTrue(os.path.exists(result_path))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|