Skip to content

Commit

Permalink
Add room loadtest scenario.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Oct 6, 2014
1 parent 16f8634 commit 77bdd7c
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 14 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
+ Add a test to check participants expiricy (doesn't return items when not needed);
+ Handle the account property in the participant obj.
+ Encrypt account information in the database.
- Update the load test scripts
+ Update the load test scripts
- Update the memory usage script with rooms (+ other stuff that needs to be updated)
- Handle the TokBox channel on /rooms (+to say)

Expand Down
4 changes: 4 additions & 0 deletions config/loadtest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"fxaOAuth": {
"client_id": "cdaf76e75c7f7a00",
"client_secret": "74a35b3eeef81a4f36ba8e7bf76e9972a3af6bd7c4c2fba7db7ccfc8b324cb8b"
},
"rooms": {
"HKDFSalt": "6b4a7eec5406fcb3d394e7f64b2a72a2",
"maxSize": 10
}
}
1 change: 1 addition & 0 deletions loadtests/loadtest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def tearDown(self):
def test_all(self):
params = self.setupCall()
self._test_websockets(*params)
self.setupRoom()

def _get_json(self, resp):
try:
Expand Down
20 changes: 17 additions & 3 deletions loadtests/loadtest/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ def setupCall(self):
calls = self.list_pending_calls()
return token, call_data, calls

def register(self):
def register(self, data=None):
if data is None:
data = {'simple_push_url': 'http://httpbin.org/deny'}
resp = self.session.post(
self.base_url + '/registration',
data={'simple_push_url': 'http://httpbin.org/deny'})
data=json.dumps(data),
headers={'Content-Type': 'application/json'})
self.assertEquals(200, resp.status_code,
"Registration failed: %s" % resp.content)

Expand All @@ -24,6 +27,9 @@ def register(self):
except KeyError:
print resp
raise
else:
self.incr_counter("register")
return self.hawk_auth

def generate_call_url(self):
resp = self.session.post(
Expand All @@ -34,6 +40,7 @@ def generate_call_url(self):
)
self.assertEquals(resp.status_code, 200,
"Call-Url creation failed: %s" % resp.content)
self.incr_counter("generate-call-url")
data = self._get_json(resp)
call_url = data.get('callUrl', data.get('call_url'))
return call_url.split('/').pop()
Expand All @@ -47,16 +54,23 @@ def initiate_call(self, token):
)
self.assertEquals(resp.status_code, 200,
"Call Initialization failed: %s" % resp.content)
self.incr_counter("initiate-call")

return self._get_json(resp)

def list_pending_calls(self):
resp = self.session.get(
self.base_url + '/calls?version=200',
auth=self.hawk_auth)
self.assertEquals(resp.status_code, 200,
"List calls failed: %s" % resp.content)
self.incr_counter("list-pending-calls")
data = self._get_json(resp)
return data['calls']

def revoke_token(self, token):
# You don't need to be authenticated to revoke a token.
self.session.delete(self.base_url + '/call-url/%s' % token)
resp = self.session.delete(self.base_url + '/call-url/%s' % token)
self.assertEquals(resp.status_code, 204,
"Revoke call-url token failed: %s" % resp.content)
self.incr_counter("revoke_token")
60 changes: 50 additions & 10 deletions loadtests/loadtest/rooms.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,68 @@
import json
import random
from six.moves import range

MAX_NUMBER_OF_PEOPLE_JOINING = 10 # Pick a random number between 1 and this value
PERCENTAGE_OF_REFRESH = 50
PERCENTAGE_OF_MANUAL_LEAVE = 60
PERCENTAGE_OF_MANUAL_ROOM_DELETE = 80


class TestRoomsMixin(object):
def setupRoom(self):
self.register({
"simplePushURLs": {
"calls": "http://httpbin.org/deny",
"rooms": "http://httpbin.org/deny"
}
})
room_token = self.create_room()
num_participants = random.randint(1, MAX_NUMBER_OF_PEOPLE_JOINING)
self.incr_counter("num-participants-%d" % num_participants)

for x in range(num_participants):
participant_hawk_auth = self.register()
self.join_room(room_token, participant_hawk_auth)

if random.randint(0, 100) < PERCENTAGE_OF_REFRESH:
self.refresh_room_presence(room_token, participant_hawk_auth)

if random.randint(0, 100) < PERCENTAGE_OF_MANUAL_LEAVE:
self.leave_room(room_token, participant_hawk_auth)

if random.randint(0, 100) < PERCENTAGE_OF_MANUAL_ROOM_DELETE:
self.delete_room(room_token)

