зеркало из https://github.com/github/vitess-gh.git
Removing a circular dependency.
This commit is contained in:
Родитель
7548f34c38
Коммит
4a898ff515
|
@ -4,7 +4,7 @@ import framework
|
|||
import cache_cases1
|
||||
import cache_cases2
|
||||
|
||||
import test_env
|
||||
import cases_framework
|
||||
|
||||
class TestWillNotBeCached(framework.TestCase):
|
||||
|
||||
|
@ -99,7 +99,7 @@ class TestCache(framework.TestCase):
|
|||
|
||||
def test_overrides(self):
|
||||
tstart = self.env.table_stats()["vtocc_view"]
|
||||
with test_env.Querylog(self.env) as querylog:
|
||||
with cases_framework.Querylog(self.env) as querylog:
|
||||
cu = self.env.execute("select * from vtocc_view where key2 = 1")
|
||||
self.assertEqual(cu.fetchone(), (1L, 10L, 1L, 3L))
|
||||
tend = self.env.table_stats()["vtocc_view"]
|
||||
|
@ -117,14 +117,14 @@ class TestCache(framework.TestCase):
|
|||
|
||||
tstart = self.env.table_stats()["vtocc_view"]
|
||||
self.env.conn.begin()
|
||||
with test_env.Querylog(self.env) as querylog:
|
||||
with cases_framework.Querylog(self.env) as querylog:
|
||||
self.env.execute("update vtocc_part1 set data1 = 2 where key2 = 1")
|
||||
log = querylog.tailer.read()
|
||||
self.env.conn.commit()
|
||||
self.assertContains(log, "update vtocc_part1 set data1 = 2 where key2 = 1 /* _stream vtocc_part1 (key2 ) (1 ); */")
|
||||
|
||||
|
||||
with test_env.Querylog(self.env) as querylog:
|
||||
with cases_framework.Querylog(self.env) as querylog:
|
||||
cu = self.env.execute("select * from vtocc_view where key2 = 1")
|
||||
self.assertEqual(cu.fetchone(), (1L, 10L, 2L, 3L))
|
||||
tend = self.env.table_stats()["vtocc_view"]
|
||||
|
@ -144,7 +144,7 @@ class TestCache(framework.TestCase):
|
|||
self.env.conn.commit()
|
||||
|
||||
|
||||
with test_env.Querylog(self.env) as querylog:
|
||||
with cases_framework.Querylog(self.env) as querylog:
|
||||
cu = self.env.execute("select * from vtocc_view where key2 = 1")
|
||||
self.assertEqual(cu.fetchone(), (1L, 10L, 2L, 2L))
|
||||
tend = self.env.table_stats()["vtocc_view"]
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
import ast
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import urllib2
|
||||
import uuid
|
||||
|
||||
import environment
|
||||
import framework
|
||||
import utils
|
||||
|
||||
import test_env
|
||||
|
||||
def cases_iterator(cases):
|
||||
for case in cases:
|
||||
|
@ -13,6 +19,7 @@ def cases_iterator(cases):
|
|||
else:
|
||||
yield case
|
||||
|
||||
|
||||
class Log(object):
|
||||
def __init__(self, line):
|
||||
self.line = line
|
||||
|
@ -103,6 +110,33 @@ class Log(object):
|
|||
return self.fail("wrong number of queries", len(case.rewritten), int(self.number_of_queries))
|
||||
|
||||
|
||||
class Querylog(object):
|
||||
|
||||
def __init__(self, env):
|
||||
self.env = env
|
||||
self.id = str(uuid.uuid4())
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
return os.path.join(environment.vtlogroot, 'querylog' + self.id)
|
||||
|
||||
@property
|
||||
def path_full(self):
|
||||
return os.path.join(environment.vtlogroot, 'querylog_full' + self.id)
|
||||
|
||||
def __enter__(self):
|
||||
self.curl = utils.curl(self.env.url('/debug/querylog'), background=True, stdout=open(self.path, 'w'))
|
||||
self.curl_full = utils.curl(self.env.url('/debug/querylog?full=true'), background=True, stdout=open(self.path_full, 'w'))
|
||||
time.sleep(0.3)
|
||||
self.tailer = framework.Tailer(open(self.path), sleep=0.1)
|
||||
return self
|
||||
|
||||
def __exit__(self, *args, **kwargs):
|
||||
self.curl.terminate()
|
||||
self.curl_full.terminate()
|
||||
return
|
||||
|
||||
|
||||
class Case(object):
|
||||
|
||||
def __init__(self, sql, bindings=None, result=None, rewritten=None, doc='',
|
||||
|
@ -149,7 +183,7 @@ class Case(object):
|
|||
|
||||
def run(self, cursor, env):
|
||||
failures = []
|
||||
with test_env.Querylog(env) as querylog:
|
||||
with Querylog(env) as querylog:
|
||||
if self.is_testing_cache:
|
||||
tstart = self.table_stats(env)
|
||||
if self.sql in ('begin', 'commit', 'rollback'):
|
||||
|
|
|
@ -12,7 +12,6 @@ import shutil
|
|||
import subprocess
|
||||
import time
|
||||
import urllib2
|
||||
import uuid
|
||||
|
||||
from vtdb import tablet as tablet_conn
|
||||
from vtdb import cursor
|
||||
|
@ -28,32 +27,6 @@ import utils
|
|||
class EnvironmentError(Exception):
|
||||
pass
|
||||
|
||||
class Querylog(object):
|
||||
|
||||
def __init__(self, env):
|
||||
self.env = env
|
||||
self.id = str(uuid.uuid4())
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
return os.path.join(environment.vtlogroot, 'querylog' + self.id)
|
||||
|
||||
@property
|
||||
def path_full(self):
|
||||
return os.path.join(environment.vtlogroot, 'querylog_full' + self.id)
|
||||
|
||||
def __enter__(self):
|
||||
self.curl = utils.curl(self.env.url('/debug/querylog'), background=True, stdout=open(self.path, 'w'))
|
||||
self.curl_full = utils.curl(self.env.url('/debug/querylog?full=true'), background=True, stdout=open(self.path_full, 'w'))
|
||||
time.sleep(0.3)
|
||||
self.tailer = framework.Tailer(open(self.path), sleep=0.1)
|
||||
return self
|
||||
|
||||
def __exit__(self, *args, **kwargs):
|
||||
self.curl.terminate()
|
||||
self.curl_full.terminate()
|
||||
return
|
||||
|
||||
|
||||
class TestEnv(object):
|
||||
memcache = False
|
||||
|
@ -163,7 +136,7 @@ class TestEnv(object):
|
|||
curs = cursor.TabletCursor(self.conn)
|
||||
error_count = 0
|
||||
|
||||
with Querylog(self) as querylog:
|
||||
with cases_framework.Querylog(self) as querylog:
|
||||
for case in cases:
|
||||
if isinstance(case, basestring):
|
||||
curs.execute(case)
|
||||
|
|
Загрузка…
Ссылка в новой задаче