测试:http 简单压测例子
This commit is contained in:
18
game-server/config/adminUser.js
Normal file
18
game-server/config/adminUser.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
module.exports = [{
|
||||||
|
'id': 'user-1',
|
||||||
|
'username': 'admin',
|
||||||
|
'password': 'admin',
|
||||||
|
'level': 1
|
||||||
|
}, {
|
||||||
|
'id': 'user-2',
|
||||||
|
'username': 'monitor',
|
||||||
|
'password': 'monitor',
|
||||||
|
'level': 2
|
||||||
|
}, {
|
||||||
|
'id': 'user-3',
|
||||||
|
'username': 'test',
|
||||||
|
'password': 'test',
|
||||||
|
'level': 2
|
||||||
|
}
|
||||||
|
];
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRtaW5Vc2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vY29uZmlnL2FkbWluVXNlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLENBQUMsT0FBTyxHQUFHLENBQUM7UUFDZCxJQUFJLEVBQUUsUUFBUTtRQUNkLFVBQVUsRUFBRSxPQUFPO1FBQ25CLFVBQVUsRUFBRSxPQUFPO1FBQ25CLE9BQU8sRUFBRSxDQUFDO0tBQ2IsRUFBRTtRQUNDLElBQUksRUFBRSxRQUFRO1FBQ2QsVUFBVSxFQUFFLFNBQVM7UUFDckIsVUFBVSxFQUFFLFNBQVM7UUFDckIsT0FBTyxFQUFFLENBQUM7S0FDYixFQUFFO1FBQ0MsSUFBSSxFQUFFLFFBQVE7UUFDZCxVQUFVLEVBQUUsTUFBTTtRQUNsQixVQUFVLEVBQUUsTUFBTTtRQUNsQixPQUFPLEVBQUUsQ0FBQztLQUNiO0NBQ0EsQ0FBQyJ9
|
||||||
5
game-server/test/ab/abSmsLogin.sh
Executable file
5
game-server/test/ab/abSmsLogin.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
if [ $# -ne 2 ]; then
|
||||||
|
echo 需要两个参数,第一个表示请求数,第二个表示并发量
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
ab -n $1 -c $2 -p smsLoginParams.txt -T 'application/json' 'http://zyz_monitor_web.trgame.cn/user/smslogin'
|
||||||
3
game-server/test/ab/smsLoginParams.txt
Normal file
3
game-server/test/ab/smsLoginParams.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"data":"9218e9b6336ece43e9ee3d044482c0bbe9d8d8bfe31f5b6a63cc167d8dd4216eaea06fbcd2f7ad238f3db147b012d78d7c903edcbaff88b1cbd228dec41c23f816e67dfffc7d06203f52b9e573caca171aa21b795c8342da110a51022bcfa903de26615ed8e15a825d36844c5459b45bcface69f352620280aa4f5017b6ae179"
|
||||||
|
}
|
||||||
71
game-server/test/stress/account.test.ts
Normal file
71
game-server/test/stress/account.test.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import 'mocha';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import { genCode, generateNum } from '../../app/pubUtils/util';
|
||||||
|
const request = require('request');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
describe('注册登录测试', function() {
|
||||||
|
const ENCRYPT_IV = 'f7182j5f04e377ux';
|
||||||
|
const ENCRYPT_KEY = 'fiqaxijabbantusmprc234fj';
|
||||||
|
|
||||||
|
it('批量注册账号1', function(done) {
|
||||||
|
const accountNum = 10;
|
||||||
|
let sendNum = 0;
|
||||||
|
let resultNum = 0;
|
||||||
|
const monTimer = setInterval(() => {
|
||||||
|
if (resultNum === accountNum) {
|
||||||
|
done();
|
||||||
|
clearInterval(monTimer);
|
||||||
|
}
|
||||||
|
}, 20);
|
||||||
|
const params = [];
|
||||||
|
for (let i = 0; i < accountNum; i++) {
|
||||||
|
const tel = `13${generateNum(9)}`;
|
||||||
|
const param = {tel, deviceId: genCode(10), code: '', platform: 'ios', pkgName: 'com.bantu.zyz', serverType: 'dev'};
|
||||||
|
const paramStr = aesEncrypt(JSON.stringify(param), ENCRYPT_KEY, ENCRYPT_IV);
|
||||||
|
params.push(paramStr);
|
||||||
|
}
|
||||||
|
console.log(params.length);
|
||||||
|
while(sendNum < accountNum && params[sendNum]) {
|
||||||
|
console.log(`sendNum2: ${sendNum}`);
|
||||||
|
request.post('http://zyz_monitor_web.trgame.cn/user/smslogin', {
|
||||||
|
json: {
|
||||||
|
data: params[sendNum]
|
||||||
|
}
|
||||||
|
}, (err, res, body) => {
|
||||||
|
expect(err).to.be.equal(null);
|
||||||
|
expect(body.result).to.be.a('string');
|
||||||
|
const result = JSON.parse(aesDecrypt(body.result, ENCRYPT_KEY, ENCRYPT_IV));
|
||||||
|
expect(result.code).to.be.equal(0);
|
||||||
|
|
||||||
|
request.post('http://zyz_monitor_web.trgame.cn/user/createrole', {
|
||||||
|
json: {
|
||||||
|
data: aesEncrypt(JSON.stringify({token: result.data.token, serverId: 1, roleName: genCode(8)}), ENCRYPT_KEY, ENCRYPT_IV)
|
||||||
|
}
|
||||||
|
}, (err, res, body) => {
|
||||||
|
console.log(`resultNum2: ${resultNum}`);
|
||||||
|
expect(err).to.be.equal(null);
|
||||||
|
expect(body.result).to.be.a('string');
|
||||||
|
const result = JSON.parse(aesDecrypt(body.result, ENCRYPT_KEY, ENCRYPT_IV));
|
||||||
|
expect(result.code).to.be.equal(0);
|
||||||
|
resultNum++;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
sendNum++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function aesEncrypt(data, key, iv) {
|
||||||
|
const cipher = crypto.createCipheriv('aes-192-cbc', key, iv);
|
||||||
|
var crypted = cipher.update(data, 'utf8', 'hex');
|
||||||
|
crypted += cipher.final('hex');
|
||||||
|
return crypted;
|
||||||
|
}
|
||||||
|
|
||||||
|
function aesDecrypt(data, key, iv) {
|
||||||
|
const decipher = crypto.createDecipheriv('aes-192-cbc', key, iv);
|
||||||
|
var decrypted = decipher.update(data, 'hex', 'utf8');
|
||||||
|
decrypted += decipher.final('utf8');
|
||||||
|
return decrypted;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user