def create_room(self):
self.hawk_room_owner = self.hawk_auth
resp = self.session.post(
self.base_url + '/rooms',
data=json.dumps({
"roomName": "UX Discussion",
"expiresIn": 1,
"roomOwner": "Alexis",
"maxSize": 10
"maxSize": MAX_NUMBER_OF_PEOPLE_JOINING
}),
headers={'Content-Type': 'application/json'},
auth=self.hawk_auth
auth=self.hawk_room_owner
)
self.assertEquals(201, resp.status_code,
"Room Creation failed with code %s: %s" % (
resp.status_code, resp.content))
self.incr_counter("create-room")
data = self._get_json(resp)
return data.get('roomToken')

def delete_room(self, room_token):
resp = self.session.delete(
self.base_url + '/rooms/%s' % room_token,
headers={'Content-Type': 'application/json'}
headers={'Content-Type': 'application/json'},
auth=self.hawk_room_owner
)

self.assertEquals(200, resp.status_code,
self.assertEquals(204, resp.status_code,
"Room deletion failed with code %s: %s" % (
resp.status_code, resp.content))
self.incr_counter("delete-room")

def join_room(self, room_token, hawk_auth=None):
if not hawk_auth:
Expand All @@ -39,14 +73,16 @@ def join_room(self, room_token, hawk_auth=None):
data=json.dumps({
"action": "join",
"displayName": "Adam",
"clientMaxSize": 2
"clientMaxSize": MAX_NUMBER_OF_PEOPLE_JOINING
}),
headers={'Content-Type': 'application/json'}
headers={'Content-Type': 'application/json'},
auth=hawk_auth
)

self.assertEquals(200, resp.status_code,
"Participant Creation failed with code %s: %s" % (
resp.status_code, resp.content))
self.incr_counter("join-room")

def refresh_room_presence(self, room_token, hawk_auth=None):
if not hawk_auth:
Expand All @@ -57,12 +93,14 @@ def refresh_room_presence(self, room_token, hawk_auth=None):
data=json.dumps({
"action": "refresh"
}),
headers={'Content-Type': 'application/json'}
headers={'Content-Type': 'application/json'},
auth=hawk_auth
)

self.assertEquals(200, resp.status_code,
"Participant refresh failed with code %s: %s" % (
resp.status_code, resp.content))
self.incr_counter("refresh-room-presence")

def leave_room(self, room_token, hawk_auth=None):
if not hawk_auth:
Expand All @@ -73,9 +111,11 @@ def leave_room(self, room_token, hawk_auth=None):
data=json.dumps({
"action": "leave"
}),
headers={'Content-Type': 'application/json'}
headers={'Content-Type': 'application/json'},
auth=hawk_auth
)

self.assertEquals(200, resp.status_code,
self.assertEquals(204, resp.status_code,
"Room leave failed with code %s: %s" % (
resp.status_code, resp.content))
self.incr_counter("leave-room")
1 change: 1 addition & 0 deletions loop/encrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function encrypt(passphrase, text) {
if (text === null) {
throw new Error("Text is empty");
}
console.log(passphrase);
var box = new sodium.SecretBox(passphrase);
var encrypted = box.encrypt(text, "utf8");
var data = {
Expand Down
8 changes: 8 additions & 0 deletions loop/routes/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ module.exports = function (apiRouter, conf, logError, storage, auth,
* @param {Function} callback which will receive the encrypted account info.
**/
function encryptAccountName(roomToken, account, callback) {
if (account === undefined) {
callback();
return;
}
var hkdf = new HKDF('sha256', roomsConf.HKDFSalt, roomToken);
hkdf.derive('account-name', 32, function(key) {
callback(encrypt(key.toString('hex'), account));
Expand All @@ -105,6 +109,10 @@ module.exports = function (apiRouter, conf, logError, storage, auth,
* @param {Function} callback which will receive the decrypted account info.
**/
function decryptAccountName(roomToken, encryptedAccount, callback) {
if (encryptedAccount === undefined) {
callback();
return;
}
var hkdf = new HKDF('sha256', roomsConf.HKDFSalt, roomToken);
hkdf.derive('account-name', 32, function(key) {
callback(decrypt(key.toString('hex'), encryptedAccount));
Expand Down
13 changes: 13 additions & 0 deletions loop/tokbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ FakeTokBox.prototype = {
return 'T' + this._token + '==' + this._urlSafeBase64RandomBytes(293);
},

getSession: function(options, cb) {
if (cb === undefined) {
cb = options;
options = undefined;
}

cb(null, this._fakeSessionId(), {apiKey: this._fakeApiKey()});
},

getSessionToken: function(sessionId) {
return this._generateFakeToken();
},

getSessionTokens: function(options, cb) {
if (cb === undefined) {
cb = options;
Expand Down

0 comments on commit 77bdd7c

Please sign in to comment.