Merge pull request #23 from Microsoft/bug/intellisenseCacheTestFix

Fixed bug in intellisense cache test
This commit is contained in:
Mitchell Sternke
2016-08-22 10:25:25 -07:00
committed by GitHub
2 changed files with 24 additions and 56 deletions

View File

@@ -53,34 +53,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
new Dictionary<ConnectionSummary, IntellisenseCache>(new ConnectionSummaryComparer());
private Object cachesLock = new Object(); // Used when we insert/remove something from the cache dictionary
private ISqlConnectionFactory factory;
private Object factoryLock = new Object();
/// <summary>
/// Internal for testing purposes only
/// </summary>
internal ISqlConnectionFactory ConnectionFactory
{
get
{
lock(factoryLock)
{
if(factory == null)
{
factory = new SqlConnectionFactory();
}
}
return factory;
}
set
{
lock(factoryLock)
{
factory = value;
}
}
}
private ConnectionService connectionService = null;
/// <summary>
@@ -112,14 +84,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
ConnectionServiceInstance.RegisterOnDisconnectTask(RemoveAutoCompleteCacheUriReference);
}
private async Task UpdateAutoCompleteCache(ConnectionInfo connectionInfo)
{
if (connectionInfo != null)
{
await UpdateAutoCompleteCache(connectionInfo.ConnectionDetails);
}
}
/// <summary>
/// Intellisense cache count access for testing.
/// </summary>
@@ -158,21 +122,24 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
/// <summary>
/// Update the cached autocomplete candidate list when the user connects to a database
/// </summary>
/// <param name="details"></param>
public async Task UpdateAutoCompleteCache(ConnectionDetails details)
/// <param name="info"></param>
public async Task UpdateAutoCompleteCache(ConnectionInfo info)
{
IntellisenseCache cache;
lock(cachesLock)
if (info != null)
{
if(!caches.TryGetValue(details, out cache))
IntellisenseCache cache;
lock(cachesLock)
{
cache = new IntellisenseCache(ConnectionFactory, details);
caches[cache.DatabaseInfo] = cache;
if(!caches.TryGetValue(info.ConnectionDetails, out cache))
{
cache = new IntellisenseCache(info.Factory, info.ConnectionDetails);
caches[cache.DatabaseInfo] = cache;
}
cache.ReferenceCount++;
}
cache.ReferenceCount++;
await cache.UpdateCache();
}
await cache.UpdateCache();
}
/// <summary>