Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socketio 1 #1319

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions client/jasmine_socketio_patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// TODO(vojta): remove once we don't care about karma-jasmine 0.1.x
//
// karma-jasmine@0.1.x relies on socket.io@0.9.x internals to figure out which transport is used.
// See https://github.com/karma-runner/karma-jasmine/blob/57dddeed2771d65457418f0357f740e3d64d6862/src/adapter.js#L50
//
// This should be ultimately solved on socket.io level (split or truncate too big messages).

var hostname = 'http://' + location.host;

if (!location.port) {
hostname += ':80';
}

if (!io.sockets) {
io.sockets = {};
// Patch, so that karma-jasmine does not throw "undefined has no transport property".
io.sockets[hostname] = {transport: {name: '<unknown transport>'}};
}
21 changes: 12 additions & 9 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var Karma = function(socket, iframe, opener, navigator, location) {
var returnUrl = queryParams['return_url' + ''] || null;
var currentTransport;

var resultsBufferLimit = 1;
var resultsBufferLimit = 50;
var resultsBuffer = [];

this.VERSION = constant.VERSION;
Expand Down Expand Up @@ -218,14 +218,17 @@ var Karma = function(socket, iframe, opener, navigator, location) {

// report browser name, id
socket.on('connect', function() {
currentTransport = socket.socket.transport.name;

// TODO(vojta): make resultsBufferLimit configurable
if (currentTransport === 'websocket' || currentTransport === 'flashsocket') {
resultsBufferLimit = 1;
} else {
resultsBufferLimit = 50;
}
// Change buffer limit when upgraded
socket.io.engine.on('upgrade', function() {
currentTransport = socket.io.engine.transport.name;

// TODO(vojta): make resultsBufferLimit configurable
// if (currentTransport === 'websocket' || currentTransport === 'flashsocket') {
// resultsBufferLimit = 1;
// } else {
// resultsBufferLimit = 50;
// }
});

socket.emit('register', {
name: navigator.userAgent,
Expand Down
4 changes: 4 additions & 0 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ var socket = io.connect('http://' + location.host, {
new StatusUpdater(socket, util.elm('title'), util.elm('banner'), util.elm('browsers'));
window.karma = new Karma(socket, util.elm('context'), window.open,
window.navigator, window.location);


// TODO(vojta): remove once we don't care about karma-jasmine 0.1.x
require('./jasmine_socketio_patch');
1 change: 1 addition & 0 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ var Browser = function(id, fullName, /* capturedBrowsers */ collection, emitter,

this.onResult = function(result) {
if (result.length) {
log.info('got results', result.length);
return result.forEach(this.onResult, this);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/launchers/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var ProcessLauncher = function(spawn, tempDir, timer) {

var errorOutput = '';

self._process.on('close', function(code) {
self._process.on('exit', function(code) {
self._onProcessExit(code, errorOutput);
});

Expand Down
10 changes: 4 additions & 6 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ var start = function(injector, config, launcher, globalEmitter, preprocess, file
// Slightly hacky way of removing disconnect listeners
// to suppress "browser disconnect" warnings
// TODO(vojta): change the client to not send the event (if disconnected by purpose)
var sockets = socketServer.sockets.sockets;
Object.getOwnPropertyNames(sockets).forEach(function(key) {
var socket = sockets[key];
socketServer.sockets.sockets.forEach(function(socket) {
socket.removeAllListeners('disconnect');
if (!socket.disconnected) {
socket.disconnect();
// Disconnect asynchronously. Socket.io mutates the `sockets.sockets` array underneath us
// so this would skip every other browser/socket.
process.nextTick(socket.disconnect.bind(socket));
}
});

Expand Down Expand Up @@ -266,9 +266,7 @@ var createSocketIoServer = function(webServer, executor, config) {
// properly on socket.io shutdown and this timeout prevents karma from exiting cleanly.
// We change this timeout to 0 to make Karma exit just after all tests were executed.
'client store expiration': 0,
logger: logger.create('socket.io', constant.LOG_ERROR),
resource: config.urlRoot + 'socket.io',
transports: config.transports
});

// hack to overcome circular dependency
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
],
"dependencies": {
"di": "~0.0.1",
"socket.io": "0.9.16",
"socket.io": "~1.3.0",
"chokidar": ">=0.8.2",
"glob": "~3.2.7",
"minimatch": "~0.2",
Expand Down
Loading