Last active
May 6, 2019 10:53
-
-
Save akshayamaldhure/09facbd1ea4959d91a58fd8dd53fac53 to your computer and use it in GitHub Desktop.
Node.js mocha test spec to check for Event Store in-flight events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let request = require('supertest'); | |
let assert = require('chai').assert; | |
let apiBaseUri = request("http://your.event.store.url:port.number"); | |
describe('Ensure no in-Flight events in the Event Store', function () { | |
let subscriptionsEndpoint = '/subscriptions'; | |
it(' Verify the total number of in-flight messages = 0', (done) => { | |
let maxRetryCount = 5; | |
let pollingInterval = 5000; | |
checkInFlightMessagesList(maxRetryCount, pollingInterval).then(() => { | |
done(); | |
}).catch(done); | |
}); | |
function checkInFlightMessagesList(maxRetryCount, pollingInterval) { | |
let totalInFlightMessagesList; | |
console.log(`Retries remaining = ${maxRetryCount}`); | |
return apiBaseUri.get(subscriptionsEndpoint) | |
.auth('eventStoreUsername', 'eventStorePassword') | |
.set('Accept', 'application/json') | |
.expect('Content-Type', /json/) | |
.expect(200) | |
.then(apiResponse => { | |
totalInFlightMessagesList = JSON.parse(apiResponse.text) | |
.map(item => item.totalInFlightMessages); | |
console.log(`Event Store ${subscriptionsEndpoint} API response: ${apiResponse.text}`); | |
for (let index = 0; index < totalInFlightMessagesList.length; index++) { | |
let totalInFlightMessages = totalInFlightMessagesList[index]; | |
if (totalInFlightMessages > 0 && maxRetryCount > 0) { | |
console.log(`Waiting for ${pollingInterval} ms`); | |
return new Promise(resolve => setTimeout(resolve, pollingInterval)) | |
.then(() => checkInFlightMessagesList(maxRetryCount - 1, pollingInterval)); | |
} else if (index === totalInFlightMessagesList.length - 1 && maxRetryCount > 0) { | |
console.log("No events are present in the in-flight queue."); | |
} else if (maxRetryCount === 0) { | |
assert.fail('Max retries exceeded; one or more events are present in the in-flight queue!'); | |
} | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment