Ejemplo n.º 1
0
    def run(self):
        """
        Ask for the sum of two random numbers and check the result
        """
        computation_times = []
        response_times = []
        a = int(random() * self.MAXRAND)
        b = int(random() * self.MAXRAND)
        code = json.dumps("print %d+%d" % (a, b))
        s = Session(self.BASE_URL)
        request = s.prepare_execution_request(code)
        sequence = 0

        with timing(computation_times):
            with timing(response_times):
                s.send_execution_request(request)
            start_time = time()
            done = False
            while not done:
                if time() - start_time > self.TIMEOUT:
                    raise Exception("TIMEOUT")
                sleep(self.POLL_INTERVAL)
                with timing(response_times):
                    r = s.output_poll(sequence)
                if len(r) == 0 or "content" not in r:
                    continue
                for m in r["content"]:
                    sequence += 1
                    if m["msg_type"] == "stream" and m["content"]["name"] == "stdout":
                        ans = int(m["content"]["data"])
                        if ans != a + b:
                            print "COMPUTATION NOT CORRECT"
                            raise ValueError(
                                "Computation not correct: %s+%s!=%s, off by %s " % (a, b, ans, ans - a - b)
                            )
                        else:
                            done = True
                            break

        self.custom_timers["Computation"] = computation_times
        self.custom_timers["Response"] = response_times
Ejemplo n.º 2
0
    def run(self):
        """
        Upload a file, change it, and then download it again
        """
        computation_times = []
        response_times = []

        s = Session(self.BASE_URL)
        request = s.prepare_execution_request(code, files=['test.txt'])
        sequence = 0
        with timing(computation_times):
            with timing(response_times):
                s.send_execution_request(request)

            done = False
            while not done:
                sleep(self.POLL_INTERVAL)
                with timing(response_times):
                    r = s.output_poll(sequence)
                if len(r) == 0 or 'content' not in r:
                    continue
                for m in r['content']:
                    sequence += 1
                    if (m['msg_type'] == "extension"
                            and m['content']['msg_type'] == "files"):
                        returned_file = m['content']['content']['files'][0]
                        if returned_file != 'test.txt':
                            print("RETURNED FILENAME NOT CORRECT")
                            raise ValueError(
                                "Returned filename not correct: %s" %
                                returned_file)
                        with timing(response_times):
                            f = s.get_file(returned_file)
                        if f != FILE_RESULT_CONTENTS:
                            print("RETURNED FILE CONTENTS NOT CORRECT")
                            raise ValueError(
                                "Returned file contents not correct: %s" % f)
                        # if we've made it this far, we're done
                        done = True
                        break

        self.custom_timers['Computation'] = computation_times
        self.custom_timers['Response'] = response_times
Ejemplo n.º 3
0
    def run(self):
        """
        Ask for the sum of two random numbers and check the result
        """
        computation_times = []
        response_times = []
        a = int(random() * self.MAXRAND)
        b = int(random() * self.MAXRAND)
        code = json.dumps('print(%d+%d)' % (a, b))
        s = Session(self.BASE_URL)
        request = s.prepare_execution_request(code)
        sequence = 0

        with timing(computation_times):
            with timing(response_times):
                s.send_execution_request(request)
            start_time = time()
            done = False
            while not done:
                if time() - start_time > self.TIMEOUT:
                    raise Exception("TIMEOUT")
                sleep(self.POLL_INTERVAL)
                with timing(response_times):
                    r = s.output_poll(sequence)
                if len(r) == 0 or 'content' not in r:
                    continue
                for m in r['content']:
                    sequence += 1
                    if (m['msg_type'] == "stream"
                            and m['content']['name'] == "stdout"):
                        ans = int(m['content']['data'])
                        if ans != a + b:
                            print("COMPUTATION NOT CORRECT")
                            raise ValueError(
                                "Computation not correct: %s+%s!=%s, off by %s "
                                % (a, b, ans, ans - a - b))
                        else:
                            done = True
                            break

        self.custom_timers['Computation'] = computation_times
        self.custom_timers['Response'] = response_times
    def run(self):
        """
        Upload a file, change it, and then download it again
        """
        computation_times=[]
        response_times=[]

        s=Session(self.BASE_URL)
        request=s.prepare_execution_request(code,files=['test.txt'])
        sequence=0
        with timing(computation_times):
            with timing(response_times):
                s.send_execution_request(request)

            done=False
            while not done:
                sleep(self.POLL_INTERVAL)
                with timing(response_times):
                    r=s.output_poll(sequence)
                if len(r)==0 or 'content' not in r:
                    continue
                for m in r['content']:
                    sequence+=1
                    if (m['msg_type']=="extension"
                        and m['content']['msg_type']=="files"):
                        returned_file=m['content']['content']['files'][0]
                        if returned_file!='test.txt':
                            print "RETURNED FILENAME NOT CORRECT"
                            raise ValueError("Returned filename not correct: %s"%returned_file)
                        with timing(response_times):
                            f=s.get_file(returned_file)
                        if f!=FILE_RESULT_CONTENTS:
                            print "RETURNED FILE CONTENTS NOT CORRECT"
                            raise ValueError("Returned file contents not correct: %s"%f)
                        # if we've made it this far, we're done
                        done=True
                        break

        self.custom_timers['Computation']=computation_times
        self.custom_timers['Response']=response_times