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