Beispiel #1
0
def test_ti(options):

    _reset,titre_test = options.test_ti_reset,''

    curdir,sqldir,resultsdir,expecteddir = utilt.get_paths()
    prtest.title('running test_ti on database "%s"' % (srvob_conf.DB_NAME,))

    dump = utilt.Dumper(srvob_conf.dbBO,options,None)
    if _reset:
        print '\tReset: Clearing market ...'
        titre_test = utilt.exec_script(dump,sqldir,'reset_market.sql')
        print '\t\tDone'

    fn = os.path.join(sqldir,'test_ti.csv')
    if( not os.path.exists(fn)):
        raise ValueError('The data %s is not found' % fn)

    with open(fn,'r') as f:
        spamreader = csv.reader(f)
        values_prov = {}
        _nbtest = 0
        for row in spamreader:
            _nbtest +=1 
            qua_prov,qtt_prov = row[5],row[6]
            if not qua_prov in values_prov.keys():
                values_prov[qua_prov] = 0
            values_prov[qua_prov] = values_prov[qua_prov] + int(qtt_prov)

    #print values_prov

    cur_login = None
    titre_test = None

    inst = utilt.ExecInst(dump)

    
    user = None
    fmtorder = "SELECT * from market.fsubmitorder('%s','%s','%s',%s,'%s',%s)" 
    fmtquote = "SELECT * from market.fsubmitquote('%s','%s','%s',%s,'%s',%s)"

    fmtjsosr  = '''SELECT jso from market.tmsg 
        where json_extract_path_text(jso,'id')::int=%i and typ='response' '''

    fmtjsose  = """SELECT json_extract_path_text(jso,'orde','id')::int id,
        sum(json_extract_path_text(jso,'mvt_from','qtt')::bigint) qtt_prov,
        sum(json_extract_path_text(jso,'mvt_to','qtt')::bigint) qtt_requ
        from market.tmsg 
        where json_extract_path_text(jso,'orig')::int=%i
        and json_extract_path_text(jso,'orde','id')::int=%i
        and typ='exchange' group by json_extract_path_text(jso,'orde','id')::int """
    '''
    the order that produced the exchange has the qualities expected 
    '''
    i= 0
    if _reset:
        print '\tSubmission: sending a series of %i tests where a random set of arguments' % _nbtest
        print '\t\tis used to submit a quote, then an order'
        with open(fn,'r') as f:
            
            spamreader = csv.reader(f)
            
            compte = utilt.Delai()
            for row in spamreader:
                user = row[0]
                params = tuple(row[1:])
                

                cursor = inst.exe( fmtquote % params,user)
                cursor = inst.exe( fmtorder % params,user)
                i +=1
                if i % 100 == 0:
                    prtest.progress(i/float(_nbtest))

        delai = compte.getSecs()

        print '\t\t%i quote & order primitives in %f seconds' % (_nbtest*2,delai)
        print '\tExecution: Waiting for end of execution ...'
        #utilt.wait_for_true(srvob_conf.dbBO,1000,"SELECT market.fstackdone()",prtest=prtest)
        utilt.wait_for_empty_stack(srvob_conf.dbBO,prtest)
        delai = compte.getSecs()
        print '\t\t Done: mean time per primitive %f seconds' % (delai/(_nbtest*2),) 
        
    fmtiter = '''SELECT json_extract_path_text(jso,'id')::int id,json_extract_path_text(jso,'primitive','type') typ 
        from market.tmsg where typ='response' and json_extract_path_text(jso,'primitive','kind')='quote' 
        order by id asc limit 10 offset %i''' 
    i = 0
    _notnull,_ko,_limit,_limitko = 0,0,0,0
    print '\tChecking: identity of quote result and order result for each %i test cases' % _nbtest
    print '\t\tusing the content of market.tmsg'
    while True:   
        cursor = inst.exe( fmtiter % i,user)
       
        vec = []
        for re in cursor:
            vec.append(re)
            
        l = len(vec)

        if l == 0: 
            break

        for idq,_type in vec:
            i += 1
            if _type == 'limit':
                _limit += 1

            # result of the quote for idq
            _cur = inst.exe(fmtjsosr %idq,user)
            res = _cur.fetchone() 
            res_quote =simplejson.loads(res[0])
            expected = res_quote['result']['qtt_give'],res_quote['result']['qtt_reci']

            #result of the order for idq+1
            _cur = inst.exe(fmtjsose %(idq+1,idq+1),user) 
            res = _cur.fetchone()

            if res is None:
                result = 0,0
            else:
                ido_,qtt_prov_,qtt_reci_ = res
                result = qtt_prov_,qtt_reci_
                _notnull +=1
                if _type == 'limit':
                    if float(expected[0])/float(expected[1]) < float(qtt_prov_)/float(qtt_reci_):
                        _limitko +=1

            if result != expected:
                _ko += 1
                print idq,res,res_quote

            if i %100 == 0:
                prtest.progress(i/float(_nbtest))
                '''
                if i == 100:
                    print '\t\t.',
                else:
                    print '.',
                sys.stdout.flush()
                
                if(_ko != 0): _errs = ' - %i errors' %_ko
                else: _errs = ''
                print ('\t\t%i quote & order\t%i quotes returned a result %s' % (i-_ko,_notnull,_errs))
                '''
    _valuesko = check_values(inst,values_prov,user)
    prtest.title('Results checkings')

    print ''
    print '\t\t%i\torders returned a result different from the previous quote' % _ko
    print '\t\t\twith the same arguments\n'

    print '\t\t%i\tlimit orders returned a result where the limit is not observed\n' % _limitko
    print '\t\t%i\tqualities where the quantity is not preserved by the market\n' % _valuesko

    prtest.line()

    if(_ko == 0 and _limitko == 0 and _valuesko == 0):
        prtest.center('\tAll %i tests passed' % i)
    else:
        prtest.center('\tSome of %i tests failed' % (i,))
    prtest.line() 
    
    inst.close()
    return titre_test
