From 95da4d81c31a7877c9e9aaa4511fd88452f168da Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Tue, 4 Apr 2017 14:00:00 +0200 Subject: [PATCH 1/6] refactor session tests --- tests/js/session-tests.js | 40 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/tests/js/session-tests.js b/tests/js/session-tests.js index aa926053..84b8be99 100644 --- a/tests/js/session-tests.js +++ b/tests/js/session-tests.js @@ -42,10 +42,6 @@ function promisifiedRegister(server, username, password) { }); } -function wait(delay) { - return new Promise((resolve, reject) => setTimeout(resolve, delay)); -} - module.exports = { testLocalRealmHasNoSession() { let realm = new Realm(); @@ -55,12 +51,11 @@ module.exports = { testProperties() { return promisifiedRegister('http://localhost:9080', uuid(), 'password').then(user => { return new Promise((resolve, _reject) => { - const accessTokenRefreshed = Symbol(); - let session; + const accessTokenRefreshed = this; - let postTokenRefreshChecks = (sender, error) => { + function postTokenRefreshChecks(sender, error) { TestCase.assertEqual(error, accessTokenRefreshed); - TestCase.assertEqual(session.url, `realm://localhost:9080/${user.identity}/myrealm`); + TestCase.assertEqual(sender.url, `realm://localhost:9080/${user.identity}/myrealm`); resolve(); }; @@ -69,7 +64,7 @@ module.exports = { const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm', error: postTokenRefreshChecks } }; const realm = new Realm(config); - session = realm.syncSession; + const session = realm.syncSession; TestCase.assertInstanceOf(session, Realm.Sync.Session); TestCase.assertEqual(session.user.identity, user.identity); @@ -83,22 +78,19 @@ module.exports = { testErrorHandling() { return promisifiedRegister('http://localhost:9080', uuid(), 'password').then(user => { - let errors = []; - let config = { sync: { user, - url: 'realm://localhost:9080/~/myrealm', - error: (sender, error) => errors.push([sender, error]) - } }; - let realm = new Realm(config); - let session = realm.syncSession; + return new Promise((resolve) => { + const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } }; + config.sync.error = (sender, error) => { + TestCase.assertEqual(sender.config.url, config.sync.url); + TestCase.assertEqual(error.message, 'simulated error'); + TestCase.assertEqual(error.code, 123); + resolve(); + }; + const realm = new Realm(config); + const session = realm.syncSession; - TestCase.assertEqual(session.config.error, config.sync.error); - session._simulateError(123, 'simulated error'); - - return wait(2000).then(() => { - TestCase.assertArrayLength(errors, 1); - TestCase.assertEqual(errors[0][0].config.url, session.config.url); - TestCase.assertEqual(errors[0][1].message, 'simulated error'); - TestCase.assertEqual(errors[0][1].code, 123); + TestCase.assertEqual(session.config.error, config.sync.error); + session._simulateError(123, 'simulated error'); }); }); } From a37c38ca92ccaf99c090b5ffbec3ad76416aa2a7 Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Tue, 4 Apr 2017 14:00:20 +0200 Subject: [PATCH 2/6] increase jasmine timeout to a ridiculously high value --- tests/spec/unit_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/spec/unit_tests.js b/tests/spec/unit_tests.js index 50f96172..d84d349c 100644 --- a/tests/spec/unit_tests.js +++ b/tests/spec/unit_tests.js @@ -27,7 +27,7 @@ const path = require('path'); const Realm = require('realm'); const RealmTests = require('../js'); -jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; +jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; // Create this method with appropriate implementation for Node testing. Realm.copyBundledRealmFiles = function() { From 9a8dc1327f392a3f804972b058ba009b79b65e5c Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Tue, 4 Apr 2017 15:26:54 +0200 Subject: [PATCH 3/6] remove assertion --- tests/js/session-tests.js | 1 - tests/spec/unit_tests.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/js/session-tests.js b/tests/js/session-tests.js index 84b8be99..1aa81372 100644 --- a/tests/js/session-tests.js +++ b/tests/js/session-tests.js @@ -81,7 +81,6 @@ module.exports = { return new Promise((resolve) => { const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } }; config.sync.error = (sender, error) => { - TestCase.assertEqual(sender.config.url, config.sync.url); TestCase.assertEqual(error.message, 'simulated error'); TestCase.assertEqual(error.code, 123); resolve(); diff --git a/tests/spec/unit_tests.js b/tests/spec/unit_tests.js index d84d349c..50f96172 100644 --- a/tests/spec/unit_tests.js +++ b/tests/spec/unit_tests.js @@ -27,7 +27,7 @@ const path = require('path'); const Realm = require('realm'); const RealmTests = require('../js'); -jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; +jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; // Create this method with appropriate implementation for Node testing. Realm.copyBundledRealmFiles = function() { From 7543c1274d842d92693a466376d6647580793b57 Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Tue, 4 Apr 2017 16:13:07 +0200 Subject: [PATCH 4/6] increase jasmine timeout to a ridiculously high value --- tests/spec/unit_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/spec/unit_tests.js b/tests/spec/unit_tests.js index 50f96172..d84d349c 100644 --- a/tests/spec/unit_tests.js +++ b/tests/spec/unit_tests.js @@ -27,7 +27,7 @@ const path = require('path'); const Realm = require('realm'); const RealmTests = require('../js'); -jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; +jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; // Create this method with appropriate implementation for Node testing. Realm.copyBundledRealmFiles = function() { From c959cc799c0e4db9301be84a458ecbe6ae2bb298 Mon Sep 17 00:00:00 2001 From: blagoev Date: Thu, 20 Apr 2017 17:02:18 +0300 Subject: [PATCH 5/6] possible fix to session tests timeout --- tests/js/session-tests.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tests/js/session-tests.js b/tests/js/session-tests.js index 1aa81372..d816a86a 100644 --- a/tests/js/session-tests.js +++ b/tests/js/session-tests.js @@ -54,9 +54,14 @@ module.exports = { const accessTokenRefreshed = this; function postTokenRefreshChecks(sender, error) { - TestCase.assertEqual(error, accessTokenRefreshed); - TestCase.assertEqual(sender.url, `realm://localhost:9080/${user.identity}/myrealm`); - resolve(); + try { + TestCase.assertEqual(error, accessTokenRefreshed); + TestCase.assertEqual(sender.url, `realm://localhost:9080/${user.identity}/myrealm`); + resolve(); + } + catch (e) { + _reject(e) + } }; // Let the error handler trigger our checks when the access token was refreshed. @@ -66,6 +71,7 @@ module.exports = { const realm = new Realm(config); const session = realm.syncSession; + TestCase.assertInstanceOf(session, Realm.Sync.Session); TestCase.assertEqual(session.user.identity, user.identity); TestCase.assertEqual(session.config.url, config.sync.url); @@ -73,17 +79,22 @@ module.exports = { TestCase.assertUndefined(session.url); TestCase.assertEqual(session.state, 'active'); }); - }); + }) }, testErrorHandling() { return promisifiedRegister('http://localhost:9080', uuid(), 'password').then(user => { - return new Promise((resolve) => { + return new Promise((resolve, _reject) => { const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } }; config.sync.error = (sender, error) => { - TestCase.assertEqual(error.message, 'simulated error'); - TestCase.assertEqual(error.code, 123); - resolve(); + try { + TestCase.assertEqual(error.message, 'simulated error'); + TestCase.assertEqual(error.code, 123); + resolve(); + } + catch (e) { + _reject(e); + } }; const realm = new Realm(config); const session = realm.syncSession; From db8eb39b8600507c3e5ae3074b156ca8febc9d39 Mon Sep 17 00:00:00 2001 From: blagoev Date: Thu, 20 Apr 2017 17:03:15 +0300 Subject: [PATCH 6/6] add semicolon --- tests/js/session-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/js/session-tests.js b/tests/js/session-tests.js index d816a86a..c0f88575 100644 --- a/tests/js/session-tests.js +++ b/tests/js/session-tests.js @@ -79,7 +79,7 @@ module.exports = { TestCase.assertUndefined(session.url); TestCase.assertEqual(session.state, 'active'); }); - }) + }); }, testErrorHandling() {