這兩天遭遇了手機號登陸相關的壓測需求,算是比較棘手的。主要緣由有兩個,第一:以前歷來沒有接手過這個項目,不熟悉各類規則;第二:數據量偏大,須要開發配合協調校驗規則。編程
traceNo
traceNo
、短信驗證碼、手機號請求登陸接口string
類型)traceNo
必需從發送驗證碼接口得到phone
和模塊類屬性lastTraceNo
來完成參數傳遞/** * 100個用戶經過發短信而後經過驗證碼登陸 */ class LoginByTel extends OkayBase { public static void main(String[] args) { def argsUtil = new ArgsUtil(args) def thread = argsUtil.getIntOrdefault(0, 100) def times = argsUtil.getIntOrdefault(1, 50) ClientManage.init(10000, 5000, 0) def threads = [] thread.times { def base = getBase(it) def info = new UserInfo(base) threads << new LoginTel(info, times) } new Concurrent(threads, "學生留存1.2.3手機驗證碼登陸").start() FanLibrary.testOver() } static class LoginTel extends ThreadLimitTimesCount<UserInfo> { public LoginTel(UserInfo info, int times) { super(info, times, null) } @Override protected void doing() throws Exception { threadmark = t.loginByTel() } } }
/** * 手機號登陸 */ public String loginByTel() { sendCodeOffline(2, phone); String url = Profile.LOGIN; JSONObject params = getParams(); params.put("login_mode", 2); params.put("params", getJson("code=" + Profile.LOGIN_CODE, "phone=" + phone)); JSONObject response = getPostResponse(url, params); if (isRight(response)) { token = response.getJSONObject("data").getString("token"); super.token = token; logger.info("帳號 {} 登陸成功", account); } else { output(response); logger.warn("帳號 {} 登陸失敗", account); fail(); } return token; }