amazon-archives / amazon-cognito-js

Amazon Cognito Sync Manager for JavaScript
http://aws.amazon.com/cognito
Apache License 2.0
202 stars 83 forks source link

Synchronize function does not works everytime. #67

Open stripathix opened 6 years ago

stripathix commented 6 years ago

Test Case:

Step 1) In chrome, I update the record of dataset then do synchronize() which gives Success Step 2) Go to firefox and synchronize() there also Success is called.

Now in firefox I have the latest record that was updated in step (1).

On repeating the above steps multiple time, step(2) stops getting latest record updated in step (1) even when onSuccess is still called for firefox step(2).

Note: To resolve conflict I use deviceLastModifiedDate. Whichever is latest I use that.

` bnUserPreferencesDataset.synchronize({onSuccess: function () {

                contents.fillDatasetMap();
            }, onConflict: function (dataset, conflicts, callback) {
                var resolved = [];
                var i = 0;
                while (i < conflicts.length) {
                    if (conflicts[i].localRecord.deviceLastModifiedDate > conflicts[i].remoteRecord.deviceLastModifiedDate) {
                        resolved.push(conflicts[i].resolveWithLocalRecord());
                    } else {
                        resolved.push(conflicts[i].resolveWithRemoteRecord());
                    }
                    i += 1;
                }
                if (resolved.length) {
                    dataset.resolve(resolved, function (err) {
                        if (err) {
                            return callback(false);
                        }
                        return callback(true);
                    });
                }
            }, onFailure: function (err) {
                console.log(err);
            }});`
stripathix commented 6 years ago

I have a record name favoriteView and I believe if I change the value of this record in chrome then on doing synchronize() in firefox I should get conflict because value of favoriteView in Firefox is different. But this does not happen always. Sometimes it works but after 3-4 attempts sync always calls onSuccess and keeps getting old records.

I have to refresh to get the latest records.