예제 #1
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
                }
예제 #2
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 ) )
예제 #3
0
def get_result() :
    global _test
    obj = json.loads( memcached.get( derive_test_results_key(), u"{}" ) )
    if not obj.has_key( "artifacts" ) :
        obj["artifacts"] = []
    if not obj.has_key( "log" ) :
        obj["log"] = ""
    if not obj.has_key( "status" ) :
        obj["status"] = "unknown"
    if not obj.has_key( "name" ) :
        obj["name"] = _test.__doc__
    if not obj.has_key( "test_id" ) :
        from testing_runtime import tests_config
        obj["test_id"] = tests_config.test_to_id( _test )
    return obj
예제 #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)
예제 #5
0
def get_current_test_result( log_offset = 0 ) :
    global _task
    from testing_runtime import tests_config

    curr_id = get_current_test_id()
    if curr_id == 0 :
        return False

    with current_test( curr_id, False ) :
        obj = json.loads( memcached.get( derive_test_results_key(), "{}" ) )

    if not obj.has_key( "artifacts" ) :
        obj["artifacts"] = []
    if not obj.has_key( "log" ) :
        obj["log"] = ""
    if not obj.has_key( "status" ) :
        obj["status"] = "unknown"
    if not obj.has_key( "name" ) :
        obj["name"] = tests_config.all_tests()[curr_id].__doc__
    if not obj.has_key( "test_id" ) :
        from testing_runtime import tests_config
        obj["test_id"] = curr_id

    return obj
예제 #6
0
def get_all_results() :
    return json.loads( memcached.get( derive_task_results_key(), "[]" ) )
예제 #7
0
def get_current_test_id() :
    return int( memcached.get( derive_current_test_key(), "0" ) )
예제 #8
0
def get_task_log() :
    return memcached.get( derive_task_log_key(), "" )