Skip to content

Commit

Permalink
Add Mode to tests for Mac (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb authored Feb 1, 2021
1 parent f3a9030 commit 0bcc3a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class AddressIndexerOutpointsRepositoryTests

public AddressIndexerOutpointsRepositoryTests()
{
var db = new LiteDatabase(new ConnectionString() { Filename = this.RandomString(20) + ".db", Upgrade = true });
LiteDB.FileMode fileMode = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? LiteDB.FileMode.Exclusive : LiteDB.FileMode.Shared;
var db = new LiteDatabase(new ConnectionString() { Filename = this.RandomString(20) + ".db", Upgrade = true, Mode = fileMode });

this.repository = new AddressIndexerOutpointsRepository(db, new ExtendedLoggerFactory(), this.maxItems);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public void OutPointCacheCanRetrieveExisting()
var dataFolder = new DataFolder(TestBase.CreateTestDir(this));
string dbPath = Path.Combine(dataFolder.RootPath, CollectionName);

var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true });
LiteDB.FileMode fileMode = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? LiteDB.FileMode.Exclusive : LiteDB.FileMode.Shared;
var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true, Mode = fileMode });
var cache = new AddressIndexerOutpointsRepository(database, new ExtendedLoggerFactory());

var outPoint = new OutPoint(uint256.Parse("0000af9ab2c8660481328d0444cf167dfd31f24ca2dbba8e5e963a2434cffa93"), 0);
Expand All @@ -203,7 +204,8 @@ public void OutPointCacheCannotRetrieveNonexistent()
var dataFolder = new DataFolder(TestBase.CreateTestDir(this));
string dbPath = Path.Combine(dataFolder.RootPath, CollectionName);

var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true });
LiteDB.FileMode fileMode = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? LiteDB.FileMode.Exclusive : LiteDB.FileMode.Shared;
var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true, Mode = fileMode });
var cache = new AddressIndexerOutpointsRepository(database, new ExtendedLoggerFactory());

Assert.False(cache.TryGetOutPointData(new OutPoint(uint256.Parse("0000af9ab2c8660481328d0444cf167dfd31f24ca2dbba8e5e963a2434cffa93"), 1), out OutPointData retrieved));
Expand All @@ -217,7 +219,8 @@ public void OutPointCacheEvicts()
var dataFolder = new DataFolder(TestBase.CreateTestDir(this));
string dbPath = Path.Combine(dataFolder.RootPath, CollectionName);

var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true });
LiteDB.FileMode fileMode = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? LiteDB.FileMode.Exclusive : LiteDB.FileMode.Shared;
var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true, Mode = fileMode });
var cache = new AddressIndexerOutpointsRepository(database, new ExtendedLoggerFactory(), 2);

Assert.Equal(0, cache.Count);
Expand Down Expand Up @@ -267,7 +270,8 @@ public void AddressCacheCanRetrieveExisting()
var dataFolder = new DataFolder(TestBase.CreateTestDir(this));
string dbPath = Path.Combine(dataFolder.RootPath, CollectionName);

var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true });
LiteDB.FileMode fileMode = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? LiteDB.FileMode.Exclusive : LiteDB.FileMode.Shared;
var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true, Mode = fileMode });
var cache = new AddressIndexRepository(database, new ExtendedLoggerFactory());

string address = "xyz";
Expand Down Expand Up @@ -295,7 +299,8 @@ public void AddressCacheRetrievesBlankRecordForNonexistent()
var dataFolder = new DataFolder(TestBase.CreateTestDir(this));
string dbPath = Path.Combine(dataFolder.RootPath, CollectionName);

var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true });
LiteDB.FileMode fileMode = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? LiteDB.FileMode.Exclusive : LiteDB.FileMode.Shared;
var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true, Mode = fileMode });
var cache = new AddressIndexRepository(database, new ExtendedLoggerFactory());

AddressIndexerData retrieved = cache.GetOrCreateAddress("xyz");
Expand All @@ -313,7 +318,8 @@ public void AddressCacheEvicts()
var dataFolder = new DataFolder(TestBase.CreateTestDir(this));
string dbPath = Path.Combine(dataFolder.RootPath, CollectionName);

var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true });
LiteDB.FileMode fileMode = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? LiteDB.FileMode.Exclusive : LiteDB.FileMode.Shared;
var database = new LiteDatabase(new ConnectionString() { Filename = dbPath, Upgrade = true, Mode = fileMode });
var cache = new AddressIndexRepository(database, new ExtendedLoggerFactory(), 4);

// Recall, each index entry counts as 1 and each balance change associated with it is an additional 1.
Expand Down

0 comments on commit 0bcc3a6

Please sign in to comment.