mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-06-05 16:58:22 +00:00
recover test.js, ready to release beta version
This commit is contained in:
parent
cfc817cb1f
commit
5130553c38
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "anyproxy",
|
"name": "anyproxy",
|
||||||
"version": "3.7.7",
|
"version": "3.8.0Beta1",
|
||||||
"description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.",
|
"description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.",
|
||||||
"main": "proxy.js",
|
"main": "proxy.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
85
test/test.js
85
test/test.js
@ -1,67 +1,60 @@
|
|||||||
var proxy = require("../proxy.js"),
|
var proxy = require("../proxy.js"),
|
||||||
proxyTester = require("proxy-eval"),
|
proxyTester = require("proxy-eval"),
|
||||||
WebSocket = require("ws");
|
WebSocket = require("ws");
|
||||||
|
|
||||||
//start a new proxy at port 8995, with websocket port 8996
|
//start a new proxy at port 8995, with websocket port 8996
|
||||||
var SOCKET_PORT = 8996,
|
var SOCKET_PORT = 8996,
|
||||||
PROXY_PORT = 8995;
|
PROXY_PORT = 8995;
|
||||||
|
|
||||||
new proxy.proxyServer({
|
new proxy.proxyServer({
|
||||||
type :"http",
|
type :"http",
|
||||||
port :PROXY_PORT,
|
port :PROXY_PORT,
|
||||||
socketPort :SOCKET_PORT,
|
socketPort :SOCKET_PORT,
|
||||||
silent :true
|
silent :true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
exports.avalibility = function(test){
|
exports.avalibility = function(test){
|
||||||
test.expect(2);
|
test.expect(2);
|
||||||
var updateCount = 0;
|
var updateCount = 0;
|
||||||
|
|
||||||
//test web socket
|
//test web socket
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
var ws = new WebSocket('ws://127.0.0.1:' + SOCKET_PORT , {
|
var ws = new WebSocket('ws://127.0.0.1:' + SOCKET_PORT , {
|
||||||
protocolVersion: 8
|
protocolVersion: 8
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('open', function open(){});
|
ws.on('open', function open(){});
|
||||||
ws.on('close', function close(){});
|
ws.on('close', function close(){});
|
||||||
ws.on('message', function message(data, flags) {
|
ws.on('message', function message(data, flags) {
|
||||||
try{
|
try{
|
||||||
var jsonData = JSON.parse(data);
|
var jsonData = JSON.parse(data);
|
||||||
jsonData.type == "update" && ++updateCount;
|
jsonData.type == "update" && ++updateCount;
|
||||||
}catch(e){}
|
}catch(e){}
|
||||||
});
|
});
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
test.ok(updateCount >= 4,"web socket message count of type 'update' ");
|
test.ok(updateCount >= 4,"web socket message count of type 'update' ");
|
||||||
test.done();
|
test.done();
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
process.exit();
|
process.exit();
|
||||||
},1000);
|
},1000);
|
||||||
},10*1000);
|
},10*1000);
|
||||||
|
|
||||||
},1000);
|
},1000);
|
||||||
|
|
||||||
//test the basic availibility of proxy server
|
//test the basic availibility of proxy server
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
var testParam = {
|
proxyTester.test({proxy : 'http://127.0.0.1:8995',reqTimeout:4500} ,function(results){
|
||||||
proxy : 'http://127.0.0.1:8995',
|
var successCount = 0;
|
||||||
reqTimeout : 4500,
|
results.map(function(item){
|
||||||
httpsPostUrl : "http://www.sample.com/"
|
item.success && ++successCount;
|
||||||
httpsPostBody : "123"
|
});
|
||||||
};
|
|
||||||
proxyTester.test(testParam ,function(results){
|
|
||||||
var successCount = 0;
|
|
||||||
results.map(function(item){
|
|
||||||
item.success && ++successCount;
|
|
||||||
});
|
|
||||||
|
|
||||||
var ifPassed = (true || results.length == successCount);
|
var ifPassed = (true || results.length == successCount);
|
||||||
if(!ifPassed){
|
if(!ifPassed){
|
||||||
proxyTester.printResult(results);
|
proxyTester.printResult(results);
|
||||||
}
|
}
|
||||||
test.ok(ifPassed, "availibility test failed");
|
test.ok(ifPassed, "availibility test failed");
|
||||||
});
|
});
|
||||||
},1000);
|
},1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user