diff options
author | Prabhu Ramachandran | 2017-08-20 01:06:08 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2017-08-20 01:06:08 +0530 |
commit | 46d9ccf47dd3cdc54732fdd833f0ee5b30fcd00f (patch) | |
tree | eecedfd0201433a436bbe43e4d38cdba89c8aa5e /yaksh/tests/test_code_server.py | |
parent | d108cd03e446dcac2b4eeeaec1ea17c47b205c78 (diff) | |
download | online_test-46d9ccf47dd3cdc54732fdd833f0ee5b30fcd00f.tar.gz online_test-46d9ccf47dd3cdc54732fdd833f0ee5b30fcd00f.tar.bz2 online_test-46d9ccf47dd3cdc54732fdd833f0ee5b30fcd00f.zip |
Safely handle code checking process being killed.
While waiting for a result, if the process is not alive, it returns an
error status and restarts another process to continue working.
Diffstat (limited to 'yaksh/tests/test_code_server.py')
-rw-r--r-- | yaksh/tests/test_code_server.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/yaksh/tests/test_code_server.py b/yaksh/tests/test_code_server.py index a73c12f..5f80f2d 100644 --- a/yaksh/tests/test_code_server.py +++ b/yaksh/tests/test_code_server.py @@ -157,6 +157,40 @@ class TestCodeServer(unittest.TestCase): expect = '5 processes, 0 running, 0 queued' self.assertTrue(expect in data) + def test_killing_process_revives_it(self): + # Given + testdata = { + 'metadata': { + 'user_answer': 'import sys; sys.exit()', + 'language': 'python', + 'partial_grading': False + }, + 'test_case_data': [{'test_case': '', + 'test_case_type': 'standardtestcase', + 'weight': 0.0}] + } + + # When + submit(self.url, '0', json.dumps(testdata), '') + result = get_result(self.url, '0', block=True) + + # Then + data = json.loads(result.get('result')) + self.assertFalse(data['success']) + self.assertTrue('Process ended with exit code' in data['error'][0]) + + # Now check the server status to see if the right number + # processes are running. + url = "http://localhost:%s/" % SERVER_POOL_PORT + + # When + response = urllib.request.urlopen(url) + data = response.read().decode('utf-8') + + # Then + expect = '5 processes, 0 running, 0 queued' + self.assertTrue(expect in data) + if __name__ == '__main__': unittest.main() |