Bug 1020024 - fix data channel connecting race conditions. r=jib

This commit is contained in:
Nils Ohlmeier [:drno] 2014-07-02 18:08:00 +02:00
Родитель 9c58a25bae
Коммит 6cbdff01c3
1 изменённых файлов: 34 добавлений и 18 удалений

Просмотреть файл

@ -1119,23 +1119,17 @@ DataChannelTest.prototype = Object.create(PeerConnectionTest.prototype, {
*/
value : function DCT_waitForInitialDataChannel(peer, onSuccess, onFailure) {
var dcConnectionTimeout = null;
var dcOpened = false;
function dataChannelConnected(channel) {
clearTimeout(dcConnectionTimeout);
is(channel.readyState, "open", peer + " dataChannels[0] switched to state: 'open'");
onSuccess();
}
if (peer.dataChannels.length >= 1) {
if (peer.dataChannels[0].readyState === "open") {
is(peer.dataChannels[0].readyState, "open", peer + " dataChannels[0] is already in state: 'open'");
// in case the switch statement below had called onSuccess already we
// don't want to call it again
if (!dcOpened) {
clearTimeout(dcConnectionTimeout);
is(channel.readyState, "open", peer + " dataChannels[0] switched to state: 'open'");
dcOpened = true;
onSuccess();
return;
} else {
is(peer.dataChannels[0].readyState, "connecting", peer + " dataChannels[0] is in state: 'connecting'");
}
} else {
info(peer + "'s dataChannels[] is empty");
}
// TODO: drno: convert dataChannels into an object and make
@ -1146,11 +1140,33 @@ DataChannelTest.prototype = Object.create(PeerConnectionTest.prototype, {
peer.registerDataChannelOpenEvents(dataChannelConnected);
}
if (onFailure) {
dcConnectionTimeout = setTimeout(function () {
info(peer + " timed out while waiting for dataChannels[0] to connect");
onFailure();
}, 60000);
if (peer.dataChannels.length >= 1) {
// snapshot of the live value as it might change during test execution
const readyState = peer.dataChannels[0].readyState;
switch (readyState) {
case "open": {
is(readyState, "open", peer + " dataChannels[0] is already in state: 'open'");
dcOpened = true;
onSuccess();
break;
}
case "connecting": {
is(readyState, "connecting", peer + " dataChannels[0] is in state: 'connecting'");
if (onFailure) {
dcConnectionTimeout = setTimeout(function () {
is(peer.dataChannels[0].readyState, "open", peer + " timed out while waiting for dataChannels[0] to open");
onFailure();
}, 60000);
}
break;
}
default: {
ok(false, "dataChannels[0] is in unexpected state " + readyState);
if (onFailure) {
onFailure()
}
}
}
}
}
}