comparison rhodecode/tests/test_crawler.py @ 1338:bbfc3f305c6b beta

Updated test_crawler to scan paths in more sensible order using ordered tuple.
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 15 May 2011 18:20:53 +0200
parents 08cd02374883
children 1881b808a71d
comparison
equal deleted inserted replaced
1337:37625d304a16 1338:bbfc3f305c6b
68 68
69 print 'total_time', total_time 69 print 'total_time', total_time
70 print 'average on req', total_time / float(pages) 70 print 'average on req', total_time / float(pages)
71 71
72 72
73 def test_changeset_walk(): 73 def test_changeset_walk(limit=None):
74 print jn(PROJECT_PATH, PROJECT) 74 print 'processing', jn(PROJECT_PATH, PROJECT)
75 total_time = 0 75 total_time = 0
76 76
77 repo = vcs.get_repo(jn(PROJECT_PATH, PROJECT)) 77 repo = vcs.get_repo(jn(PROJECT_PATH, PROJECT))
78 78 cnt = 0
79 for i in repo: 79 for i in repo:
80 80 cnt += 1
81 raw_cs = '/'.join((PROJECT, 'changeset', i.raw_id)) 81 raw_cs = '/'.join((PROJECT, 'changeset', i.raw_id))
82 if limit and limit == cnt:
83 break
82 84
83 full_uri = (BASE_URI % raw_cs) 85 full_uri = (BASE_URI % raw_cs)
84 s = time.time() 86 s = time.time()
85 f = o.open(full_uri) 87 f = o.open(full_uri)
86 size = len(f.read()) 88 size = len(f.read())
87 e = time.time() - s 89 e = time.time() - s
88 total_time += e 90 total_time += e
89 print 'visited %s\%s size:%s req:%s ms' % (full_uri, i, size, e) 91 print 'visited %s\%s size:%s req:%s ms' % (full_uri, i, size, e)
90 92
91 print 'total_time', total_time 93 print 'total_time', total_time
92 print 'average on req', total_time / float(len(repo)) 94 print 'average on req', total_time / float(cnt)
95
93 96
94 def test_files_walk(): 97 def test_files_walk():
95 print jn(PROJECT_PATH, PROJECT) 98 print 'processing', jn(PROJECT_PATH, PROJECT)
96 total_time = 0 99 total_time = 0
97 100
98 repo = vcs.get_repo(jn(PROJECT_PATH, PROJECT)) 101 repo = vcs.get_repo(jn(PROJECT_PATH, PROJECT))
99 102
100 paths_ = set() 103 from rhodecode.lib.oset import OrderedSet
104
105 paths_ = OrderedSet([''])
101 try: 106 try:
102 tip = repo.get_changeset('tip') 107 tip = repo.get_changeset('tip')
103 for topnode, dirs, files in tip.walk('/'): 108 for topnode, dirs, files in tip.walk('/'):
109
110 for dir in dirs:
111 paths_.add(dir.path)
112 for f in dir:
113 paths_.add(f.path)
114
104 for f in files: 115 for f in files:
105 paths_.add(f.path) 116 paths_.add(f.path)
106 for dir in dirs:
107 for f in files:
108 paths_.add(f.path)
109 117
110 except vcs.exception.RepositoryError, e: 118 except vcs.exception.RepositoryError, e:
111 pass 119 pass
112 120
113 for f in paths_: 121 for f in paths_:
123 131
124 print 'total_time', total_time 132 print 'total_time', total_time
125 print 'average on req', total_time / float(len(repo)) 133 print 'average on req', total_time / float(len(repo))
126 134
127 135
128 #test_changelog_walk()
129 #test_changeset_walk()
130 test_files_walk() 136 test_files_walk()
137 test_changelog_walk(40)
138 test_changeset_walk(limit=100)
139