allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [17/50] git commit: [#6388] simple call count script
Date Mon, 06 Jan 2014 15:18:07 GMT
[#6388] simple call count script


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/497a7347
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/497a7347
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/497a7347

Branch: refs/heads/cj/6992
Commit: 497a734704e692b02479a885390ddd2a4b0e3c53
Parents: 0f9768d
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Tue Dec 17 21:27:56 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Thu Jan 2 16:16:20 2014 +0000

----------------------------------------------------------------------
 Allura/allura/tests/decorators.py | 26 +++++++++++
 scripts/perf/call_count.py        | 80 ++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/497a7347/Allura/allura/tests/decorators.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/decorators.py b/Allura/allura/tests/decorators.py
index dd9fdf1..3e1c43d 100644
--- a/Allura/allura/tests/decorators.py
+++ b/Allura/allura/tests/decorators.py
@@ -26,6 +26,7 @@ import tg
 from paste.deploy.converters import asbool
 
 from allura import model as M
+import allura.config.middleware
 
 
 def with_user_project(username):
@@ -120,3 +121,28 @@ def without_module(*module_names):
                 return func(*a, **kw)
         return wrapped
     return _without_module
+
+
+class patch_middleware_config(object):
+    '''
+    Context manager that patches the configuration used during middleware
+    setup for Allura
+    '''
+
+    def __init__(self, new_configs):
+        self.new_configs = new_configs
+
+    def __enter__(self):
+        self._make_app = allura.config.middleware.make_app
+
+        def make_app(global_conf, full_stack=True, **app_conf):
+            app_conf.update(self.new_configs)
+            return self._make_app(global_conf, full_stack, **app_conf)
+
+        allura.config.middleware.make_app = make_app
+
+        return self
+
+    def __exit__(self, exc_type, exc_val, exc_t):
+        allura.config.middleware.make_app = self._make_app
+        return self

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/497a7347/scripts/perf/call_count.py
----------------------------------------------------------------------
diff --git a/scripts/perf/call_count.py b/scripts/perf/call_count.py
new file mode 100755
index 0000000..2b8e15c
--- /dev/null
+++ b/scripts/perf/call_count.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+import json
+from pprint import pprint
+
+from pylons import tmpl_context as c
+from testfixtures import LogCapture
+
+from allura import model as M
+from allura.lib.helpers import push_config
+from allura.tests import TestController
+from allura.tests.decorators import patch_middleware_config
+
+from forgewiki import model as WM
+
+
+def main():
+    test = TestController()
+    setup(test)
+    url = generate_wiki_thread(test)
+    load_page(test, url)
+    load_page(test, url)
+    load_page(test, url)
+    test.tearDown()
+
+
+def setup(test):
+    # includes setting up mim
+    with patch_middleware_config({'stats.sample_rate': 1}):
+       test.setUp()
+
+
+def generate_wiki_thread(test):
+    # automagically instantiate the app
+    test.app.get('/wiki/')
+
+    project = M.Project.query.get(shortname='test')
+    app = project.app_instance('wiki')
+
+    page = WM.Page.query.get(app_config_id=app.config._id, title='Home')
+    thread = page.discussion_thread
+    # create 3 posts by 2 users
+    with push_config(c, user=M.User.query.get(username='test-admin'),
+                        app=app,
+                        project=project):
+        thread.add_post(text='This is very helpful')
+        thread.add_post(text="But it's not **super** helpful")
+        with push_config(c, user=M.User.query.get(username='test-user')):
+            thread.add_post(text='I disagree')
+
+    url = '/p/test/wiki/_discuss/thread/{}/'.format(thread._id)
+    return url
+
+
+def load_page(test, url):
+    with LogCapture('stats') as l:
+        print url, test.app.get(url, extra_environ=dict(username='*anonymous')).status
+    for r in l.records:
+        timings = json.loads(r.message)
+        print json.dumps(timings['call_counts'])
+
+if __name__ == '__main__':
+    main()


Mime
View raw message