allow running all tests at the same path by invalidating all cached realm paths between test runs
This commit is contained in:
parent
4cfa8eae7b
commit
aa035717a5
|
@ -860,6 +860,11 @@
|
|||
INFOPLIST_FILE = tests/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
OTHER_CPLUSPLUSFLAGS = (
|
||||
"$(OTHER_CFLAGS)",
|
||||
"-isystem",
|
||||
core/include,
|
||||
);
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
|
@ -875,6 +880,11 @@
|
|||
INFOPLIST_FILE = tests/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
OTHER_CPLUSPLUSFLAGS = (
|
||||
"$(OTHER_CFLAGS)",
|
||||
"-isystem",
|
||||
core/include,
|
||||
);
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
|
@ -982,6 +992,11 @@
|
|||
INFOPLIST_FILE = tests/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
OTHER_CPLUSPLUSFLAGS = (
|
||||
"$(OTHER_CFLAGS)",
|
||||
"-isystem",
|
||||
core/include,
|
||||
);
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = GCov_Build;
|
||||
|
|
|
@ -198,7 +198,9 @@ bool Realm::update_schema(std::unique_ptr<Schema> schema, uint64_t version)
|
|||
auto migration_function = [&](Group*, Schema&) {
|
||||
SharedRealm old_realm(new Realm(old_config));
|
||||
auto updated_realm = shared_from_this();
|
||||
m_config.migration_function(old_realm, updated_realm);
|
||||
if (m_config.migration_function) {
|
||||
m_config.migration_function(old_realm, updated_realm);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
|
@ -438,6 +440,19 @@ void RealmCache::cache_realm(SharedRealm &realm, std::thread::id thread_id)
|
|||
}
|
||||
}
|
||||
|
||||
void RealmCache::invalidate_all()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
for (auto &path_realms:m_cache) {
|
||||
for (auto &realm_iter:path_realms.second) {
|
||||
if (auto realm = realm_iter.second.lock()) {
|
||||
realm->invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RealmCache::clear()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
|
|
@ -131,6 +131,7 @@ namespace realm {
|
|||
SharedRealm get_any_realm(const std::string &path);
|
||||
void remove(const std::string &path, std::thread::id thread_id);
|
||||
void cache_realm(SharedRealm &realm, std::thread::id thread_id = std::this_thread::get_id());
|
||||
void invalidate_all();
|
||||
void clear();
|
||||
|
||||
private:
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#import "RJSUtil.hpp"
|
||||
#import "RJSRealm.hpp"
|
||||
|
||||
#import "shared_realm.hpp"
|
||||
|
||||
NSString *RealmPathForFile(NSString *fileName) {
|
||||
#if TARGET_OS_IPHONE
|
||||
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
||||
|
@ -30,10 +32,9 @@ NSString *RealmPathForFile(NSString *fileName) {
|
|||
return [path stringByAppendingPathComponent:fileName];
|
||||
}
|
||||
|
||||
static NSString *s_testPrefix;
|
||||
|
||||
NSString *TestRealmPath() {
|
||||
return RealmPathForFile([s_testPrefix stringByAppendingPathComponent:@"test.realm"]);
|
||||
return RealmPathForFile(@"test.realm");
|
||||
}
|
||||
|
||||
static void DeleteOrThrow(NSString *path) {
|
||||
|
@ -72,10 +73,8 @@ static JSClassRef s_globalClass;
|
|||
- (void)setUp {
|
||||
[super setUp];
|
||||
|
||||
s_testPrefix = [[NSUUID UUID] UUIDString];
|
||||
NSString *defaultDir = RealmPathForFile(s_testPrefix);
|
||||
NSString *defaultDir = [[NSString stringWithUTF8String:RJSDefaultPath().c_str()] stringByDeletingLastPathComponent];
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:defaultDir withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
RJSSetDefaultPath([defaultDir stringByAppendingPathComponent:@"default.realm"].UTF8String);
|
||||
|
||||
JSGlobalContextRef ctx = JSGlobalContextCreateInGroup(NULL, s_globalClass);
|
||||
self.context = [JSContext contextWithJSGlobalContextRef:ctx];
|
||||
|
@ -90,9 +89,12 @@ static JSClassRef s_globalClass;
|
|||
- (void)tearDown {
|
||||
self.context = nil;
|
||||
|
||||
realm::Realm::s_global_cache.invalidate_all();
|
||||
realm::Realm::s_global_cache.clear();
|
||||
|
||||
DeleteRealmFilesAtPath(TestRealmPath());
|
||||
DeleteRealmFilesAtPath(@(RJSDefaultPath().c_str()));
|
||||
|
||||
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue