Remove extra level of tasks in binding queue (#79)

* Remove extra layer of tasks in binding queue

* Change order of assigning result to avoid race condition

* Add timeout log for the metadata lock event

* Fix test cases
This commit is contained in:
Karl Burtram
2016-10-08 00:06:35 +00:00
committed by GitHub
parent 03d7fd94c8
commit f32b0290bb
5 changed files with 73 additions and 85 deletions

View File

@@ -89,45 +89,29 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
/// <summary>
/// Test bind operation callback
/// </summary>
private Task<object> TestBindOperation(
private object TestBindOperation(
IBindingContext bindContext,
CancellationToken cancelToken)
{
return Task.Run(() =>
{
cancelToken.WaitHandle.WaitOne(this.bindCallbackDelay);
this.isCancelationRequested = cancelToken.IsCancellationRequested;
if (!this.isCancelationRequested)
{
cancelToken.WaitHandle.WaitOne(this.bindCallbackDelay);
this.isCancelationRequested = cancelToken.IsCancellationRequested;
if (!this.isCancelationRequested)
{
++this.bindCallCount;
}
return new CompletionItem[0] as object;
});
++this.bindCallCount;
}
return new CompletionItem[0];
}
/// <summary>
/// Test callback for the bind timeout operation
/// </summary>
private Task<object> TestTimeoutOperation(
private object TestTimeoutOperation(
IBindingContext bindingContext)
{
++this.timeoutCallCount;
return Task.FromResult(new CompletionItem[0] as object);
return new CompletionItem[0];
}
/// <summary>
/// Runs for a few seconds to allow the queue to pump any requests
/// </summary>
private void WaitForQueue(int delay = 5000)
{
int step = 50;
int steps = delay / step + 1;
for (int i = 0; i < steps; ++i)
{
Thread.Sleep(step);
}
}
/// <summary>
/// Queues a single task
/// </summary>
@@ -141,7 +125,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
bindOperation: TestBindOperation,
timeoutOperation: TestTimeoutOperation);
WaitForQueue();
Thread.Sleep(1000);
this.bindingQueue.StopQueueProcessor(15000);
@@ -166,7 +150,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
timeoutOperation: TestTimeoutOperation);
}
WaitForQueue();
Thread.Sleep(2000);
this.bindingQueue.StopQueueProcessor(15000);
@@ -183,14 +167,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
{
InitializeTestSettings();
this.bindCallbackDelay = 10000;
this.bindCallbackDelay = 1000;
this.bindingQueue.QueueBindingOperation(
key: "testkey",
bindingTimeout: bindCallbackDelay / 2,
bindOperation: TestBindOperation,
timeoutOperation: TestTimeoutOperation);
WaitForQueue(this.bindCallbackDelay + 2000);
Thread.Sleep(this.bindCallbackDelay + 100);
this.bindingQueue.StopQueueProcessor(15000);