Skip to content

Added fixture based tests and re-enabled disabled tests #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 14, 2020
3 changes: 3 additions & 0 deletions src/Client/LanguageClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHand
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(string method, Type type, JsonRpcHandlerOptions options) =>
AddHandler(method, type, options);

ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandlerLink(string sourceMethod, string destinationMethod) =>
AddHandlerLink(sourceMethod, destinationMethod);

ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonRequest(string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options) =>
OnJsonRequest(method, handler, options);

Expand Down
3 changes: 3 additions & 0 deletions src/Dap.Client/DebugAdapterClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ IDebugAdapterClientRegistry IJsonRpcHandlerRegistry<IDebugAdapterClientRegistry>
IDebugAdapterClientRegistry IJsonRpcHandlerRegistry<IDebugAdapterClientRegistry>.AddHandler(string method, Type type, JsonRpcHandlerOptions options) =>
AddHandler(method, type, options);

IDebugAdapterClientRegistry IJsonRpcHandlerRegistry<IDebugAdapterClientRegistry>.AddHandlerLink(string sourceMethod, string destinationMethod) =>
AddHandlerLink(sourceMethod, destinationMethod);

IDebugAdapterClientRegistry IJsonRpcHandlerRegistry<IDebugAdapterClientRegistry>.OnJsonRequest(
string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options
) => OnJsonRequest(method, handler, options);
Expand Down
2 changes: 2 additions & 0 deletions src/Dap.Protocol/IProgressObservable.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using OmniSharp.Extensions.DebugAdapter.Protocol.Events;
using OmniSharp.Extensions.DebugAdapter.Protocol.Models;

namespace OmniSharp.Extensions.DebugAdapter.Protocol
{
public interface IProgressObservable : IObservable<ProgressEvent>
{
ProgressToken ProgressToken { get; }
}
}
1 change: 0 additions & 1 deletion src/Dap.Protocol/Models/ProgressToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public bool Equals(ProgressToken other) =>
String == other.String;

public bool Equals(long other) => IsLong && Long == other;

public bool Equals(string other) => IsString && String == other;

private string DebuggerDisplay => IsString ? String : IsLong ? Long.ToString() : "";
Expand Down
3 changes: 3 additions & 0 deletions src/Dap.Server/DebugAdapterServerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ IDebugAdapterServerRegistry IJsonRpcHandlerRegistry<IDebugAdapterServerRegistry>
IDebugAdapterServerRegistry IJsonRpcHandlerRegistry<IDebugAdapterServerRegistry>.AddHandler(string method, Type type, JsonRpcHandlerOptions options) =>
AddHandler(method, type, options);

IDebugAdapterServerRegistry IJsonRpcHandlerRegistry<IDebugAdapterServerRegistry>.AddHandlerLink(string sourceMethod, string destinationMethod) =>
AddHandlerLink(sourceMethod, destinationMethod);

IDebugAdapterServerRegistry IJsonRpcHandlerRegistry<IDebugAdapterServerRegistry>.OnJsonRequest(
string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options
) => OnJsonRequest(method, handler, options);
Expand Down
2 changes: 1 addition & 1 deletion src/JsonRpc.Testing/AggregateSettler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AggregateSettler : ISettler

public AggregateSettler(params ISettler[] settlers) => _settlers = settlers;

public Task SettleNext() => Settle().Take(1).IgnoreElements().LastOrDefaultAsync().ToTask();
public Task SettleNext() => Task.WhenAll(_settlers.Select(z => z.SettleNext()));

public IObservable<Unit> Settle() =>
_settlers
Expand Down
4 changes: 2 additions & 2 deletions src/JsonRpc.Testing/JsonRpcIntegrationServerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public JsonRpcIntegrationServerTestBase(JsonRpcTestOptions testOptions)
_cancellationTokenSource = new CancellationTokenSource();
if (!Debugger.IsAttached)
{
_cancellationTokenSource.CancelAfter(testOptions.TestTimeout);
_cancellationTokenSource.CancelAfter(testOptions.CancellationTimeout);
}

Events = ClientEvents = new Settler(TestOptions.SettleTimeSpan, TestOptions.SettleTimeout, CancellationToken);
Events = ClientEvents = new Settler(TestOptions, CancellationToken);
}

