Selecting bot_type changed to be specified in the test file
Selecting bot_type changed to be specified in the test file instead of specify it in the running command. Now we can write test for rtcBot that run one bot on chrome for android and the other bot on chrome for desktop. R=andresp@webrtc.org Review URL: https://webrtc-codereview.appspot.com/23069004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7458 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
e93cbd13d5
commit
3e2f8ff36c
@ -17,12 +17,7 @@ access its exposed API. Details are in botmanager.js.
|
||||
== How to run the test ==
|
||||
$ cd trunk/webrtc/tool/rtcbot
|
||||
$ npm install express browserify ws websocket-stream dnode
|
||||
$ node test.js <bot_type> <test_file_path>
|
||||
|
||||
<bot_type> — the type of the running bot. For example:
|
||||
- chrome: chrome on host machine.
|
||||
- android: android device. Details in "Android" Section.
|
||||
- android-chrome: chrome on android device. Details in "Android" Section.
|
||||
$ node test.js <test_file_path>
|
||||
|
||||
== Example on how to install nodejs ==
|
||||
$ cd /work/tools/
|
||||
@ -31,6 +26,12 @@ access its exposed API. Details are in botmanager.js.
|
||||
$ nvm install 0.10
|
||||
$ nvm use 0.10
|
||||
|
||||
== Supported Bot Types ==
|
||||
- "chrome": chrome on host machine.
|
||||
- "android-chrome": chrome on android device. Details in "Android" Section.
|
||||
|
||||
* Bot type is specified for each spawned bot in the test file.
|
||||
|
||||
== Android ==
|
||||
Before running test with Android one MUST forward the device port 8080 to the
|
||||
host machine. That is easy to achieve with chrome port forwarding tools.
|
||||
|
@ -25,10 +25,10 @@ function getUserMedia(constraints, onSuccessCallback, onFailCallback){
|
||||
}
|
||||
}
|
||||
|
||||
function createPeerConnection(doneCallback, failCallback) {
|
||||
function createPeerConnection(config, doneCallback, failCallback) {
|
||||
console.log("Creating peer connection");
|
||||
var obj = {};
|
||||
var pc = new webkitRTCPeerConnection(null);
|
||||
var pc = new webkitRTCPeerConnection(config);
|
||||
|
||||
expose(obj, pc, "close");
|
||||
expose(obj, pc, "createOffer");
|
||||
@ -113,9 +113,38 @@ function getStreamFromIdentifier_(id) {
|
||||
return null;
|
||||
};
|
||||
|
||||
// Ask computeengineondemand to give us TURN server credentials and URIs.
|
||||
function asyncCreateTurnConfig(onSuccess, onError) {
|
||||
var CEOD_URL = ('https://computeengineondemand.appspot.com/turn?' +
|
||||
'username=1234&key=5678');
|
||||
var xhr = new XMLHttpRequest();
|
||||
function onResult() {
|
||||
if (xhr.readyState != 4)
|
||||
return;
|
||||
|
||||
if (xhr.status != 200) {
|
||||
onError('TURN request failed');
|
||||
return;
|
||||
}
|
||||
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
var iceServer = {
|
||||
'username': response.username,
|
||||
'credential': response.password,
|
||||
'urls': response.uris
|
||||
};
|
||||
onSuccess({ 'iceServers': [ iceServer ] });
|
||||
}
|
||||
|
||||
xhr.onreadystatechange = onResult;
|
||||
xhr.open('GET', CEOD_URL, true);
|
||||
xhr.send();
|
||||
};
|
||||
|
||||
connectToServer({
|
||||
ping: ping,
|
||||
getUserMedia: getUserMedia,
|
||||
createPeerConnection: createPeerConnection,
|
||||
showStream: showStream,
|
||||
asyncCreateTurnConfig: asyncCreateTurnConfig,
|
||||
});
|
||||
|
@ -16,11 +16,10 @@ var fs = require('fs');
|
||||
var vm = require('vm');
|
||||
var BotManager = require('./botmanager.js');
|
||||
|
||||
function Test(botType) {
|
||||
function Test() {
|
||||
this.timeout_ = setTimeout(
|
||||
this.fail.bind(this, "Test timeout!"),
|
||||
100000);
|
||||
this.botType_ = botType;
|
||||
}
|
||||
|
||||
Test.prototype = {
|
||||
@ -67,11 +66,11 @@ Test.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
spawnBot: function (name, doneCallback) {
|
||||
spawnBot: function (name, botType, doneCallback) {
|
||||
// Lazy initialization of botmanager.
|
||||
if (!this.botManager_)
|
||||
this.botManager_ = new BotManager();
|
||||
this.botManager_.spawnNewBot(name, this.botType_, doneCallback);
|
||||
this.botManager_.spawnNewBot(name, botType, doneCallback);
|
||||
},
|
||||
|
||||
createStatisticsReport: function (outputFileName) {
|
||||
@ -137,11 +136,11 @@ StatisticsReport.prototype = {
|
||||
},
|
||||
}
|
||||
|
||||
function runTest(botType, testfile) {
|
||||
function runTest(testfile) {
|
||||
console.log("Running test: " + testfile);
|
||||
var script = vm.createScript(fs.readFileSync(testfile), testfile);
|
||||
script.runInNewContext({ test: new Test(botType), setInterval: setInterval,
|
||||
script.runInNewContext({ test: new Test(), setInterval: setInterval,
|
||||
setTimeout: setTimeout });
|
||||
}
|
||||
|
||||
runTest(process.argv[2], process.argv[3]);
|
||||
runTest(process.argv[2]);
|
||||
|
@ -16,4 +16,4 @@ function testPingPong(bot) {
|
||||
}
|
||||
}
|
||||
|
||||
test.spawnBot("alice", testPingPong);
|
||||
test.spawnBot("alice", "chrome", testPingPong);
|
||||
|
@ -17,7 +17,7 @@ function testOfferAnswer(peer1, peer2) {
|
||||
establishCall);
|
||||
|
||||
function createPeerConnection(done) {
|
||||
this.createPeerConnection(done, test.fail);
|
||||
this.createPeerConnection(null, done, test.fail);
|
||||
}
|
||||
|
||||
function establishCall(pc1, pc2) {
|
||||
@ -49,6 +49,6 @@ function expectedCall() {
|
||||
test.done();
|
||||
}
|
||||
|
||||
test.wait( [ test.spawnBot.bind(test, "alice"),
|
||||
test.spawnBot.bind(test, "bob") ],
|
||||
test.wait( [ test.spawnBot.bind(test, "alice", "chrome"),
|
||||
test.spawnBot.bind(test, "bob", "chrome") ],
|
||||
testOfferAnswer);
|
||||
|
@ -24,7 +24,9 @@ function testVideoStreaming(bot1, bot2) {
|
||||
onPeerConnectionCreated);
|
||||
|
||||
function createPeerConnection(done) {
|
||||
this.createPeerConnection(done, test.fail);
|
||||
this.asyncCreateTurnConfig(function(config) {
|
||||
this.createPeerConnection(config, done, test.fail);
|
||||
}.bind(this), test.fail);
|
||||
}
|
||||
|
||||
function onPeerConnectionCreated(peer1, peer2) {
|
||||
@ -101,6 +103,6 @@ function testVideoStreaming(bot1, bot2) {
|
||||
}
|
||||
}
|
||||
|
||||
test.wait( [ test.spawnBot.bind(test, "alice"),
|
||||
test.spawnBot.bind(test, "bob") ],
|
||||
test.wait( [ test.spawnBot.bind(test, "alice", "chrome"),
|
||||
test.spawnBot.bind(test, "bob", "android-chrome") ],
|
||||
testVideoStreaming);
|
||||
|
Loading…
Reference in New Issue
Block a user