@@ -68,24 +68,6 @@ void create_schema(const AppSession& app_session, Schema target_schema, int64_t
68
68
});
69
69
}
70
70
71
- std::pair<SharedRealm, std::exception_ptr> async_open_realm (const Realm::Config& config)
72
- {
73
- auto task = Realm::get_synchronized_realm (config);
74
- ThreadSafeReference tsr;
75
- SharedRealm realm;
76
- std::exception_ptr err = nullptr ;
77
- auto pf = util::make_promise_future<void >();
78
- task->start ([&tsr, &err, promise = util::CopyablePromiseHolder (std::move (pf.promise ))](
79
- ThreadSafeReference&& ref, std::exception_ptr e) mutable {
80
- tsr = std::move (ref);
81
- err = e;
82
- promise.get_promise ().emplace_value ();
83
- });
84
- pf.future .get ();
85
- realm = err ? nullptr : Realm::get_shared_realm (std::move (tsr));
86
- return std::pair (realm, err);
87
- }
88
-
89
71
std::vector<ObjectSchema> get_schema_v0 ()
90
72
{
91
73
return {
@@ -373,20 +355,17 @@ TEST_CASE("Cannot migrate schema to unknown version", "[sync][flx][flx schema mi
373
355
config.sync_config ->error_handler = err_handler;
374
356
375
357
{
376
- auto [realm, error] = async_open_realm (config);
377
- REQUIRE_FALSE (realm);
378
- REQUIRE (error);
379
- REQUIRE_THROWS_CONTAINING (std::rethrow_exception (error), " Client provided invalid schema version" );
358
+ auto status = async_open_realm (config);
359
+ REQUIRE_FALSE (status.is_ok ());
360
+ REQUIRE_THAT (status.get_status ().reason (), Catch::Matchers::ContainsSubstring (" Client provided invalid schema version" ));
380
361
error_future.get ();
381
362
check_realm_schema (config.path , target_schema, target_schema_version);
382
363
}
383
364
384
365
// Update schema version to 0 and try again (the version now matches the actual schema).
385
366
config.schema_version = 0 ;
386
367
config.sync_config ->error_handler = nullptr ;
387
- auto [realm, error] = async_open_realm (config);
388
- REQUIRE (realm);
389
- REQUIRE_FALSE (error);
368
+ REQUIRE (async_open_realm (config).is_ok ());
390
369
check_realm_schema (config.path , schema_v0, 0 );
391
370
}
392
371
@@ -443,11 +422,9 @@ TEST_CASE("Schema version mismatch between client and server", "[sync][flx][flx
443
422
return SyncClientHookAction::NoAction;
444
423
};
445
424
446
- auto [realm, error] = async_open_realm (config);
447
- REQUIRE_FALSE (realm);
448
- REQUIRE (error);
449
- REQUIRE_THROWS_CONTAINING (std::rethrow_exception (error),
450
- " The following changes cannot be made in additive-only schema mode" );
425
+ auto status = async_open_realm (config);
426
+ REQUIRE_FALSE (status.is_ok ());
427
+ REQUIRE_THAT (status.get_status ().reason (), Catch::Matchers::ContainsSubstring (" The following changes cannot be made in additive-only schema mode" ));
451
428
REQUIRE (schema_migration_required);
452
429
// Applying the new schema (and version) fails, therefore the schema is unversioned (the metadata table is removed
453
430
// during migration). There is a schema though because the server schema is already applied by the time the client
@@ -479,9 +456,7 @@ TEST_CASE("Fresh realm does not require schema migration", "[sync][flx][flx sche
479
456
return SyncClientHookAction::NoAction;
480
457
};
481
458
482
- auto [realm, error] = async_open_realm (config);
483
- REQUIRE (realm);
484
- REQUIRE_FALSE (error);
459
+ REQUIRE (async_open_realm (config).is_ok ());
485
460
check_realm_schema (config.path , schema_v1, 1 );
486
461
}
487
462
@@ -564,9 +539,7 @@ TEST_CASE("Upgrade schema version (with recovery) then downgrade", "[sync][flx][
564
539
config.schema_version = 1 ;
565
540
config.schema = schema_v1;
566
541
config.sync_config ->subscription_initializer = get_subscription_initializer_callback_for_schema_v1 ();
567
- auto [realm, error] = async_open_realm (config);
568
- REQUIRE (realm);
569
- REQUIRE_FALSE (error);
542
+ auto realm = successfully_async_open_realm (config);
570
543
check_realm_schema (config.path , schema_v1, 1 );
571
544
572
545
auto table = realm->read_group ().get_table (" class_TopLevel" );
@@ -596,9 +569,7 @@ TEST_CASE("Upgrade schema version (with recovery) then downgrade", "[sync][flx][
596
569
config.schema = schema_v2;
597
570
config.sync_config ->subscription_initializer = get_subscription_initializer_callback_for_schema_v2 ();
598
571
599
- auto [realm, error] = async_open_realm (config);
600
- REQUIRE (realm);
601
- REQUIRE_FALSE (error);
572
+ auto realm = successfully_async_open_realm (config);
602
573
check_realm_schema (config.path , schema_v2, 2 );
603
574
604
575
auto table = realm->read_group ().get_table (" class_TopLevel" );
@@ -616,9 +587,7 @@ TEST_CASE("Upgrade schema version (with recovery) then downgrade", "[sync][flx][
616
587
config.schema = schema_v1;
617
588
config.sync_config ->subscription_initializer = get_subscription_initializer_callback_for_schema_v1 ();
618
589
619
- auto [realm, error] = async_open_realm (config);
620
- REQUIRE (realm);
621
- REQUIRE_FALSE (error);
590
+ auto realm = successfully_async_open_realm (config);
622
591
check_realm_schema (config.path , schema_v1, 1 );
623
592
624
593
auto table = realm->read_group ().get_table (" class_TopLevel" );
@@ -636,9 +605,7 @@ TEST_CASE("Upgrade schema version (with recovery) then downgrade", "[sync][flx][
636
605
config.schema = schema_v0;
637
606
config.sync_config ->subscription_initializer = get_subscription_initializer_callback_for_schema_v0 ();
638
607
639
- auto [realm, error] = async_open_realm (config);
640
- REQUIRE (realm);
641
- REQUIRE_FALSE (error);
608
+ auto realm = successfully_async_open_realm (config);
642
609
check_realm_schema (config.path , schema_v0, 0 );
643
610
644
611
auto table = realm->read_group ().get_table (" class_TopLevel" );
@@ -720,9 +687,7 @@ TEST_CASE("An interrupted schema migration can recover on the next session",
720
687
}
721
688
722
689
// Retry the migration.
723
- auto [realm, error] = async_open_realm (config);
724
- REQUIRE (realm);
725
- REQUIRE_FALSE (error);
690
+ REQUIRE (async_open_realm (config).is_ok ());
726
691
REQUIRE (schema_version_changed_count == 2 );
727
692
check_realm_schema (config.path , schema_v1, 1 );
728
693
}
@@ -752,9 +717,7 @@ TEST_CASE("Migrate to new schema version with a schema subset", "[sync][flx][flx
752
717
config.schema = schema_subset;
753
718
config.sync_config ->subscription_initializer = get_subscription_initializer_callback_for_schema_v1 ();
754
719
755
- auto [realm, error] = async_open_realm (config);
756
- REQUIRE (realm);
757
- REQUIRE_FALSE (error);
720
+ REQUIRE (async_open_realm (config).is_ok ());
758
721
check_realm_schema (config.path , schema_v1, 1 );
759
722
}
760
723
@@ -835,9 +798,7 @@ TEST_CASE("Client reset during schema migration", "[sync][flx][flx schema migrat
835
798
++after_reset_count;
836
799
};
837
800
838
- auto [realm, error] = async_open_realm (config);
839
- REQUIRE (realm);
840
- REQUIRE_FALSE (error);
801
+ auto realm = successfully_async_open_realm (config);
841
802
REQUIRE (before_reset_count == 0 );
842
803
REQUIRE (after_reset_count == 0 );
843
804
check_realm_schema (config.path , schema_v1, 1 );
@@ -926,9 +887,7 @@ TEST_CASE("Migrate to new schema version after migration to intermediate version
926
887
config.schema_version = 2 ;
927
888
config.schema = schema_v2;
928
889
config.sync_config ->subscription_initializer = get_subscription_initializer_callback_for_schema_v2 ();
929
- auto [realm, error] = async_open_realm (config);
930
- REQUIRE (realm);
931
- REQUIRE_FALSE (error);
890
+ auto realm = successfully_async_open_realm (config);
932
891
REQUIRE (schema_version_changed_count == 2 );
933
892
check_realm_schema (config.path , schema_v2, 2 );
934
893
@@ -951,9 +910,7 @@ TEST_CASE("Send schema version zero if no schema is used to open the realm",
951
910
952
911
config.schema = {};
953
912
config.schema_version = -1 ; // override the schema version set by SyncTestFile constructor
954
- auto [realm, error] = async_open_realm (config);
955
- REQUIRE (realm);
956
- REQUIRE_FALSE (error);
913
+ REQUIRE (async_open_realm (config).is_ok ());
957
914
// The schema is received from the server, but it is unversioned.
958
915
check_realm_schema (config.path , schema_v0, ObjectStore::NotVersioned);
959
916
}
@@ -1061,9 +1018,7 @@ TEST_CASE("Client reset and schema migration", "[sync][flx][flx schema migration
1061
1018
++after_reset_count;
1062
1019
};
1063
1020
1064
- auto [realm, error] = async_open_realm (config);
1065
- REQUIRE (realm);
1066
- REQUIRE_FALSE (error);
1021
+ auto realm = successfully_async_open_realm (config);
1067
1022
REQUIRE (before_reset_count == 0 );
1068
1023
REQUIRE (after_reset_count == 0 );
1069
1024
check_realm_schema (config.path , schema_v1, 1 );
@@ -1204,9 +1159,7 @@ TEST_CASE("Upgrade schema version with no subscription initializer", "[sync][flx
1204
1159
config.schema_version = 1 ;
1205
1160
config.schema = schema_v1;
1206
1161
config.sync_config ->subscription_initializer = nullptr ;
1207
- auto [realm, error] = async_open_realm (config);
1208
- REQUIRE (realm);
1209
- REQUIRE_FALSE (error);
1162
+ auto realm = successfully_async_open_realm (config);
1210
1163
check_realm_schema (config.path , schema_v1, 1 );
1211
1164
1212
1165
auto table = realm->read_group ().get_table (" class_TopLevel" );
0 commit comments