protected CompositeDisposable Disposable { get; }
Expand Down
20 changes: 10 additions & 10 deletions src/JsonRpc.Testing/JsonRpcTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ public JsonRpcTestBase(JsonRpcTestOptions testOptions)
_cancellationTokenSource = new CancellationTokenSource();
if (!Debugger.IsAttached)
{
_cancellationTokenSource.CancelAfter(testOptions.TestTimeout);
_cancellationTokenSource.CancelAfter(testOptions.CancellationTimeout);
}

ClientEvents = new Settler(TestOptions.SettleTimeSpan, TestOptions.SettleTimeout, CancellationToken);
ServerEvents = new Settler(TestOptions.SettleTimeSpan, TestOptions.SettleTimeout, CancellationToken);
ClientEvents = new Settler(TestOptions, CancellationToken);
ServerEvents = new Settler(TestOptions, CancellationToken);
Events = new AggregateSettler(ClientEvents, ServerEvents);
}

protected CompositeDisposable Disposable { get; }
protected ISettler ClientEvents { get; }
protected ISettler ServerEvents { get; }
protected ISettler Events { get; }
protected JsonRpcTestOptions TestOptions { get; }
protected internal CancellationToken CancellationToken => _cancellationTokenSource.Token;
protected Task SettleNext() => Events.SettleNext();
protected IObservable<Unit> Settle() => Events.Settle();
public ISettler ClientEvents { get; }
public ISettler ServerEvents { get; }
public ISettler Events { get; }
public JsonRpcTestOptions TestOptions { get; }
public CancellationToken CancellationToken => _cancellationTokenSource.Token;
public Task SettleNext() => Events.SettleNext();
public IObservable<Unit> Settle() => Events.Settle();

public void Dispose()
{
Expand Down
6 changes: 3 additions & 3 deletions src/JsonRpc.Testing/JsonRpcTestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public JsonRpcTestOptions(ILoggerFactory clientLoggerFactory, ILoggerFactory ser

public ILoggerFactory ClientLoggerFactory { get; internal set; } = NullLoggerFactory.Instance;
public ILoggerFactory ServerLoggerFactory { get; internal set; } = NullLoggerFactory.Instance;
public TimeSpan SettleTimeSpan { get; internal set; } = TimeSpan.FromMilliseconds(100);
public TimeSpan SettleTimeout { get; internal set; } = TimeSpan.FromMilliseconds(500);
public TimeSpan TestTimeout { get; internal set; } = TimeSpan.FromMinutes(5);
public TimeSpan WaitTime { get; internal set; } = TimeSpan.FromMilliseconds(50);
public TimeSpan Timeout { get; internal set; } = TimeSpan.FromMilliseconds(500);
public TimeSpan CancellationTimeout { get; internal set; } = TimeSpan.FromMinutes(5);
public PipeOptions DefaultPipeOptions { get; internal set; } = new PipeOptions();
}
}
12 changes: 6 additions & 6 deletions src/JsonRpc.Testing/JsonRpcTestOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ public static JsonRpcTestOptions WithClientLoggerFactory(this JsonRpcTestOptions
return options;
}

public static JsonRpcTestOptions WithSettleTimeSpan(this JsonRpcTestOptions options, TimeSpan settleTimeSpan)
public static JsonRpcTestOptions WithWaitTime(this JsonRpcTestOptions options, TimeSpan waitTime)
{
options.SettleTimeSpan = settleTimeSpan;
options.WaitTime = waitTime;
return options;
}

public static JsonRpcTestOptions WithSettleTimeout(this JsonRpcTestOptions options, TimeSpan timeout)
public static JsonRpcTestOptions WithTimeout(this JsonRpcTestOptions options, TimeSpan timeout)
{
options.SettleTimeout = timeout;
options.Timeout = timeout;
return options;
}

public static JsonRpcTestOptions WithTestTimeout(this JsonRpcTestOptions options, TimeSpan testTimeout)
public static JsonRpcTestOptions WithCancellationTimeout(this JsonRpcTestOptions options, TimeSpan cancellationTimeout)
{
options.TestTimeout = testTimeout;
options.CancellationTimeout = cancellationTimeout;
return options;
}

