Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
[FIX JENKINS-37206] Updated to use newer SSE client for stability (#61)
Browse files Browse the repository at this point in the history
* Updated to use newer SSE client

* Updated to use newer SSE client
  • Loading branch information
tfennelly committed Oct 13, 2016
1 parent 50dd452 commit 125172d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
30 changes: 14 additions & 16 deletions src/main/js/api/sse.js
Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -40,7 +39,6 @@ exports.connect = function(browser, done) {
}
});
}
browser.sseClient = sseClient;
};

/**
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/main/js/globals.js
Expand Up @@ -19,6 +19,7 @@ module.exports = {
browser.end();
} finally {
sse.disconnect(function() {
console.log('>> Test suite "done". Okay to start next test.');
done();
});
}
Expand Down

0 comments on commit 125172d

Please sign in to comment.