最近遭遇了绑定手机号相关的压测需求,有了手机号登录的经验和测试数据,这次算起来比较简单。最重要的是难点就是要求开发配合调整配置已经在上一期文章:手机号验证码登录性能测试中问题解决了,绑定手机号唯一的难点就是如何在单账号绑定的过程中不断切换手机号,而且保证最后账号的绑定手机号还是一开始的14+uid
的模式。
traceNo
traceNo
、短信验证码、手机号请求绑定手机号接口string
类型)traceNo
必需从发送验证码接口获得149
和148
之间切换,149
为初始状态,这里并没有使用每次换一个新手机号,第一是怕出现偶然重复,第二是数据维护不容易phone
和模块类属性lastTraceNo
来完成参数传递/**
* 每个用户先发短信然后绑定手机号,手机号分为148和149切换,后8位于uid后8位.最后会把测试数据固定在149号段
*/
class BindPhone 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 Bind(info, times)
}
new Concurrent(threads, "学生留存1.2.3绑定手机号").start()
thread.times {
def base = getBase(it)
def info = new UserInfo(base)
info.bindPhoneInit()
}
FanLibrary.testOver()
}
static class Bind extends ThreadLimitTimesCount<UserInfo> {
public LoginTel(UserInfo info, int times) {
super(info, times, null)
}
@Override
protected void doing() throws Exception {
threadmark = t.bindPhone()
}
}
}
/**
* 获取用户信息
*
* @return
*/
public JSONObject getUserInfo() {
String url = UserInfoApi.USERINFO;
JSONObject params = getParams();
JSONObject response = getPostResponse(url, params);
output(response);
return response;
}
/**
* 绑定手机号
*
* @return
*/
public JSONObject bindPhone(String phone) {
sendCodeOnline(phone);
String url = UserInfoApi.BIND_PHONE;
JSONObject params = getParams();
params.put("phone", phone);
params.put("traceno", lastTraceNo);
params.put("code", Common.TEL_CODE);
JSONObject response = getPostResponse(url, params);
output(response);
return response;
}
/**
* 绑定手机号,压测用
*
* @return
*/
public String bindPhone() {
phone = phone.startsWith("149") ? 148 + phone.substring(3) : 149 + phone.substring(3);
bindPhone(phone);
return lastTraceNo;
}
/**
* 初始化手机号,默认id前两位改成14
*
* @return
*/
public JSONObject bindPhoneInit() {
JSONObject userInfo = getUserInfo();
String tel = userInfo.getJSONObject("data").getString("tel");
if (tel.startsWith("149")) return null;
phone = 149 + phone.substring(3);
sendCodeOnline(phone);
String url = UserInfoApi.BIND_PHONE;
JSONObject params = getParams();
params.put("phone", phone);
params.put("traceno", lastTraceNo);
params.put("code", Common.TEL_CODE);
JSONObject response = getPostResponse(url, params);
output(response);
return response;
}
/**
* 发送绑定手机号信息
*
* @param phone
* @return
*/
public JSONObject sendCodeOnline(String phone) {
String url = UserInfoApi.SEND_CODE_ONLINE;
JSONObject params = getParams();
params.put("scene_type", 1);//1绑定手机
params.put("phone", phone);
output(phone);
JSONObject response = getPostResponse(url, params);
output(response);
if (isRight(response)) {
lastTraceNo = response.getJSONObject("data").getString("traceno");
}
return response;
}