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

Commit

Permalink
Minor comments and issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki committed Aug 31, 2017
1 parent 4d9e86e commit 21d84bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
18 changes: 8 additions & 10 deletions client/datasync-client/src/DataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class DataManager {
*
* @returns Promise (bluebird)
*/
public list(): Bluebird<any> {
public list(): Bluebird<any[]> {
const self = this;
return new Bluebird(function(resolve, reject) {
syncApi.doList(self.datasetId, function(syncDataSetList: any) {
Expand Down Expand Up @@ -164,36 +164,34 @@ export class DataManager {
/**
* A utility function to push any updates to the remote server and then stop syncing.
* If there are pending sync operations, then force them to sync and then stop syncing.
* Method can be used to ensure that all changes were saved to server before logout.
*
* @param userOptions - object that can contain delay
* @returns {*}
*/
public safeStop = function(userOptions) {
const self = this;
// Amount of time to wait before attempting stop.
const defaultOptions = {
delay: 5000
};

const options = _.defaults(userOptions, defaultOptions);

function forceSyncThenStop(pendingUpdateQueueSize) {
if (pendingUpdateQueueSize === 0) {
self.stop().then(Bluebird.resolve);
return;
}
// Steps: force sync, wait, check if results were synced back, stop server
return self.forceSync()
.delay(options.delay)
.then(self.getQueueSize.bind(self))
.then(function(size) {
if (size > 0) {
Bluebird.reject(new Error('forceSync failed, outstanding results still present'));
return Bluebird.reject(new Error('forceSync failed, outstanding results still present'));
}
})
.then(self.stop.bind(self))
.then(function() {
Bluebird.resolve();
}, function() {
Bluebird.reject(new Error('forceSync error'));
});
.then(self.stop.bind(self));
}
return self.getQueueSize().then(forceSyncThenStop);
};
Expand All @@ -219,7 +217,7 @@ export class DataManager {
const self = this;
return new Bluebird(function(resolve) {
syncApi.getPending(self.datasetId, function(pending?) {
resolve(_.size(pending));
return resolve(_.size(pending));
});
});
};
Expand Down
5 changes: 3 additions & 2 deletions client/datasync-client/test/DataManagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ describe('Data Manager', function() {

it('should safeStop', function() {
const mockRecordUid = 'syncRecordUID';
const results = [{}, {}];
const results = [];
const mock$fh = {
getPending: sinon.stub().callsArgWith(1, results),
forceSync: sinon.stub().callsArgWith(1),
getPending: sinon.stub().callsArgWith(1, results)
};

const DataManager = proxyquire.noCallThru().load('../src/DataManager', {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "lerna run test",
"test-ci": "npm-run-all test coverage:* && npm run publish:test",
"test-ci": "npm-run-all test coverage:*",
"coverage:create-file": "echo '' > ./coverage_report/coverage_merged.info",
"coverage:merge-reports": "lcov-result-merger './coverage_report/*/lcov.info' './coverage_report/coverage_merged.info'",
"coverage:upload-coveralls": "cat ./coverage_report/coverage_merged.info | coveralls",
Expand Down

0 comments on commit 21d84bc

Please sign in to comment.