Пример #1
0
def test():
    log_debug('register', 'start testing ')
    get_pkgs_details_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        
        if RANDOM_CAT:
            cat_num = randint(0, len(CAT) - 1)
            cat_name = CAT[cat_num]
            if not CATEGORIES.has_key(cat_name):
                log_err('get_packages_details', 'failed to get the category, invalid category is %s' % str(cat_name))
                return False
            cate = CATEGORIES[cat_name]
        else:
            cate = CATEGORY
        
        message = json.dumps({'operator':'get_counter', 'category':cate})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_counter' != result['operator'] or cate != result['category'] or not  result['data']:
            log_err('get_counter', 'failed to get counter')
            return False
        counter = result['data']
        if not counter:
            log_err('get_counter', 'failed to get the total number of %s ' % str(cate))
            return False
        if SHOW_TIME:
            log_debug('get_counter', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        log_debug('get_counter', 'counter=%s' % str(counter))
        rank = randint(0, (int(counter)  + PAGE_SIZE  - 1) / PAGE_SIZE - 1)
        log_debug('get_counter', 'rank=%d' % rank)
        
        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({'operator':'get_packages_details', 'category':cate, 'rank':rank})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_packages_details' != result['operator'] or cate != result['category'] or rank != result['rank'] or not  result['data']:
            log_err('get_packages_details', 'failed to get packages details')
            return False
        ret = result['data']
        for item in ret:
            if not item['pkg'] or not item['title'] or not item['auth']:
                log_err('get_packages_details', 'failed to get valid details')
                return False
        if SHOW_TIME:
            log_debug('get_packages_details', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        get_pkgs_details_cnt += 1
        log_debug('get_packages_details', 'get_pkgs_details_cnt=%d' % get_pkgs_details_cnt)
        log_debug('get_packages_details', 'packages_details=%s' % str(ret))
Пример #2
0
def test():
    log_debug('has_package', 'start testing ')
    login_cnt = 0
    has_pkg_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        username = USER + str(USER_START + i)
        message = json.dumps({
            'op': 'login',
            'user': username,
            'password': PASSWORD
        })
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'login' != result['op'] or username != result[
                'user'] or not result['data']:
            log_err('login', 'failed to login %s.' % str(username))
            return False
        uid = result['data'][0]
        if not uid:
            log_err('has_package->login',
                    'failed to login %s, invalid uid or key.' % str(username))
            return False
        if SHOW_TIME:
            log_debug('has_package->login',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        login_cnt += 1
        log_debug('has_package->login', 'login_cnt=%d' % login_cnt)

        if SHOW_TIME:
            start_time = datetime.utcnow()
        package = PACKAGE + str(PKG_START + i)
        message = json.dumps({
            'op': 'has_package',
            'uid': uid,
            'package': package
        })
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'has_package' != result['op'] or package != result[
                'package'] or not result['data']:
            log_err('has_package', 'failed to install app %s' % str(package))
            return False
        if SHOW_TIME:
            log_debug('has_package',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        has_pkg_cnt += 1
        log_debug('has_package', 'has_pkg_cnt=%d' % has_pkg_cnt)
Пример #3
0
def test():
    log_debug('login', 'start testing ')
    login_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        username = USER + str(USER_START + i)
        message = json.dumps({'operator':'login', 'user':username, 'password':PASSWORD})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'login' != result['operator'] or username != result['user'] or not  result['data']:
            log_err('login', 'failed to login %s.' % str(username))
            return False
        uid = result['data'][0]
        key = result['data'][1]
        if not uid or not key:
            log_err('login', 'failed to login %s, invalid uid or key.' % str(username))
            return False
        if SHOW_TIME:
            log_debug('login', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        login_cnt += 1
        log_debug('login', 'login_cnt=%d' % login_cnt)
Пример #4
0
def test():
    log_debug('register', 'start testing ')
    get_top_details_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        
        if RANDOM_CAT:
            cat_num = randint(0, len(CAT) - 1)
            cat_name = CAT[cat_num]
            if not CATEGORIES.has_key(cat_name):
                log_err('get_top_details', 'failed to get the top details, invalid category is %s' % str(cat_name))
                return False
            cate = CATEGORIES[cat_name]
        else:
            cate = CATEGORY
        
        message = json.dumps({'operator':'get_top_details', 'category':cate})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_top_details' != result['operator'] or cate != result['category']:
            log_err('get_top_details', 'failed to get the top packages details of %s' % str(cate))
            return False
        if SHOW_TIME:
            log_debug('register', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        ret = result['data']
        get_top_details_cnt += 1
        log_debug('get_top_details', 'get_top_details_cnt=%d' % get_top_details_cnt)
        log_debug('get_top_details', 'top details packages=%s' % str(ret))
Пример #5
0
def test():
    log_debug('get_author', 'start testing ')
    auth_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        
        if RANDOM_PKG:
            cat_num = randint(0, len(CAT) - 1)
            cat_name = CAT[cat_num]
            pkg_num = randint(0, PKG_NUM - 1)
            package = cat_name + '_' + PKG + str(pkg_num)
        else:
            package = PACKAGE + str(PKG_START + i)
        
        message = json.dumps({'operator':'get_author', 'package':package})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_author' != result['operator'] or package != result['package'] or not  result['data']:
            log_err('get_author', 'failed to get the author of %s ' % str(package))
            return False
        auth_cnt += 1
        log_debug('get_author', 'auth_cnt=%d' % auth_cnt)
        log_debug('get_author', 'the author of %s is %s' % (str(package), str(result['data'])))
        if SHOW_TIME:
            log_debug('get_author', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
Пример #6
0
def test():
    log_debug('get_author', 'start testing ')
    auth_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        
        if RANDOM_PKG:
            cat_num = randint(0, len(CATEGORIES.keys()) - 1)
            cat_name = CATEGORIES.keys()[cat_num]
            pkg_num = randint(50, PKG_NUM)
            package = cat_name + '_' + PKG + str(pkg_num)
        else:
            package = PACKAGE + str(PKG_START + i)
        
        message = json.dumps({'op':'get_author', 'package':package})
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_author' != result['op'] or package != result['package'] or not  result['data']:
            log_err('get_author', 'failed to get the author of %s ' % str(package))
            return False
        auth_cnt += 1
        log_debug('get_author', 'auth_cnt=%d' % auth_cnt)
        log_debug('get_author', 'the author of %s is %s' % (str(package), str(result['data'])))
        if SHOW_TIME:
            log_debug('get_author', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
Пример #7
0
def test():
    log_debug('get_installed_packages', 'start testing ')
    login_cnt = 0
    get_inst_pkgs_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        username = USER + str(USER_START + i)
        message = json.dumps({'op':'login', 'user':username, 'password':PASSWORD})
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'login' != result['op'] or username != result['user'] or not  result['data']:
            log_err('get_installed_packages->login', 'failed to login %s.' % str(username))
            return False
        uid = result['data'][0]
        if not uid:
            log_err('get_installed_packages->login', 'failed to login %s, invalid uid.' % str(username))
            return False
        if SHOW_TIME:
            log_debug('get_installed_packages->login', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        login_cnt += 1
        log_debug('get_installed_packages->login', 'login_cnt=%d' % login_cnt)
        
        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({'op':'get_installed_packages', 'uid':uid})
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_installed_packages' != result['op'] or uid != result['uid']:
            log_err('get_installed_packages', 'failed to get installed packages')
            return False
        get_inst_pkgs_cnt += 1
        log_debug('get_installed_packages', 'get_inst_pkgs_cnt=%d' % get_inst_pkgs_cnt)
        log_debug('get_installer_packages', 'the packages of %s has installed are %s' % (str(username), str(result['data'])))
        if SHOW_TIME:
            log_debug('get_installed_packages', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
Пример #8
0
def test():
    log_debug('get_counter', 'start testing ')
    get_count = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()

        if RANDOM_CAT:
            cat_num = randint(0, len(CATEGORIES.keys()) - 1)
            cat_name = CATEGORIES.keys()[cat_num]
            if not CATEGORIES.has_key(cat_name):
                log_err(
                    'get_counter',
                    'failed to get the category, invalid category is %s' %
                    str(cat_name))
                return False
            cate = CATEGORIES[cat_name]
        else:
            cate = CATEGORY

        message = json.dumps({'op': 'get_counter', 'category': cate})
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_counter' != result['op'] or cate != result[
                'category'] or not result['data']:
            log_err('get_counter', 'failed to get counter')
            return False
        counter = result['data']
        if not counter:
            log_err('get_counter',
                    'failed to get the total number of %s ' % str(cate))
            return False
        get_count += 1
        log_debug('get_inst', 'get_count=%d' % get_count)
        if SHOW_TIME:
            log_debug('get_counter',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        log_debug('get_counter', 'counter=%s' % str(counter))
        if int(counter) < 1:
            rank = 0
        else:
            rank = randint(0, (int(counter) + PAGE_SIZE - 1) / PAGE_SIZE - 1)
        log_debug('get_counter', 'rank=%d' % rank)
Пример #9
0
def test():
    log_debug('register', 'start testing ')
    register_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        username = USER + str(USER_START + i)
        message = json.dumps({'operator':'register', 'user':username, 'password':PASSWORD, 'email':EMAIL})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'register' != result['operator'] or username != result['user'] or not  result['data']:
            log_err('register', 'failed to register %s.' % str(username))
            return False
        register_cnt += 1
        log_debug('register', 'register_cnt=%d' % register_cnt)
        if SHOW_TIME:
            log_debug('register', 'test, time=%d sec' % (datetime.utcnow() - start_time).seconds)
Пример #10
0
def test():
    log_debug('get_categories', 'start testing ')
    cat_cnt = 0
    for _ in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({'operator':'get_categories'})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_categories' != result['operator'] or not  result['data']:
            log_err('get_categories', 'failed to get categories')
            return False
        cat_cnt += 1
        log_debug('get_categories', 'cat_cnt=%d' % cat_cnt)
        log_debug('get_categories', 'categories=%s' % str(result['data']))
        if SHOW_TIME:
            log_debug('get_categories', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
Пример #11
0
def test():
    log_debug('register', 'start testing ')
    register_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        username = USER + str(USER_START + i)
        message = json.dumps({'op':'register', 'user':username, 'password':PASSWORD, 'email':EMAIL})
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'register' != result['op'] or username != result['user'] or not  result['data']:
            log_err('register', 'failed to register %s.' % str(username))
            return False
        register_cnt += 1
        log_debug('register', 'register_cnt=%d' % register_cnt)
        if SHOW_TIME:
            log_debug('register', 'test, time=%d sec' % (datetime.utcnow() - start_time).seconds)
Пример #12
0
def test():
    log_debug('get_categories', 'start testing ')
    cat_cnt = 0
    for _ in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({'op': 'get_categories'})
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_categories' != result['op'] or not result['data']:
            log_err('get_categories', 'failed to get categories')
            return False
        cat_cnt += 1
        log_debug('get_categories', 'cat_cnt=%d' % cat_cnt)
        log_debug('get_categories', 'categories=%s' % str(result['data']))
        if SHOW_TIME:
            log_debug('get_categories',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)
Пример #13
0
def test():
    log_debug('get_top_details', 'start testing ')
    get_top_details_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()

        if RANDOM_CAT:
            cat_num = randint(0, len(CATEGORIES.keys()) - 1)
            cat_name = CATEGORIES.keys()[cat_num]
            if not CATEGORIES.has_key(cat_name):
                log_err(
                    'get_top_details',
                    'failed to get the top details, invalid category is %s' %
                    str(cat_name))
                return False
            cate = CATEGORIES[cat_name]
        else:
            cate = CATEGORY

        message = json.dumps({'op': 'get_top_details', 'category': cate})
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_top_details' != result['op'] or cate != result[
                'category']:
            log_err('get_top_details',
                    'failed to get the top packages details of %s' % str(cate))
            return False
        if SHOW_TIME:
            log_debug('get_top_details',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        ret = result['data']
        get_top_details_cnt += 1
        log_debug('get_top_details',
                  'get_top_details_cnt=%d' % get_top_details_cnt)
        log_debug('get_top_details', 'top details packages=%s' % str(ret))
Пример #14
0
def test():
    log_debug('upload', 'start testing ')
    login_cnt = 0
    upload_cnt = 0
    get_pkgs_details_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        username = USER + str(USER_START + i)
        uid, key = login(username, PASSWORD)
        if not uid or not key:
            log_err('upload->login', 'failed to login %s.' % str(username))
            return False
        login_cnt += 1
        log_debug('upload->login', 'login_cnt=%d' % login_cnt)
        package = PACKAGE + str(50 + i)
        if not upload(PATH, uid, package, VERSION, APP, key):
            log_err('upload', 'failed to upload app %s' % str(package))
            return False
        if SHOW_TIME:
            log_debug('upload',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        upload_cnt += 1
        log_debug('upload', 'upload_cnt=%d' % upload_cnt)

        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({'op': 'get_counter', 'category': CATEGORY})
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_counter' != result['op'] or CATEGORY != result[
                'category'] or not result['data']:
            log_err('get_counter', 'failed to get counter')
            return False
        counter = result['data']
        if not counter:
            log_err('get_counter',
                    'failed to get the total number of %s ' % str(CATEGORY))
            return False
        if SHOW_TIME:
            log_debug('get_counter',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        log_debug('get_counter', 'counter=%s' % str(counter))
        if int(counter) < 1:
            rank = 0
        else:
            rank = randint(0, (int(counter) + PAGE_SIZE - 1) / PAGE_SIZE - 1)
        log_debug('get_counter', 'rank=%d' % rank)

        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({
            'op': 'get_packages_details',
            'category': CATEGORY,
            'rank': rank
        })
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_packages_details' != result[
                'op'] or CATEGORY != result['category'] or rank != result[
                    'rank'] or not result['data']:
            log_err('get_packages_details', 'failed to get packages details')
            return False
        ret = result['data']
        for item in ret:
            if not item['pkg'] or not item['title'] or not item['auth']:
                log_err('get_packages_details', 'failed to get valid details')
                return False
        if SHOW_TIME:
            log_debug('get_packages_details',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        get_pkgs_details_cnt += 1
        log_debug('get_packages_details',
                  'get_pkgs_details_cnt=%d' % get_pkgs_details_cnt)
        log_debug('get_packages_details', 'packages_details=%s' % str(ret))
Пример #15
0
def test():
    log_debug('install', 'start testing ')
    login_cnt = 0
    install_cnt = 0
    get_top_cnt = 0
    has_pkg_cnt = 0
    download_cnt = 0
    get_top_details_cnt = 0

    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        username = USER + str(USER_START + i)
        message = json.dumps({
            'op': 'login',
            'user': username,
            'password': PASSWORD
        })
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'login' != result['op'] or username != result[
                'user'] or not result['data']:
            log_err('login', 'failed to login %s.' % str(username))
            return False
        uid = result['data'][0]
        key = result['data'][1]
        if not uid or not key:
            log_err('install->login',
                    'failed to login %s, invalid uid or key.' % str(username))
            return False
        if SHOW_TIME:
            log_debug('install->login',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        login_cnt += 1
        log_debug('install->login', 'login_cnt=%d' % login_cnt)

        if SHOW_TIME:
            start_time = datetime.utcnow()
        if RANDOM_PKG:
            cat_num = randint(0, len(CATEGORIES.keys()) - 1)
            cat_name = CATEGORIES.keys()[cat_num]
            pkg_num = randint(50, PKG_NUM)
            package = cat_name + '_' + PKG + str(pkg_num)
        else:
            package = PACKAGE + str(PKG_START + i)
        message = json.dumps({
            'op': 'download',
            'uid': uid,
            'package': package,
            'version': VERSION
        })
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        log_debug('download', 'result=%s' % result)
        if not result or 'download' != result['op'] or uid != result[
                'uid'] or not result['data']:
            log_err('download', 'failed to download app %s' % str(package))
            return False
        ret = result['data']
        if not ret:
            log_err(
                'download',
                'failed to download app %s, invalid return message' %
                str(package))
            return False
        download_cnt += 1
        log_debug('install', 'download_cnt=%d' % download_cnt)
        if SHOW_TIME:
            log_debug('download',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)

        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({
            'op': 'install',
            'uid': uid,
            'package': package,
            'version': VERSION,
            'type': APP,
            'content': ret
        })
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'install' != result['op'] or uid != result[
                'uid'] or not result['data']:
            log_err('install', 'failed to install app %s' % str(package))
            return False
        ret = result['data']
        if not ret:
            log_err(
                'install', 'failed to install app %s, invalid return message' %
                str(package))
            return False
        install_cnt += 1
        log_debug('install', 'install_cnt=%d' % install_cnt)
        if SHOW_TIME:
            log_debug('install',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)

        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({
            'op': 'has_package',
            'uid': uid,
            'package': package
        })
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'has_package' != result['op'] or package != result[
                'package'] or not result['data']:
            log_err('install-->has_package',
                    'failed to has app %s' % str(package))
            return False
        has_pkg_cnt += 1
        log_debug('has_package', 'has_pkg_cnt=%d' % has_pkg_cnt)
        if SHOW_TIME:
            log_debug('has_package',
                      'time=%d sec' % (datetime.utcnow() - start_time).seconds)

        if not CATEGORIES.has_key(cat_name):
            log_err(
                'get_top', 'failed to get the top, invalid category is %s' %
                str(cat_name))
            return False
        cate = CATEGORIES[cat_name]

        message = json.dumps({'op': 'get_top', 'category': cate})
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_top' != result['op'] or cate != result[
                'category']:
            log_err('get_top',
                    'failed to get the top packages of %s' % str(cate))
            return False
        ret = result['data']
        get_top_cnt += 1
        log_debug('get_top', 'get_top_cnt=%d' % get_top_cnt)
        log_debug('get_top', 'top packages=%s' % str(ret))

        message = json.dumps({'op': 'get_top_details', 'category': cate})
        ws = create_connection("ws://%s:%d/ws" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_top_details' != result['op'] or cate != result[
                'category']:
            log_err('get_top_details',
                    'failed to get the top packages details of %s' % str(cate))
            return False
        ret = result['data']
        get_top_details_cnt += 1
        log_debug('get_top_details',
                  'get_top_details_cnt=%d' % get_top_details_cnt)
        log_debug('get_top_details', 'top details packages=%s' % str(ret))
Пример #16
0
def test():
    log_debug('install', 'start testing ')
    login_cnt = 0
    install_cnt = 0
    has_pkg_cnt = 0
    get_top_cnt = 0
    get_top_details_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        username = USER + str(USER_START + i)
        message = json.dumps({'operator':'login', 'user':username, 'password':PASSWORD})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'login' != result['operator'] or username != result['user'] or not  result['data']:
            log_err('login', 'failed to login %s.' % str(username))
            return False
        uid = result['data'][0]
        key = result['data'][1]
        if not uid or not key:
            log_err('install->login', 'failed to login %s, invalid uid or key.' % str(username))
            return False
        if SHOW_TIME:
            log_debug('install->login', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        login_cnt += 1
        log_debug('install->login', 'login_cnt=%d' % login_cnt)
        
        if SHOW_TIME:
            start_time = datetime.utcnow()
        cat_num = randint(0, len(CAT) - 1)
        cat_name = CAT[cat_num]
        if RANDOM_PKG:
            pkg_num = randint(60, PKG_NUM - 1)
            package = cat_name + '_' + PKG + str(pkg_num)
        else:
            package = PACKAGE + str(PKG_START + i)
        message = json.dumps({'operator':'install', 'uid':uid, 'package':package, 'version':VERSION, 'typ':APP})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'install' != result['operator'] or uid != result['uid'] or not  result['data']:
            log_err('install', 'failed to install app %s' % str(package))
            return False
        ret = result['data']
        if not ret:
            log_err('install', 'failed to install app %s, invalid return message' % str(package))
            return False
        install_cnt += 1
        log_debug('install', 'install_cnt=%d' % install_cnt)
        if SHOW_TIME:
            log_debug('install', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        
        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({'operator':'has_package', 'uid':uid,'package':package})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'has_package' != result['operator'] or package != result['package'] or not  result['data']:
            log_err('install-->has_package', 'failed to has app %s' % str(package))
            return False
        has_pkg_cnt += 1
        log_debug('has_package', 'has_pkg_cnt=%d' % has_pkg_cnt)
        if SHOW_TIME:
            log_debug('has_package', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        
        
        if not CATEGORIES.has_key(cat_name):
            log_err('get_top', 'failed to get the top, invalid category is %s' % str(cat_name))
            return False
        cate = CATEGORIES[cat_name]
        
        message = json.dumps({'operator':'get_top', 'category':cate})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_top' != result['operator'] or cate != result['category']:
            log_err('get_top', 'failed to get the top packages of %s' % str(cate))
            return False
        ret = result['data']
        get_top_cnt +=1
        log_debug('get_top', 'get_top_cnt=%d' % get_top_cnt)
        log_debug('get_top', 'top packages=%s' % str(ret))
        
        message = json.dumps({'operator':'get_top_details', 'category':cate})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_top_details' != result['operator'] or cate != result['category']:
            log_err('get_top_details', 'failed to get the top packages details of %s' % str(cate))
            return False
        ret = result['data']
        get_top_details_cnt += 1
        log_debug('get_top_details', 'get_top_details_cnt=%d' % get_top_details_cnt)
        log_debug('get_top_details', 'top details packages=%s' % str(ret))
        
Пример #17
0
def test():
    log_debug('upload', 'start testing ')
    login_cnt = 0
    upload_cnt = 0
    get_pkgs_details_cnt = 0
    for i in range(TEST_ROUNDS):
        if SHOW_TIME:
            start_time = datetime.utcnow()
        username = USER + str(USER_START + i)
        uid, key = login(username, PASSWORD)
        if not uid or not key:
            log_err('upload->login', 'failed to login %s.' % str(username))
            return False
        login_cnt += 1
        log_debug('upload->login', 'login_cnt=%d' % login_cnt)
        package = PACKAGE + str(PKG_START + i)
        if not upload(PATH, uid, package, VERSION, APP, key):
            log_err('upload', 'failed to upload app %s' % str(package))
            return False
        if SHOW_TIME:
            log_debug('upload', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        upload_cnt += 1
        log_debug('upload', 'upload_cnt=%d' % upload_cnt)
        
        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({'operator':'get_counter', 'category':CATEGORY})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_counter' != result['operator'] or CATEGORY != result['category'] or not  result['data']:
            log_err('get_counter', 'failed to get counter')
            return False
        counter = result['data']
        if not counter:
            log_err('get_counter', 'failed to get the total number of %s ' % str(CATEGORY))
            return False
        if SHOW_TIME:
            log_debug('get_counter', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        log_debug('get_counter', 'counter=%s' % str(counter))
        rank = randint(0, (int(counter)  + PAGE_SIZE  - 1) / PAGE_SIZE - 1)
        log_debug('get_counter', 'rank=%d' % rank)
        
        if SHOW_TIME:
            start_time = datetime.utcnow()
        message = json.dumps({'operator':'get_packages_details', 'category':CATEGORY, 'rank':rank})
        ws = create_connection("ws://%s:%d/" % (get_manager(), get_port()))
        ws.send(message)
        ret = ws.recv()
        ws.close()
        result = json.loads(ret)
        if not result or 'get_packages_details' != result['operator'] or CATEGORY != result['category'] or rank != result['rank'] or not  result['data']:
            log_err('get_packages_details', 'failed to get packages details')
            return False
        ret = result['data']
        for item in ret:
            if not item['pkg'] or not item['title'] or not item['auth']:
                log_err('get_packages_details', 'failed to get valid details')
                return False
        if SHOW_TIME:
            log_debug('get_packages_details', 'time=%d sec' % (datetime.utcnow() - start_time).seconds)
        get_pkgs_details_cnt += 1
        log_debug('get_packages_details', 'get_pkgs_details_cnt=%d' % get_pkgs_details_cnt)
        log_debug('get_packages_details', 'packages_details=%s' % str(ret))