diff --git a/bin/load_gen b/bin/load_gen index cf770562d52f452275cae1f36118acdd2e804f54..aa858490e194c7a1af8834a882d31289f617d530 100755 --- a/bin/load_gen +++ b/bin/load_gen @@ -377,8 +377,7 @@ if (args.u) { // now create all them users! console.log("Runing with", (end - start + 1), "pre-created users (XXX@loadtest.domain)"); for (var i = start; i < end; i++) { - var user = userdb.getNewUser(i + "@loadtest.domain", "THE PASSWORD"); - userdb.releaseUser(user); + userdb.addNewUser(userdb.getNewUser(i + "@loadtest.domain", "THE PASSWORD")); } console.log("users created! applying load..."); poll(); diff --git a/lib/load_gen/activities/reset_pass.js b/lib/load_gen/activities/reset_pass.js index a60f5002ecbcce22661010989663f600032a10e2..45dca0cf569f72cda52afc03455d744f0f5eb726 100644 --- a/lib/load_gen/activities/reset_pass.js +++ b/lib/load_gen/activities/reset_pass.js @@ -45,26 +45,32 @@ common = require('../common'); exports.startFunc = function(cfg, cb) { - var user = userdb.getExistingUser(); + var origUser = userdb.getExistingUser(); - if (!user) { + if (!origUser) { winston.warn("can't achieve desired concurrency! not enough users!"); return cb("not enough users"); } + var user = origUser; + + var newUser; + if (user.emails.length > 1) { + user = newUser = userdb.splitUser(user); + } + // unlock the user when we're done with them cb = (function() { var _cb = cb; return function(x) { - userdb.releaseUser(user); + // if the request is successful, and we split off a new user, + // then lets add them to the database + if (!x && newUser) userdb.addNewUser(newUser); + userdb.releaseUser(origUser); _cb(x); }; })(); - // to "reset" a password, we'll break a single email of of the selected existing user - // into a new user. - user = userdb.splitUser(user); - // now everything is identical to the signup flow // pick a device context at random var context = userdb.any(user.ctxs); diff --git a/lib/load_gen/activities/signup.js b/lib/load_gen/activities/signup.js index 60270fd31500e59982f03274523f818a4f057f45..c15db747d90fe9294b7a089d4d291e128ebd005f 100644 --- a/lib/load_gen/activities/signup.js +++ b/lib/load_gen/activities/signup.js @@ -76,7 +76,7 @@ exports.startFunc = function(cfg, cb) { cb = (function() { var _cb = cb; return function(x) { - userdb.releaseUser(user); + if (!x) userdb.addNewUser(user); _cb(x); }; })(); @@ -109,7 +109,7 @@ exports.startFunc = function(cfg, cb) { try { r.body = JSON.parse(r.body); if (r.code !== 200 || r.body.success !== true) { - throw "non-success"; + throw "non-success" + (r.body && r.body.reason ? " (" + r.body.reason + ")" : ""); } } catch(e) { return cb("failed to complete user creation: " + e); diff --git a/lib/load_gen/common.js b/lib/load_gen/common.js index a02e599ea4bb8355863cdaaa3c4119ba0e543510..0a7cf61789c473e022578ff4195436de7309cd06 100644 --- a/lib/load_gen/common.js +++ b/lib/load_gen/common.js @@ -67,7 +67,7 @@ exports.genAssertionAndVerify = function(cfg, user, ctx, email, audience, cb) { try { if (!typeof JSON.parse(r.body) === 'object') throw 'bogus response'; } catch(e) { - return cb(e.toString()); + return cb(e.toString() + " - " + r.body); } var assertion = crypto.getAssertion({ diff --git a/lib/load_gen/user_db.js b/lib/load_gen/user_db.js index 3e15e19efc9434f68b7f84469f688bf8397fcaea..241b53119289106a1d0beafa2d18223b73775266 100644 --- a/lib/load_gen/user_db.js +++ b/lib/load_gen/user_db.js @@ -88,11 +88,14 @@ exports.getNewUser = function(email, password) { } ] }; - numLockedUsers++; - users.push(user); return user; }; +exports.addNewUser = function(user) { + delete user.locked; + users.push(user); +}; + var numLockedUsers = 0; exports.getExistingUser = function() { @@ -114,14 +117,13 @@ exports.getExistingUser = function() { exports.splitUser = function(user) { if (!user.locked) throw "you can't split a user that's not in use!"; if (user.emails.length == 1) { - return user; + throw "you can't split a user with only one email"; } else { var newuser = exports.getNewUser(); // When splitting an account, always split off the *last* email. // The *first* email may be associated with a pre-created account. // see issue #681 newuser.emails[0] = user.emails.pop(); - exports.releaseUser(user); return newuser; } };