Change fragile test to wait for signal rather than for a period of time (#936)

* Change test to wait for signal rather than for 4 seconds

* Tiny refactoring
This commit is contained in:
Kristian Dupont 2017-03-24 12:49:28 +01:00 committed by GitHub
parent 479b21c3f8
commit 045b963d6f
2 changed files with 25 additions and 17 deletions

View File

@ -82,8 +82,8 @@ function refreshAccessToken(user, localRealmPath, realmUrl) {
if (newUser) {
let session = newUser._sessionForOnDiskPath(localRealmPath);
if (session) {
const errorHandler = session.config.error;
if (response.status != 200) {
let errorHandler = session.config.error;
let error = new AuthError(json);
if (errorHandler) {
errorHandler(session, error);
@ -94,6 +94,10 @@ function refreshAccessToken(user, localRealmPath, realmUrl) {
parsedRealmUrl.set('pathname', json.access_token.token_data.path);
session._refreshAccessToken(json.access_token.token, parsedRealmUrl.href);
if (errorHandler && errorHandler._notifyOnAccessTokenRefreshed) {
errorHandler(session, errorHandler._notifyOnAccessTokenRefreshed)
}
const tokenExpirationDate = new Date(json.access_token.token_data.expires * 1000);
scheduleAccessTokenRefresh(newUser, localRealmPath, realmUrl, tokenExpirationDate);
}

View File

@ -54,26 +54,30 @@ module.exports = {
testProperties() {
return promisifiedRegister('http://localhost:9080', uuid(), 'password').then(user => {
let config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } };
let realm = new Realm(config);
let session = realm.syncSession;
return new Promise((resolve, _reject) => {
const accessTokenRefreshed = Symbol();
let session;
TestCase.assertInstanceOf(session, Realm.Sync.Session);
TestCase.assertEqual(session.user.identity, user.identity);
TestCase.assertEqual(session.config.url, config.sync.url);
TestCase.assertEqual(session.config.user.identity, config.sync.user.identity);
TestCase.assertUndefined(session.url);
TestCase.assertEqual(session.state, 'active');
let postTokenRefreshChecks = (sender, error) => {
TestCase.assertEqual(error, accessTokenRefreshed);
TestCase.assertEqual(session.url, `realm://localhost:9080/${user.identity}/myrealm`);
resolve();
};
/* disable until the sporadic failures are resolved
// give the session enough time to refresh its access token and bind itself
// TODO: Use an event to discover when the session is bound
let timeout = 4000;
// Let the error handler trigger our checks when the access token was refreshed.
postTokenRefreshChecks._notifyOnAccessTokenRefreshed = accessTokenRefreshed;
return wait(timeout).then(() => {
TestCase.assertEqual(session.url, `realm://localhost:9080/${user.identity}/myrealm`);
const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm', error: postTokenRefreshChecks } };
const realm = new Realm(config);
session = realm.syncSession;
TestCase.assertInstanceOf(session, Realm.Sync.Session);
TestCase.assertEqual(session.user.identity, user.identity);
TestCase.assertEqual(session.config.url, config.sync.url);
TestCase.assertEqual(session.config.user.identity, config.sync.user.identity);
TestCase.assertUndefined(session.url);
TestCase.assertEqual(session.state, 'active');
});
*/
});
},