Skip to content
Permalink
Browse files

[FIX JENKINS-37206] Updated to use newer SSE client for stability (#61)

* Updated to use newer SSE client

* Updated to use newer SSE client
  • Loading branch information...
tfennelly committed Oct 13, 2016
1 parent 50dd452 commit 125172d45887d4d8075864a0e265e2004d0de1c4
Showing with 16 additions and 17 deletions.
  1. +1 −1 package.json
  2. +14 −16 src/main/js/api/sse.js
  3. +1 −0 src/main/js/globals.js
@@ -24,7 +24,7 @@
"homepage": "https://github.com/cloudbees/blueocean-acceptance-test#readme",
"devDependencies": {
"@jenkins-cd/js-modules": "0.0.8",
"@jenkins-cd/sse-gateway": "0.0.9",
"@jenkins-cd/sse-gateway": "0.0.10",
"async": "^2.0.1",
"events": "1.1.1",
"eventsource": "0.2.1",
@@ -2,6 +2,7 @@ var sseClient = require('@jenkins-cd/sse-gateway/headless-client');
var jobChannel = undefined;
var jobEventListeners = [];
var jobEventHistory = [];
var sseConnection;

/**
* Connect to the SSE Gateway.
@@ -12,22 +13,20 @@ var jobEventHistory = [];
* @param done
*/
exports.connect = function(browser, done) {
if (jobChannel) {
if (sseConnection) {
exports.disconnect(function() {
exports.connect(browser, done);
});
} else {
sseClient.connect({
sseConnection = sseClient.connect({
clientId: 'blueocean-acceptance-tests',
jenkinsUrl: browser.launchUrl,
onConnect: function() {
browser.sseClient = sseClient;

console.log('Connected to the Jenkins SSE Gateway.');

// Subscribe to job channel so we have it ready to listen
// before any tests start running.
jobChannel = sseClient.subscribe({
jobChannel = sseConnection.subscribe({
channelName: 'job',
onEvent: function (event) {
callJobEventListeners(event);
@@ -40,7 +39,6 @@ exports.connect = function(browser, done) {
}
});
}
browser.sseClient = sseClient;
};

/**
@@ -52,22 +50,22 @@ exports.connect = function(browser, done) {
*/
exports.disconnect = function(onDisconnected) {
function clientDisconnect() {
sseClient.disconnect();
if (sseConnection) {
sseConnection.disconnect();
}
sseConnection = undefined;
jobEventListeners = [];
jobEventHistory = [];
console.log('Disconnected from the Jenkins SSE Gateway.');
if (onDisconnected) {
onDisconnected();
}
}

if (jobChannel) {
sseClient.unsubscribe(jobChannel, function() {
try {
jobChannel = undefined;
clientDisconnect();
} finally {
if (onDisconnected) {
onDisconnected();
}
}
sseConnection.unsubscribe(jobChannel, function() {
jobChannel = undefined;
clientDisconnect();
});
} else {
clientDisconnect();
@@ -19,6 +19,7 @@ module.exports = {
browser.end();
} finally {
sse.disconnect(function() {
console.log('>> Test suite "done". Okay to start next test.');
done();
});
}

0 comments on commit 125172d

Please sign in to comment.
You can’t perform that action at this time.