2010-11-04 02:18:18 +03:00
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
# 1.1 (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.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
# for the specific language governing rights and limitations under the
|
|
|
|
# License.
|
|
|
|
#
|
|
|
|
# The Original Code is Raindrop.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is
|
|
|
|
# Mozilla Messaging, Inc..
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
#
|
|
|
|
|
2010-09-20 10:34:19 +04:00
|
|
|
# The Grinder 3.4
|
|
|
|
# HTTP script originally recorded by TCPProxy, but then hacked...
|
|
|
|
|
|
|
|
from net.grinder.script import Test
|
|
|
|
from net.grinder.script.Grinder import grinder
|
|
|
|
from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
|
|
|
|
from HTTPClient import NVPair
|
|
|
|
from HTTPClient import Cookie, CookieModule, CookiePolicyHandler
|
|
|
|
|
|
|
|
connectionDefaults = HTTPPluginControl.getConnectionDefaults()
|
2011-03-04 22:56:40 +03:00
|
|
|
|
|
|
|
# Decode gzipped responses
|
|
|
|
connectionDefaults.useContentEncoding = 1
|
2011-03-23 22:12:20 +03:00
|
|
|
# in ms
|
|
|
|
connectionDefaults.setTimeout(60000)
|
2011-03-04 22:56:40 +03:00
|
|
|
|
2010-09-20 10:34:19 +04:00
|
|
|
httpUtilities = HTTPPluginControl.getHTTPUtilities()
|
|
|
|
|
|
|
|
log = grinder.logger.output
|
|
|
|
|
2010-09-23 09:57:47 +04:00
|
|
|
# Properties read from the grinder .properties file.
|
|
|
|
# After how many 'send' requests should we perform oauth? This is to
|
|
|
|
# simulate cookie expiry or session timeouts.
|
|
|
|
sends_per_oauth = grinder.getProperties().getInt("linkdrop.sends_per_oauth", 0)
|
|
|
|
|
2010-09-20 10:34:19 +04:00
|
|
|
# The URL of the server we want to hit.
|
2010-09-23 09:57:47 +04:00
|
|
|
linkdrop_host = grinder.getProperties().getProperty("linkdrop.host", 'http://127.0.0.1:5000')
|
|
|
|
|
2010-10-19 21:20:20 +04:00
|
|
|
# Service we want to test
|
|
|
|
linkdrop_service = grinder.getProperties().getProperty("linkdrop.service", 'twitter.com')
|
|
|
|
|
|
|
|
# Static URL we want to hit
|
|
|
|
linkdrop_static_url = grinder.getProperties().getProperty("linkdrop.static_url", '/share/')
|
|
|
|
|
|
|
|
# How often we want to hit the static page per send
|
|
|
|
linkdrop_static_per_send = grinder.getProperties().getInt("linkdrop.static_per_send", 0)
|
|
|
|
|
2010-09-20 10:34:19 +04:00
|
|
|
# *sob* - failed to get json packages working. Using 're' is an option,
|
|
|
|
# although it requires you install jython2.5 (which still doesn't have
|
|
|
|
# json builtin) - so to avoid all that complication, hack 'eval' into
|
|
|
|
# working for us...
|
|
|
|
_json_ns = {'null': None}
|
|
|
|
def json_loads(val):
|
|
|
|
return eval(val, _json_ns)
|
|
|
|
|
2010-09-23 09:57:47 +04:00
|
|
|
CookieModule.setCookiePolicyHandler(None)
|
2010-09-20 10:34:19 +04:00
|
|
|
from net.grinder.plugin.http import HTTPPluginControl
|
|
|
|
HTTPPluginControl.getConnectionDefaults().followRedirects = 1
|
|
|
|
|
|
|
|
# To use a proxy server, uncomment the next line and set the host and port.
|
|
|
|
# connectionDefaults.setProxyServer("localhost", 8001)
|
|
|
|
|
|
|
|
# These definitions at the top level of the file are evaluated once,
|
|
|
|
# when the worker process is started.
|
|
|
|
connectionDefaults.defaultHeaders = \
|
|
|
|
[ NVPair('Accept-Language', 'en-us,en;q=0.5'),
|
|
|
|
NVPair('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'),
|
|
|
|
NVPair('Accept-Encoding', 'gzip, deflate'),
|
|
|
|
NVPair('User-Agent', 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:2.0b6) Gecko/20100101 Firefox/4.0b6'), ]
|
|
|
|
|
|
|
|
request1 = HTTPRequest()
|
|
|
|
|
2011-03-23 22:12:20 +03:00
|
|
|
def authService():
|
2010-09-20 10:34:19 +04:00
|
|
|
threadContext = HTTPPluginControl.getThreadHTTPClientContext()
|
|
|
|
CookieModule.discardAllCookies(threadContext)
|
|
|
|
# Call authorize requesting we land back on /account/get - after
|
|
|
|
# a couple of redirects for auth, we should wind up with the data from
|
|
|
|
# account/get - which should now include our account info.
|
2010-09-23 09:57:47 +04:00
|
|
|
result = request1.POST(linkdrop_host + '/api/account/authorize',
|
2011-03-23 22:12:20 +03:00
|
|
|
(
|
2010-10-19 21:20:20 +04:00
|
|
|
NVPair('domain', linkdrop_service),
|
2010-09-20 10:34:19 +04:00
|
|
|
NVPair('end_point_success', '/api/account/get'),
|
2011-03-23 22:12:20 +03:00
|
|
|
NVPair('end_point_auth_failure', '/current/send/auth.html#oauth_failure'), ),
|
2010-09-20 10:34:19 +04:00
|
|
|
( NVPair('Content-Type', 'application/x-www-form-urlencoded'), ))
|
2010-09-23 09:57:47 +04:00
|
|
|
assert result.getStatusCode()==200, result
|
2010-09-20 10:34:19 +04:00
|
|
|
data = json_loads(result.getText())
|
|
|
|
assert data, 'account/get failed to return data'
|
|
|
|
userid = data[0]['accounts'][0]['userid']
|
2011-03-23 22:12:20 +03:00
|
|
|
for cookie in CookieModule.listAllCookies(threadContext):
|
|
|
|
if cookie.name == "linkdrop":
|
|
|
|
linkdrop_cookie = cookie
|
|
|
|
assert linkdrop_cookie
|
|
|
|
return userid, linkdrop_cookie
|
2010-09-20 10:34:19 +04:00
|
|
|
|
2010-10-19 21:20:20 +04:00
|
|
|
authService = Test(3, "auth %s" % linkdrop_service).wrap(authService)
|
2010-10-01 20:27:41 +04:00
|
|
|
|
2011-03-23 22:12:20 +03:00
|
|
|
def send(userid, domain=linkdrop_service, message="take that!"):
|
2010-09-23 09:57:47 +04:00
|
|
|
"""POST send."""
|
2011-03-23 22:12:20 +03:00
|
|
|
assert userid, 'userid id set'
|
2010-09-23 09:57:47 +04:00
|
|
|
result = request1.POST(linkdrop_host + '/api/send',
|
|
|
|
( NVPair('domain', domain),
|
2010-09-20 10:34:19 +04:00
|
|
|
NVPair('userid', userid),
|
2011-03-09 06:57:34 +03:00
|
|
|
# NOTE: no 'link' as we don't want to hit bitly in these tests
|
|
|
|
# (and if we ever decide we do, we must not use the bitly production
|
|
|
|
# userid and key!)
|
|
|
|
# NVPair('link', "http://www.google.com/%s" % grinder.getRunNumber() ),
|
2010-09-23 09:57:47 +04:00
|
|
|
NVPair('message', message), ),
|
2010-09-20 10:34:19 +04:00
|
|
|
( NVPair('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'), ))
|
2010-09-23 09:57:47 +04:00
|
|
|
assert result.getStatusCode()==200, result
|
|
|
|
assert '"error": null' in result.getText(), result.getText()
|
2010-09-20 10:34:19 +04:00
|
|
|
return result
|
|
|
|
|
2010-10-01 20:27:41 +04:00
|
|
|
send = Test(4, "Send message").wrap(send)
|
|
|
|
|
2010-10-19 21:20:20 +04:00
|
|
|
def getStatic(url="/share/"):
|
2011-03-09 06:57:34 +03:00
|
|
|
result = request1.GET(linkdrop_host + url)
|
|
|
|
assert result.getStatusCode()==200, result
|
|
|
|
return result
|
2010-10-19 21:20:20 +04:00
|
|
|
|
|
|
|
getStatic = Test(5, "Static request").wrap(getStatic)
|
|
|
|
|
2010-09-23 09:57:47 +04:00
|
|
|
# The test itself.
|
|
|
|
class TestRunner:
|
|
|
|
"""A TestRunner instance is created for each worker thread."""
|
|
|
|
def __init__(self):
|
|
|
|
self.linkdrop_cookie = None
|
2011-03-04 22:58:36 +03:00
|
|
|
self.userid = None
|
2010-09-23 09:57:47 +04:00
|
|
|
|
|
|
|
def doit(self):
|
2011-03-09 06:57:34 +03:00
|
|
|
if linkdrop_static_per_send:
|
|
|
|
for i in range(0,linkdrop_static_per_send):
|
|
|
|
getStatic(linkdrop_static_url)
|
2011-03-23 22:12:20 +03:00
|
|
|
|
|
|
|
if (sends_per_oauth and grinder.getRunNumber() % sends_per_oauth==0):
|
|
|
|
self.linkdrop_cookie = None
|
|
|
|
self.userid = None
|
|
|
|
|
|
|
|
if self.userid is None:
|
|
|
|
self.userid, self.linkdrop_cookie = authService()
|
|
|
|
|
2010-09-23 09:57:47 +04:00
|
|
|
# cookies are reset by the grinder each test run - re-inject the
|
|
|
|
# linkdrop session cookie.
|
|
|
|
threadContext = HTTPPluginControl.getThreadHTTPClientContext()
|
|
|
|
CookieModule.addCookie(self.linkdrop_cookie, threadContext)
|
2011-03-23 22:12:20 +03:00
|
|
|
send(self.userid)
|
2010-09-23 09:57:47 +04:00
|
|
|
|
|
|
|
# wrap the work in a grinder 'Test' - the unit where stats are collected.
|
|
|
|
doit = Test(1, "send with oauth").wrap(doit)
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
"""This method is called for every run performed by the worker thread."""
|
2010-10-01 20:27:41 +04:00
|
|
|
TestRunner.doit(self)
|