Expand Down
33 changes: 22 additions & 11 deletions src/JsonRpc.Testing/Settler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
using System.Threading;
Expand All @@ -11,21 +12,21 @@ namespace OmniSharp.Extensions.JsonRpc.Testing
{
public class Settler : ISettler, IRequestSettler, IDisposable
{
private readonly TimeSpan _timeout;
private readonly JsonRpcTestOptions _options;
private readonly CancellationToken _cancellationToken;
private readonly IScheduler _scheduler;
private readonly IObservable<Unit> _settle;
private readonly IObserver<int> _requester;
private readonly IDisposable _connectable;
private readonly IObservable<Unit> _defaultValue;
private readonly IObservable<Unit> _timeoutValue;

public Settler(TimeSpan waitTime, TimeSpan timeout, CancellationToken cancellationToken, IScheduler scheduler = null)
public Settler(JsonRpcTestOptions options, CancellationToken cancellationToken, IScheduler scheduler = null)
{
_timeout = timeout;
_options = options;
_cancellationToken = cancellationToken;
scheduler ??= Scheduler.Immediate;
_scheduler = scheduler;
_defaultValue = Return(Unit.Default, _scheduler);
_timeoutValue = Return(Unit.Default, _scheduler);
var subject = new Subject<int>();
var data = subject;

Expand All @@ -42,24 +43,34 @@ public Settler(TimeSpan waitTime, TimeSpan timeout, CancellationToken cancellati
z => {
if (z > 0)
{
return Timer(_timeout, _scheduler)
.Select(z => Unit.Default);
return Never<Unit>();
// return Timer(_options.Timeout, _scheduler)
// .Select(z => Unit.Default);
}

return Amb(Timer(waitTime, _scheduler), Timer(_timeout, _scheduler))
return Timer(_options.WaitTime, _scheduler)
.Select(z => Unit.Default);
}
)
.Replay(1, _scheduler);
_connectable = connectable.Connect();
_settle = connectable
.Switch();
.Select(o => o.Timeout(_options.Timeout, _scheduler))
.Switch();
_requester = subject.AsObserver();
}

public Task SettleNext() => _settle.Take(1).IgnoreElements().LastOrDefaultAsync().ToTask(_cancellationToken);
public Task SettleNext() => SettleNextInternal().ToTask(_cancellationToken);

public IObservable<Unit> Settle() => _settle.Timeout(_timeout, _scheduler).Catch<Unit, Exception>(_ => _defaultValue);
public IObservable<Unit> SettleNextInternal() => _settle
.Catch<Unit, Exception>(_ => _timeoutValue)
.Take(1)
.IgnoreElements()
.LastOrDefaultAsync();

public IObservable<Unit> Settle() => _settle
.Timeout(_options.Timeout, _scheduler)
.Catch<Unit, Exception>(_ => _timeoutValue);

void IRequestSettler.OnStartRequest() => _requester.OnNext(1);

Expand Down
35 changes: 30 additions & 5 deletions src/JsonRpc/CompositeHandlersManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,40 @@ public IDisposable Add(string method, IJsonRpcHandler handler, JsonRpcHandlerOpt
return result;
}

public IDisposable Add(JsonRpcHandlerFactory factory, JsonRpcHandlerOptions options) => _parent.Add(factory, options);
public IDisposable Add(JsonRpcHandlerFactory factory, JsonRpcHandlerOptions options)
{
var result = _parent.Add(factory, options);
_compositeDisposable.Add(result);
return result;
}

public IDisposable Add(string method, JsonRpcHandlerFactory factory, JsonRpcHandlerOptions options) => _parent.Add(method, factory, options);
public IDisposable Add(string method, JsonRpcHandlerFactory factory, JsonRpcHandlerOptions options)
{
var result = _parent.Add(factory, options);
_compositeDisposable.Add(result);
return result;
}

public IDisposable Add(Type handlerType, JsonRpcHandlerOptions options) => _parent.Add(handlerType, options);
public IDisposable Add(Type handlerType, JsonRpcHandlerOptions options)
{
var result = _parent.Add(handlerType, options);
_compositeDisposable.Add(result);
return result;
}

public IDisposable Add(string method, Type handlerType, JsonRpcHandlerOptions options) => _parent.Add(method, handlerType, options);
public IDisposable Add(string method, Type handlerType, JsonRpcHandlerOptions options)
{
var result = _parent.Add(method, handlerType, options);
_compositeDisposable.Add(result);
return result;
}

public IDisposable AddLink(string sourceMethod, string destinationMethod) => _parent.AddLink(sourceMethod, destinationMethod);
public IDisposable AddLink(string sourceMethod, string destinationMethod)
{
var result = _parent.AddLink(sourceMethod,destinationMethod);
_compositeDisposable.Add(result);
return result;
}

public CompositeDisposable GetDisposable() => _compositeDisposable;
}
Expand Down
1 change: 1 addition & 0 deletions src/JsonRpc/IJsonRpcHandlerRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface IJsonRpcHandlerRegistry<out T> : IJsonRpcHandlerRegistry where
T AddHandler<TTHandler>(string method, JsonRpcHandlerOptions options = null) where TTHandler : IJsonRpcHandler;
T AddHandler(Type type, JsonRpcHandlerOptions options = null);
T AddHandler(string method, Type type, JsonRpcHandlerOptions options = null);
T AddHandlerLink(string sourceMethod, string destinationMethod);

T OnJsonRequest(string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options = null);
T OnJsonRequest(string method, Func<JToken, CancellationToken, Task<JToken>> handler, JsonRpcHandlerOptions options = null);
Expand Down
6 changes: 6 additions & 0 deletions src/JsonRpc/InterimJsonRpcServerRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@ public sealed override T AddHandler(string method, Type type, JsonRpcHandlerOpti
_handlersManager.Add(method, type, options);
return (T) (object) this;
}

public sealed override T AddHandlerLink(string sourceMethod, string destinationMethod)
{
_handlersManager.AddLink(sourceMethod, destinationMethod);
return (T) (object) this;
}
}
}
1 change: 1 addition & 0 deletions src/JsonRpc/JsonRpcCommonMethodsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public T OnNotification(string method, Func<CancellationToken, Task> handler, Js
public abstract T AddHandler<THandler>(string method, JsonRpcHandlerOptions options = null) where THandler : IJsonRpcHandler;
public abstract T AddHandler(Type type, JsonRpcHandlerOptions options = null);
public abstract T AddHandler(string method, Type type, JsonRpcHandlerOptions options = null);
public abstract T AddHandlerLink(string sourceMethod, string destinationMethod);

#endregion
}
Expand Down
6 changes: 6 additions & 0 deletions src/JsonRpc/JsonRpcOptionsRegistryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public sealed override T AddHandler(string method, Type type, JsonRpcHandlerOpti
return (T) (object) this;
}