Beispiel #2
0
    print 'Num\tStatus\tName'
    print ''
    for file_test in _fts: # itération on test cases
        _nom_test = file_test[:-4]
        _terr +=1
        _num_test +=1
        
        file_result = file_test[:-4]+'.res'
        _fte = os.path.join(resultsdir,file_result)
        _fre = os.path.join(expecteddir,file_result)
        
        with open(_fte,'w') as f:        
            cur = None

            dump = utilt.Dumper(srvob_conf.dbBO,options,None)
            titre_test = utilt.exec_script(dump,sqldir,'reset_market.sql')
            dump = utilt.Dumper(srvob_conf.dbBO,options,f)
            titre_test = utilt.exec_script(dump,sqldir,file_test)

            utilt.wait_for_true(srvob_conf.dbBO,20,"SELECT market.fstackdone()")

            conn = molet.DbData(srvob_conf.dbBO)
            try:
                with molet.DbCursor(conn) as cur:
                    dump.torder(cur)
                    dump.tmsg(cur)

            finally:
                conn.close()

        if(os.path.exists(_fre)):
Beispiel #3
0
def test_ti(options):

    _reset, titre_test = options.test_ti_reset, ''

    curdir, sqldir, resultsdir, expecteddir = utilt.get_paths()
    prtest.title('running test_ti on database "%s"' % (srvob_conf.DB_NAME, ))

    dump = utilt.Dumper(srvob_conf.dbBO, options, None)
    if _reset:
        print '\tReset: Clearing market ...'
        titre_test = utilt.exec_script(dump, sqldir, 'reset_market.sql')
        print '\t\tDone'

    fn = os.path.join(sqldir, 'test_ti.csv')
    if (not os.path.exists(fn)):
        raise ValueError('The data %s is not found' % fn)

    with open(fn, 'r') as f:
        spamreader = csv.reader(f)
        values_prov = {}
        _nbtest = 0
        for row in spamreader:
            _nbtest += 1
            qua_prov, qtt_prov = row[5], row[6]
            if not qua_prov in values_prov.keys():
                values_prov[qua_prov] = 0
            values_prov[qua_prov] = values_prov[qua_prov] + int(qtt_prov)

    #print values_prov

    cur_login = None
    titre_test = None

    inst = utilt.ExecInst(dump)

    user = None
    fmtorder = "SELECT * from market.fsubmitorder('%s','%s','%s',%s,'%s',%s)"
    fmtquote = "SELECT * from market.fsubmitquote('%s','%s','%s',%s,'%s',%s)"

    fmtjsosr = '''SELECT jso from market.tmsg 
        where json_extract_path_text(jso,'id')::int=%i and typ='response' '''

    fmtjsose = """SELECT json_extract_path_text(jso,'orde','id')::int id,
        sum(json_extract_path_text(jso,'mvt_from','qtt')::bigint) qtt_prov,
        sum(json_extract_path_text(jso,'mvt_to','qtt')::bigint) qtt_requ
        from market.tmsg 
        where json_extract_path_text(jso,'orig')::int=%i
        and json_extract_path_text(jso,'orde','id')::int=%i
        and typ='exchange' group by json_extract_path_text(jso,'orde','id')::int """
    '''
    the order that produced the exchange has the qualities expected 
    '''
    i = 0
    if _reset:
        print '\tSubmission: sending a series of %i tests where a random set of arguments' % _nbtest
        print '\t\tis used to submit a quote, then an order'
        with open(fn, 'r') as f:

            spamreader = csv.reader(f)

            compte = utilt.Delai()
            for row in spamreader:
                user = row[0]
                params = tuple(row[1:])

                cursor = inst.exe(fmtquote % params, user)
                cursor = inst.exe(fmtorder % params, user)
                i += 1
                if i % 100 == 0:
                    prtest.progress(i / float(_nbtest))

        delai = compte.getSecs()

        print '\t\t%i quote & order primitives in %f seconds' % (_nbtest * 2,
                                                                 delai)
        print '\tExecution: Waiting for end of execution ...'
        #utilt.wait_for_true(srvob_conf.dbBO,1000,"SELECT market.fstackdone()",prtest=prtest)
        utilt.wait_for_empty_stack(srvob_conf.dbBO, prtest)
        delai = compte.getSecs()
        print '\t\t Done: mean time per primitive %f seconds' % (
            delai / (_nbtest * 2), )

    fmtiter = '''SELECT json_extract_path_text(jso,'id')::int id,json_extract_path_text(jso,'primitive','type') typ 
        from market.tmsg where typ='response' and json_extract_path_text(jso,'primitive','kind')='quote' 
        order by id asc limit 10 offset %i'''
    i = 0
    _notnull, _ko, _limit, _limitko = 0, 0, 0, 0
    print '\tChecking: identity of quote result and order result for each %i test cases' % _nbtest
    print '\t\tusing the content of market.tmsg'
    while True:
        cursor = inst.exe(fmtiter % i, user)

        vec = []
        for re in cursor:
            vec.append(re)

        l = len(vec)

        if l == 0:
            break

        for idq, _type in vec:
            i += 1
            if _type == 'limit':
                _limit += 1

            # result of the quote for idq
            _cur = inst.exe(fmtjsosr % idq, user)
            res = _cur.fetchone()
            res_quote = simplejson.loads(res[0])
            expected = res_quote['result']['qtt_give'], res_quote['result'][
                'qtt_reci']

            #result of the order for idq+1
            _cur = inst.exe(fmtjsose % (idq + 1, idq + 1), user)
            res = _cur.fetchone()

            if res is None:
                result = 0, 0
            else:
                ido_, qtt_prov_, qtt_reci_ = res
                result = qtt_prov_, qtt_reci_
                _notnull += 1
                if _type == 'limit':
                    if float(expected[0]) / float(
                            expected[1]) < float(qtt_prov_) / float(qtt_reci_):
                        _limitko += 1

            if result != expected:
                _ko += 1
                print idq, res, res_quote

            if i % 100 == 0:
                prtest.progress(i / float(_nbtest))
                '''
                if i == 100:
                    print '\t\t.',
                else:
                    print '.',
                sys.stdout.flush()
                
                if(_ko != 0): _errs = ' - %i errors' %_ko
                else: _errs = ''
                print ('\t\t%i quote & order\t%i quotes returned a result %s' % (i-_ko,_notnull,_errs))
                '''
    _valuesko = check_values(inst, values_prov, user)
    prtest.title('Results checkings')

    print ''
    print '\t\t%i\torders returned a result different from the previous quote' % _ko
    print '\t\t\twith the same arguments\n'

    print '\t\t%i\tlimit orders returned a result where the limit is not observed\n' % _limitko
    print '\t\t%i\tqualities where the quantity is not preserved by the market\n' % _valuesko

    prtest.line()

    if (_ko == 0 and _limitko == 0 and _valuesko == 0):
        prtest.center('\tAll %i tests passed' % i)
    else:
        prtest.center('\tSome of %i tests failed' % (i, ))
    prtest.line()

    inst.close()
    return titre_test
Beispiel #4
0
    print 'Num\tStatus\tName'
    print ''
    for file_test in _fts:  # itération on test cases
        _nom_test = file_test[:-4]
        _terr += 1
        _num_test += 1

        file_result = file_test[:-4] + '.res'
        _fte = os.path.join(resultsdir, file_result)
        _fre = os.path.join(expecteddir, file_result)

        with open(_fte, 'w') as f:
            cur = None

            dump = utilt.Dumper(srvob_conf.dbBO, options, None)
            titre_test = utilt.exec_script(dump, sqldir, 'reset_market.sql')
            dump = utilt.Dumper(srvob_conf.dbBO, options, f)
            titre_test = utilt.exec_script(dump, sqldir, file_test)

            utilt.wait_for_true(srvob_conf.dbBO, 20,
                                "SELECT market.fstackdone()")

            conn = molet.DbData(srvob_conf.dbBO)
            try:
                with molet.DbCursor(conn) as cur:
                    dump.torder(cur)
                    dump.tmsg(cur)

            finally:
                conn.close()