Use an uncached realm instance for _waitForDownload (#1083)

Fixes #1061
This commit is contained in:
Yavor Georgiev 2017-06-19 13:58:19 +02:00 committed by GitHub
parent acd962d602
commit 28fe678a1b
2 changed files with 33 additions and 29 deletions

View File

@ -550,6 +550,7 @@ void RealmClass<T>::wait_for_download_completion(ContextType ctx, FunctionType,
ValueType sync_config_value = Object::get_property(ctx, config_object, "sync"); ValueType sync_config_value = Object::get_property(ctx, config_object, "sync");
if (!Value::is_undefined(ctx, sync_config_value)) { if (!Value::is_undefined(ctx, sync_config_value)) {
realm::Realm::Config config; realm::Realm::Config config;
config.cache = false;
static const String encryption_key_string = "encryptionKey"; static const String encryption_key_string = "encryptionKey";
ValueType encryption_key_value = Object::get_property(ctx, config_object, encryption_key_string); ValueType encryption_key_value = Object::get_property(ctx, config_object, encryption_key_string);
if (!Value::is_undefined(ctx, encryption_key_value)) { if (!Value::is_undefined(ctx, encryption_key_value)) {
@ -590,7 +591,7 @@ void RealmClass<T>::wait_for_download_completion(ContextType ctx, FunctionType,
if (user && user->state() != SyncUser::State::Error) { if (user && user->state() != SyncUser::State::Error) {
if (auto session = user->session_for_on_disk_path(config.path)) { if (auto session = user->session_for_on_disk_path(config.path)) {
session->wait_for_download_completion([=](std::error_code error_code) { session->wait_for_download_completion([=](std::error_code error_code) {
realm->config(); //capture and keep realm instance for till here realm->close(); //capture and keep realm instance for till here
waitFunc(error_code); waitFunc(error_code);
}); });
return; return;

View File

@ -147,29 +147,26 @@ module.exports = {
}) })
.then(() => { .then(() => {
return promisifiedLogin('http://localhost:9080', username, 'password').then(user => { return promisifiedLogin('http://localhost:9080', username, 'password').then(user => {
return new Promise((resolve, reject) => { const accessTokenRefreshed = this;
const accessTokenRefreshed = this; let successCounter = 0;
let successCounter = 0;
let config = { let config = {
sync: { user, url: `realm://localhost:9080/~/${realmName}` }, sync: { user, url: `realm://localhost:9080/~/${realmName}` },
schema: [{ name: 'Dog', properties: { name: 'string' } }], schema: [{ name: 'Dog', properties: { name: 'string' } }],
}; };
Realm.open(config) return Realm.open(config)
.then(realm => { .then(realm => {
let actualObjectsCount = realm.objects('Dog').length; let actualObjectsCount = realm.objects('Dog').length;
TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Synced realm does not contain the expected objects count"); TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Synced realm does not contain the expected objects count");
return realm.syncSession;
const session = realm.syncSession; }).then(session => {
TestCase.assertInstanceOf(session, Realm.Sync.Session); TestCase.assertInstanceOf(session, Realm.Sync.Session);
TestCase.assertEqual(session.user.identity, user.identity); TestCase.assertEqual(session.user.identity, user.identity);
TestCase.assertEqual(session.config.url, config.sync.url); TestCase.assertEqual(session.config.url, config.sync.url);
TestCase.assertEqual(session.config.user.identity, config.sync.user.identity); TestCase.assertEqual(session.config.user.identity, config.sync.user.identity);
TestCase.assertEqual(session.state, 'active'); TestCase.assertEqual(session.state, 'active');
resolve(); });
}).catch(e => { reject(e) });
});
}); });
}); });
}, },
@ -217,13 +214,19 @@ module.exports = {
let actualObjectsCount = realm.objects('Dog').length; let actualObjectsCount = realm.objects('Dog').length;
TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Synced realm does not contain the expected objects count"); TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Synced realm does not contain the expected objects count");
const session = realm.syncSession; setTimeout(() => {
TestCase.assertInstanceOf(session, Realm.Sync.Session); try {
TestCase.assertEqual(session.user.identity, user.identity); const session = realm.syncSession;
TestCase.assertEqual(session.config.url, config.sync.url); TestCase.assertInstanceOf(session, Realm.Sync.Session);
TestCase.assertEqual(session.config.user.identity, config.sync.user.identity); TestCase.assertEqual(session.user.identity, user.identity);
TestCase.assertEqual(session.state, 'active'); TestCase.assertEqual(session.config.url, config.sync.url);
resolve(); TestCase.assertEqual(session.config.user.identity, config.sync.user.identity);
TestCase.assertEqual(session.state, 'active');
resolve();
} catch (e) {
reject(e);
}
}, 50);
} }
catch (e) { catch (e) {
reject(e); reject(e);