public sealed override T AddHandlerLink(string sourceMethod, string destinationMethod)
{
Handlers.Add(JsonRpcHandlerDescription.Link(sourceMethod, destinationMethod));
return (T) (object) this;
}

#endregion
}
}
3 changes: 2 additions & 1 deletion src/JsonRpc/OutputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ ILogger<OutputHandler> logger
pipeWriter,
serializer,
receiver,
new EventLoopScheduler(_ => new Thread(_) { IsBackground = true, Name = "OutputHandler" }),
TaskPoolScheduler.Default,
//new EventLoopScheduler(_ => new Thread(_) { IsBackground = true, Name = "OutputHandler" }),
logger
)
{
Expand Down
16 changes: 15 additions & 1 deletion src/Protocol/Client/WorkDone/LanguageClientWorkDoneManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
Expand Down Expand Up @@ -96,6 +97,19 @@ public void Dispose()
_progressObservable.Dispose();
}

public IDisposable Subscribe(IObserver<WorkDoneProgress> observer) => _progressObservable.Subscribe(observer);
public IDisposable Subscribe(IObserver<WorkDoneProgress> observer)
{
return _progressObservable.Subscribe(
_ => {
observer.OnNext(_);
if (_ is WorkDoneProgressEnd)
{
observer.OnCompleted();
}
},
observer.OnError,
observer.OnCompleted
);
}
}
}
3 changes: 3 additions & 0 deletions src/Server/LanguageServerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ ILanguageServerRegistry IJsonRpcHandlerRegistry<ILanguageServerRegistry>.AddHand
ILanguageServerRegistry IJsonRpcHandlerRegistry<ILanguageServerRegistry>.AddHandler(string method, Type type, JsonRpcHandlerOptions options) =>
AddHandler(method, type, options);

ILanguageServerRegistry IJsonRpcHandlerRegistry<ILanguageServerRegistry>.AddHandlerLink(string sourceMethod, string destinationMethod) =>
AddHandlerLink(sourceMethod, destinationMethod);

ILanguageServerRegistry IJsonRpcHandlerRegistry<ILanguageServerRegistry>.OnJsonRequest(string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options) =>
OnJsonRequest(method, handler, options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ namespace Dap.Tests.Integration
public class ConnectionAndDisconnectionTests : DebugAdapterProtocolTestBase
{
public ConnectionAndDisconnectionTests(ITestOutputHelper outputHelper) : base(
new JsonRpcTestOptions()
.ConfigureForXUnit(outputHelper)
.WithTestTimeout(TimeSpan.FromSeconds(20))
new JsonRpcTestOptions().ConfigureForXUnit(outputHelper)
)
{
}
Expand Down
Loading