示例#1
0
 def test_shutdown(self):
     self.m.configure(self.config)
     sess = MockXQueueServer()
     sess._json = {'return_code': 0, 'msg': 'logged in'}
     for c in self.m.clients:
         c.session = sess
     self.m.start()
     self.assertRaises(SystemExit, self.m.shutdown)
示例#2
0
 def test_shutdown(self):
     self.m.configure(self.config)
     sess = MockXQueueServer()
     sess._json = {'return_code': 0, 'msg': 'logged in'}
     for c in self.m.clients:
         c.session = sess
     self.m.start()
     self.assertRaises(SystemExit, self.m.shutdown)
示例#3
0
    def test_start(self):
        self.m.configure(self.config)
        sess = MockXQueueServer()
        sess._json = {'return_code': 0, 'msg': 'logged in'}
        for c in self.m.clients:
            c.session = sess

        self.m.start()
        for c in self.m.clients:
            self.assertTrue(c.is_alive())
示例#4
0
    def test_start(self):
        self.m.configure(self.config)
        sess = MockXQueueServer()
        sess._json = {'return_code': 0, 'msg': 'logged in'}
        for c in self.m.clients:
            c.session = sess

        self.m.start()
        for c in self.m.clients:
            self.assertTrue(c.is_alive())
示例#5
0
    def test_wait(self):
        # no-op
        self.m.wait()

        self.m.configure(self.config)

        def slow_reply(url, response, session):
            if url.endswith('get_submission/'):
                response.json.return_value = {
                    u'return_code':
                    0,
                    u'success':
                    1,
                    u'content':
                    json.dumps({
                        u'xqueue_header': {
                            u'hello': 1
                        },
                        u'xqueue_body': {
                            u'blah': json.dumps({}),
                        }
                    })
                }
            if url.endswith('put_result/'):
                time.sleep(2)

        import threading

        def stopper(client):
            time.sleep(.4)
            client.running = False

        for c in self.m.clients:
            c.session = MockXQueueServer()
            c._json = {'return_code': 0, 'msg': 'logged in'}
            c.session._url_checker = slow_reply
            c.session._json = {'return_code': 0}

        self.m.poll_time = 1
        self.m.start()
        threading.Thread(target=stopper, args=(self.m.clients[0], )).start()

        self.assertRaises(SystemExit, self.m.wait)
示例#6
0
    def test_codejail_config(self):
        config = {
            "name": "python",
            "python_bin": "/usr/bin/python",
            "user": "******",
            "limits": {
                "CPU": 2,
                "VMEM": 1024
            }
        }
        self.m.enable_codejail(config)
        self.assertTrue(codejail.jail_code.is_configured("python"))
        self.m.enable_codejail({
            "name": "other-python",
            "python_bin": "/usr/local/bin/python"
        })
        self.assertTrue(codejail.jail_code.is_configured("other-python"))

        # now we'll see if the codejail config is inherited in the handler subprocess
        handler_config = self.config['test1'].copy()
        client = self.m.client_from_config("test", handler_config)
        client.session = MockXQueueServer()
        client._handle_submission(
            json.dumps({
                "xqueue_header":
                "",
                "xqueue_files": [],
                "xqueue_body":
                json.dumps({
                    'student_response':
                    'blah',
                    'grader_payload':
                    json.dumps({'grader': '/tmp/grader.py'})
                })
            }))
        last_req = client.session._requests[-1]
        self.assertIn('codejail configured',
                      last_req.kwargs['data']['xqueue_body'])