Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Test case when exchange rates APIs are unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
chill117 committed Aug 21, 2018
1 parent 3adcea7 commit 20528ef
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 24 deletions.
1 change: 0 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var config = module.exports = {
debug: true,
host: process.env.CT_API_SERVER_HOST || 'localhost',
port: parseInt(process.env.CT_API_SERVER_PORT || 3600),
supportedDisplayCurrencies: [
Expand Down
4 changes: 4 additions & 0 deletions services/coinbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ module.exports = function(app) {
return cb(error);
}

if (response.statusCode >= 400) {
return cb(new Error('Failed to get exchange rates from coinbase (HTTP ' + response.statusCode + ')'))
}

try {
data = JSON.parse(data);
} catch (error) {
Expand Down
24 changes: 18 additions & 6 deletions sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,32 @@ module.exports = function(app) {
})();
};

var exchangeRatesPollingTimeout, doPollingExchangeRates;
var startPollingExchangeRates = function() {
doPollingExchangeRates = true;
(function getExchangeRates() {
if (!doPollingExchangeRates) return;
app.providers.exchangeRates(function(error, data) {
var delay;
if (error) {
app.error(error);
return _.delay(getExchangeRates, app.config.exchangeRates.polling.retryDelayOnError);
app.log(error);
delay = app.config.exchangeRates.polling.retryDelayOnError;
} else {
var channel = 'exchange-rates';
cache[channel] = data;
broadcastToChannel(channel, data);
delay = app.config.exchangeRates.polling.frequency;
}
var channel = 'exchange-rates';
cache[channel] = data;
broadcastToChannel(channel, data);
_.delay(getExchangeRates, app.config.exchangeRates.polling.frequency);
exchangeRatesPollingTimeout = _.delay(getExchangeRates, delay);
});
})();
};

var stopPollingExchangeRates = function() {
doPollingExchangeRates = false;
clearTimeout(exchangeRatesPollingTimeout);
};

var getPaymentMethodStatuses = function() {
var service = app.services.bitcoindZeroMQ;
var networks = _.keys(app.lib.BitcoindZeroMQ.prototype.networks);
Expand Down Expand Up @@ -311,6 +322,7 @@ module.exports = function(app) {
primus: primus,
savePrimusClientLibraryToFile: savePrimusClientLibraryToFile,
startPollingExchangeRates: startPollingExchangeRates,
stopPollingExchangeRates: stopPollingExchangeRates,
startPollingMoneroTxs: startPollingMoneroTxs,
startProvidingStatus: startProvidingStatus,
};
Expand Down
Loading

0 comments on commit 20528ef

Please sign in to comment.