Adjust unit tests and apply fixes to scope

This commit is contained in:
Mole
2021-03-12 13:10:17 +01:00
parent 498a5e0c66
commit 5c7e4f8dde
2 changed files with 122 additions and 57 deletions

View File

@@ -519,7 +519,26 @@ namespace Umbraco.Core.Scoping
{
if (ParentScope is null)
{
WriteLocks[instanceId][lockId]++;
// Try and get the dict associated with the scope id.
var locksDictFound = WriteLocks.TryGetValue(instanceId, out var locksDict);
if (locksDictFound)
{
var lockFound = locksDict.TryGetValue(lockId, out var value);
if (lockFound)
{
WriteLocks[instanceId][lockId] = value+1;
}
else
{
WriteLocks[instanceId][lockId] = 1;
}
}
else
{
// The scope hasn't requested a lock yet, so we have to create a dict for it.
WriteLocks[instanceId] = new Dictionary<int, int>();
WriteLocks[instanceId][lockId] = 1;
}
}
else
{
@@ -543,7 +562,25 @@ namespace Umbraco.Core.Scoping
{
if (ParentScope is null)
{
ReadLocks[instanceId][lockId]++;
var locksDictFound = ReadLocks.TryGetValue(instanceId, out var locksDict);
if (locksDictFound)
{
var lockFound = locksDict.TryGetValue(lockId, out var value);
if (lockFound)
{
ReadLocks[instanceId][lockId] = value + 1;
}
else
{
ReadLocks[instanceId][lockId] = 1;
}
}
else
{
// The scope hasn't requested a lock yet, so we have to create a dict for it.
ReadLocks[instanceId] = new Dictionary<int, int>();
ReadLocks[instanceId][lockId] = 1;
}
}
else
{
@@ -721,11 +758,13 @@ namespace Umbraco.Core.Scoping
catch
{
DecrementWriteLock(lockId, instanceId);
throw;
}
}
else
{
DecrementWriteLock(lockId, instanceId);
// We already have a lock, so just increment the count for debugging purposes
IncrementWriteLock(lockId, instanceId);
}
}
}