Esempio n. 1
0
    def __exit__(self, etype, value, traceback):
        global _test
        _test = self._old_test

        if self._update_current_test_value :
            from testing_runtime import tests_config
            memcached.set( derive_current_test_key(), self._old_current )
Esempio n. 2
0
def ajax_read( task_id=None, log_len = 0, tests_count = 0, cur_log_offset = 0 ) :
    log_len = int( log_len )
    tests_count = int( tests_count )
    cur_log_offset = int( cur_log_offset )
    with current_task( int(task_id) ) :
        _task = get_task()

        if (_task.status == u"success" or _task.status == u"fail") :
            return { "state" : "final",
                     "text" : _task.log[log_len:],
                     "result" : json.loads( _task.result )[tests_count:],
                     "current" : False
            }

        # prev cur id compare
        cur_test_id = get_current_test_id()
        last_test_res = get_current_test_result()

        if ( last_test_res != False ) :
            prev_id = int( memcached.get( derive_prev_request_test_id_key(), "0" ) )
            state = "same"
            if prev_id <> cur_test_id :
                cur_log_offset = 0
                state = "new"
            last_test_res[ "log" ] = last_test_res[ "log" ][ cur_log_offset: ]
            last_test_res[ "state" ] = state

            memcached.set( derive_prev_request_test_id_key(), cur_test_id )
            # prev cur id compare

        return { "state" : "continue",
                 "text" : get_task_log()[log_len:],
                 "result" : get_all_results()[tests_count:],
                 "current" : last_test_res
                }
Esempio n. 3
0
    def __enter__(self):
        global _test
        self._old_test = _test
        _test = self._test

        if self._update_current_test_value :
            from testing_runtime import tests_config
            self._old_current = memcached.get( derive_current_test_key(), "0" )
            memcached.set( derive_current_test_key(), tests_config.test_to_id( _test ) )
Esempio n. 4
0
def write( s, append=True, to_task_log=False ) :
    s = u"{time} {info}".format(
            time=time.strftime( u"[%H:%M:%S]", time.localtime() ),
            info=s
        )
    test = get_test()
    if (to_task_log) or (test is None) :
        if append == True :
            was = memcached.get( derive_task_log_key(), u"" )
            memcached.set( derive_task_log_key(), was + u"\n" + s )
        else :
            memcached.set( derive_task_log_key(), s )
    else :
        if append == True :
            obj = get_result()
            obj["log"] += u"\n" + s
            set_result(obj)
        else :
            obj = get_result()
            obj["log"] = s
            set_result(obj)
Esempio n. 5
0
def set_result(obj) :
    memcached.set( derive_test_results_key(), json.dumps( obj ) )
Esempio n. 6
0
def save_test_result() :
    global _all
    obj = get_result()
    _all.append( obj )
    memcached.set( derive_task_results_key(), json.dumps( _all ) )
Esempio n. 7
0
def reset() :
    global _all
    _all = []
    memcached.set( derive_prev_request_test_id_key(), "0" )