Skip to content

Commit 79c95bc

Browse files
Added fixture based tests and re-enabled disabled tests (#310)
* Added fixture based tests and re-enabled disabled tests * Fixed settler tests and hardened settler a little bit more * lets keep this going * skip progress tests * equals was a mistake * progress tests * progress tests * progress tests * fixed bug in work done progress (not completeing correctly!) * Progress tests * some tests just aren't ready yet
1 parent 3161bfc commit 79c95bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1018
-518
lines changed

src/Client/LanguageClientOptions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHand
6161
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandler(string method, Type type, JsonRpcHandlerOptions options) =>
6262
AddHandler(method, type, options);
6363

64+
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.AddHandlerLink(string sourceMethod, string destinationMethod) =>
65+
AddHandlerLink(sourceMethod, destinationMethod);
66+
6467
ILanguageClientRegistry IJsonRpcHandlerRegistry<ILanguageClientRegistry>.OnJsonRequest(string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options) =>
6568
OnJsonRequest(method, handler, options);
6669

src/Dap.Client/DebugAdapterClientOptions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ IDebugAdapterClientRegistry IJsonRpcHandlerRegistry<IDebugAdapterClientRegistry>
4949
IDebugAdapterClientRegistry IJsonRpcHandlerRegistry<IDebugAdapterClientRegistry>.AddHandler(string method, Type type, JsonRpcHandlerOptions options) =>
5050
AddHandler(method, type, options);
5151

52+
IDebugAdapterClientRegistry IJsonRpcHandlerRegistry<IDebugAdapterClientRegistry>.AddHandlerLink(string sourceMethod, string destinationMethod) =>
53+
AddHandlerLink(sourceMethod, destinationMethod);
54+
5255
IDebugAdapterClientRegistry IJsonRpcHandlerRegistry<IDebugAdapterClientRegistry>.OnJsonRequest(
5356
string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options
5457
) => OnJsonRequest(method, handler, options);
+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using OmniSharp.Extensions.DebugAdapter.Protocol.Events;
3+
using OmniSharp.Extensions.DebugAdapter.Protocol.Models;
34

45
namespace OmniSharp.Extensions.DebugAdapter.Protocol
56
{
67
public interface IProgressObservable : IObservable<ProgressEvent>
78
{
9+
ProgressToken ProgressToken { get; }
810
}
911
}

src/Dap.Protocol/Models/ProgressToken.cs

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public bool Equals(ProgressToken other) =>
6969
String == other.String;
7070

7171
public bool Equals(long other) => IsLong && Long == other;
72-
7372
public bool Equals(string other) => IsString && String == other;
7473

7574
private string DebuggerDisplay => IsString ? String : IsLong ? Long.ToString() : "";

src/Dap.Server/DebugAdapterServerOptions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ IDebugAdapterServerRegistry IJsonRpcHandlerRegistry<IDebugAdapterServerRegistry>
3737
IDebugAdapterServerRegistry IJsonRpcHandlerRegistry<IDebugAdapterServerRegistry>.AddHandler(string method, Type type, JsonRpcHandlerOptions options) =>
3838
AddHandler(method, type, options);
3939

40+
IDebugAdapterServerRegistry IJsonRpcHandlerRegistry<IDebugAdapterServerRegistry>.AddHandlerLink(string sourceMethod, string destinationMethod) =>
41+
AddHandlerLink(sourceMethod, destinationMethod);
42+
4043
IDebugAdapterServerRegistry IJsonRpcHandlerRegistry<IDebugAdapterServerRegistry>.OnJsonRequest(
4144
string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options
4245
) => OnJsonRequest(method, handler, options);

src/JsonRpc.Testing/AggregateSettler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class AggregateSettler : ISettler
1313

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

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

1818
public IObservable<Unit> Settle() =>
1919
_settlers

src/JsonRpc.Testing/JsonRpcIntegrationServerTestBase.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public JsonRpcIntegrationServerTestBase(JsonRpcTestOptions testOptions)
1919
_cancellationTokenSource = new CancellationTokenSource();
2020
if (!Debugger.IsAttached)
2121
{
22-
_cancellationTokenSource.CancelAfter(testOptions.TestTimeout);
22+
_cancellationTokenSource.CancelAfter(testOptions.CancellationTimeout);
2323
}
2424

25-
Events = ClientEvents = new Settler(TestOptions.SettleTimeSpan, TestOptions.SettleTimeout, CancellationToken);
25+
Events = ClientEvents = new Settler(TestOptions, CancellationToken);
2626
}
2727

2828
protected CompositeDisposable Disposable { get; }

src/JsonRpc.Testing/JsonRpcTestBase.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ public JsonRpcTestBase(JsonRpcTestOptions testOptions)
1919
_cancellationTokenSource = new CancellationTokenSource();
2020
if (!Debugger.IsAttached)
2121
{
22-
_cancellationTokenSource.CancelAfter(testOptions.TestTimeout);
22+
_cancellationTokenSource.CancelAfter(testOptions.CancellationTimeout);
2323
}
2424

25-
ClientEvents = new Settler(TestOptions.SettleTimeSpan, TestOptions.SettleTimeout, CancellationToken);
26-
ServerEvents = new Settler(TestOptions.SettleTimeSpan, TestOptions.SettleTimeout, CancellationToken);
25+
ClientEvents = new Settler(TestOptions, CancellationToken);
26+
ServerEvents = new Settler(TestOptions, CancellationToken);
2727
Events = new AggregateSettler(ClientEvents, ServerEvents);
2828
}
2929

3030
protected CompositeDisposable Disposable { get; }
31-
protected ISettler ClientEvents { get; }
32-
protected ISettler ServerEvents { get; }
33-
protected ISettler Events { get; }
34-
protected JsonRpcTestOptions TestOptions { get; }
35-
protected internal CancellationToken CancellationToken => _cancellationTokenSource.Token;
36-
protected Task SettleNext() => Events.SettleNext();
37-
protected IObservable<Unit> Settle() => Events.Settle();
31+
public ISettler ClientEvents { get; }
32+
public ISettler ServerEvents { get; }
33+
public ISettler Events { get; }
34+
public JsonRpcTestOptions TestOptions { get; }
35+
public CancellationToken CancellationToken => _cancellationTokenSource.Token;
36+
public Task SettleNext() => Events.SettleNext();
37+
public IObservable<Unit> Settle() => Events.Settle();
3838

3939
public void Dispose()
4040
{

src/JsonRpc.Testing/JsonRpcTestOptions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public JsonRpcTestOptions(ILoggerFactory clientLoggerFactory, ILoggerFactory ser
2121

2222
public ILoggerFactory ClientLoggerFactory { get; internal set; } = NullLoggerFactory.Instance;
2323
public ILoggerFactory ServerLoggerFactory { get; internal set; } = NullLoggerFactory.Instance;
24-
public TimeSpan SettleTimeSpan { get; internal set; } = TimeSpan.FromMilliseconds(100);
25-
public TimeSpan SettleTimeout { get; internal set; } = TimeSpan.FromMilliseconds(500);
26-
public TimeSpan TestTimeout { get; internal set; } = TimeSpan.FromMinutes(5);
24+
public TimeSpan WaitTime { get; internal set; } = TimeSpan.FromMilliseconds(50);
25+
public TimeSpan Timeout { get; internal set; } = TimeSpan.FromMilliseconds(500);
26+
public TimeSpan CancellationTimeout { get; internal set; } = TimeSpan.FromMinutes(5);
2727
public PipeOptions DefaultPipeOptions { get; internal set; } = new PipeOptions();
2828
}
2929
}

src/JsonRpc.Testing/JsonRpcTestOptionsExtensions.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ public static JsonRpcTestOptions WithClientLoggerFactory(this JsonRpcTestOptions
1818
return options;
1919
}
2020

21-
public static JsonRpcTestOptions WithSettleTimeSpan(this JsonRpcTestOptions options, TimeSpan settleTimeSpan)
21+
public static JsonRpcTestOptions WithWaitTime(this JsonRpcTestOptions options, TimeSpan waitTime)
2222
{
23-
options.SettleTimeSpan = settleTimeSpan;
23+
options.WaitTime = waitTime;
2424
return options;
2525
}
2626

27-
public static JsonRpcTestOptions WithSettleTimeout(this JsonRpcTestOptions options, TimeSpan timeout)
27+
public static JsonRpcTestOptions WithTimeout(this JsonRpcTestOptions options, TimeSpan timeout)
2828
{
29-
options.SettleTimeout = timeout;
29+
options.Timeout = timeout;
3030
return options;
3131
}
3232

33-
public static JsonRpcTestOptions WithTestTimeout(this JsonRpcTestOptions options, TimeSpan testTimeout)
33+
public static JsonRpcTestOptions WithCancellationTimeout(this JsonRpcTestOptions options, TimeSpan cancellationTimeout)
3434
{
35-
options.TestTimeout = testTimeout;
35+
options.CancellationTimeout = cancellationTimeout;
3636
return options;
3737
}
3838

src/JsonRpc.Testing/Settler.cs

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Reactive;
33
using System.Reactive.Concurrency;
4+
using System.Reactive.Linq;
45
using System.Reactive.Subjects;
56
using System.Reactive.Threading.Tasks;
67
using System.Threading;
@@ -11,21 +12,21 @@ namespace OmniSharp.Extensions.JsonRpc.Testing
1112
{
1213
public class Settler : ISettler, IRequestSettler, IDisposable
1314
{
14-
private readonly TimeSpan _timeout;
15+
private readonly JsonRpcTestOptions _options;
1516
private readonly CancellationToken _cancellationToken;
1617
private readonly IScheduler _scheduler;
1718
private readonly IObservable<Unit> _settle;
1819
private readonly IObserver<int> _requester;
1920
private readonly IDisposable _connectable;
20-
private readonly IObservable<Unit> _defaultValue;
21+
private readonly IObservable<Unit> _timeoutValue;
2122

22-
public Settler(TimeSpan waitTime, TimeSpan timeout, CancellationToken cancellationToken, IScheduler scheduler = null)
23+
public Settler(JsonRpcTestOptions options, CancellationToken cancellationToken, IScheduler scheduler = null)
2324
{
24-
_timeout = timeout;
25+
_options = options;
2526
_cancellationToken = cancellationToken;
2627
scheduler ??= Scheduler.Immediate;
2728
_scheduler = scheduler;
28-
_defaultValue = Return(Unit.Default, _scheduler);
29+
_timeoutValue = Return(Unit.Default, _scheduler);
2930
var subject = new Subject<int>();
3031
var data = subject;
3132

@@ -42,24 +43,34 @@ public Settler(TimeSpan waitTime, TimeSpan timeout, CancellationToken cancellati
4243
z => {
4344
if (z > 0)
4445
{
45-
return Timer(_timeout, _scheduler)
46-
.Select(z => Unit.Default);
46+
return Never<Unit>();
47+
// return Timer(_options.Timeout, _scheduler)
48+
// .Select(z => Unit.Default);
4749
}
4850

49-
return Amb(Timer(waitTime, _scheduler), Timer(_timeout, _scheduler))
51+
return Timer(_options.WaitTime, _scheduler)
5052
.Select(z => Unit.Default);
5153
}
5254
)
5355
.Replay(1, _scheduler);
5456
_connectable = connectable.Connect();
5557
_settle = connectable
56-
.Switch();
58+
.Select(o => o.Timeout(_options.Timeout, _scheduler))
59+
.Switch();
5760
_requester = subject.AsObserver();
5861
}
5962

60-
public Task SettleNext() => _settle.Take(1).IgnoreElements().LastOrDefaultAsync().ToTask(_cancellationToken);
63+
public Task SettleNext() => SettleNextInternal().ToTask(_cancellationToken);
6164

62-
public IObservable<Unit> Settle() => _settle.Timeout(_timeout, _scheduler).Catch<Unit, Exception>(_ => _defaultValue);
65+
public IObservable<Unit> SettleNextInternal() => _settle
66+
.Catch<Unit, Exception>(_ => _timeoutValue)
67+
.Take(1)
68+
.IgnoreElements()
69+
.LastOrDefaultAsync();
70+
71+
public IObservable<Unit> Settle() => _settle
72+
.Timeout(_options.Timeout, _scheduler)
73+
.Catch<Unit, Exception>(_ => _timeoutValue);
6374

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

src/JsonRpc/CompositeHandlersManager.cs

+30-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,40 @@ public IDisposable Add(string method, IJsonRpcHandler handler, JsonRpcHandlerOpt
2727
return result;
2828
}
2929

30-
public IDisposable Add(JsonRpcHandlerFactory factory, JsonRpcHandlerOptions options) => _parent.Add(factory, options);
30+
public IDisposable Add(JsonRpcHandlerFactory factory, JsonRpcHandlerOptions options)
31+
{
32+
var result = _parent.Add(factory, options);
33+
_compositeDisposable.Add(result);
34+
return result;
35+
}
3136

32-
public IDisposable Add(string method, JsonRpcHandlerFactory factory, JsonRpcHandlerOptions options) => _parent.Add(method, factory, options);
37+
public IDisposable Add(string method, JsonRpcHandlerFactory factory, JsonRpcHandlerOptions options)
38+
{
39+
var result = _parent.Add(factory, options);
40+
_compositeDisposable.Add(result);
41+
return result;
42+
}
3343

34-
public IDisposable Add(Type handlerType, JsonRpcHandlerOptions options) => _parent.Add(handlerType, options);
44+
public IDisposable Add(Type handlerType, JsonRpcHandlerOptions options)
45+
{
46+
var result = _parent.Add(handlerType, options);
47+
_compositeDisposable.Add(result);
48+
return result;
49+
}
3550

36-
public IDisposable Add(string method, Type handlerType, JsonRpcHandlerOptions options) => _parent.Add(method, handlerType, options);
51+
public IDisposable Add(string method, Type handlerType, JsonRpcHandlerOptions options)
52+
{
53+
var result = _parent.Add(method, handlerType, options);
54+
_compositeDisposable.Add(result);
55+
return result;
56+
}
3757

38-
public IDisposable AddLink(string sourceMethod, string destinationMethod) => _parent.AddLink(sourceMethod, destinationMethod);
58+
public IDisposable AddLink(string sourceMethod, string destinationMethod)
59+
{
60+
var result = _parent.AddLink(sourceMethod,destinationMethod);
61+
_compositeDisposable.Add(result);
62+
return result;
63+
}
3964

4065
public CompositeDisposable GetDisposable() => _compositeDisposable;
4166
}

src/JsonRpc/IJsonRpcHandlerRegistry.cs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public interface IJsonRpcHandlerRegistry<out T> : IJsonRpcHandlerRegistry where
2525
T AddHandler<TTHandler>(string method, JsonRpcHandlerOptions options = null) where TTHandler : IJsonRpcHandler;
2626
T AddHandler(Type type, JsonRpcHandlerOptions options = null);
2727
T AddHandler(string method, Type type, JsonRpcHandlerOptions options = null);
28+
T AddHandlerLink(string sourceMethod, string destinationMethod);
2829

2930
T OnJsonRequest(string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options = null);
3031
T OnJsonRequest(string method, Func<JToken, CancellationToken, Task<JToken>> handler, JsonRpcHandlerOptions options = null);

src/JsonRpc/InterimJsonRpcServerRegistry.cs

+6
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,11 @@ public sealed override T AddHandler(string method, Type type, JsonRpcHandlerOpti
5757
_handlersManager.Add(method, type, options);
5858
return (T) (object) this;
5959
}
60+
61+
public sealed override T AddHandlerLink(string sourceMethod, string destinationMethod)
62+
{
63+
_handlersManager.AddLink(sourceMethod, destinationMethod);
64+
return (T) (object) this;
65+
}
6066
}
6167
}

src/JsonRpc/JsonRpcCommonMethodsBase.cs

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public T OnNotification(string method, Func<CancellationToken, Task> handler, Js
112112
public abstract T AddHandler<THandler>(string method, JsonRpcHandlerOptions options = null) where THandler : IJsonRpcHandler;
113113
public abstract T AddHandler(Type type, JsonRpcHandlerOptions options = null);
114114
public abstract T AddHandler(string method, Type type, JsonRpcHandlerOptions options = null);
115+
public abstract T AddHandlerLink(string sourceMethod, string destinationMethod);
115116

116117
#endregion
117118
}

src/JsonRpc/JsonRpcOptionsRegistryBase.cs

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public sealed override T AddHandler(string method, Type type, JsonRpcHandlerOpti
6969
return (T) (object) this;
7070
}
7171

72+
public sealed override T AddHandlerLink(string sourceMethod, string destinationMethod)
73+
{
74+
Handlers.Add(JsonRpcHandlerDescription.Link(sourceMethod, destinationMethod));
75+
return (T) (object) this;
76+
}
77+
7278
#endregion
7379
}
7480
}

src/JsonRpc/OutputHandler.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ ILogger<OutputHandler> logger
5555
pipeWriter,
5656
serializer,
5757
receiver,
58-
new EventLoopScheduler(_ => new Thread(_) { IsBackground = true, Name = "OutputHandler" }),
58+
TaskPoolScheduler.Default,
59+
//new EventLoopScheduler(_ => new Thread(_) { IsBackground = true, Name = "OutputHandler" }),
5960
logger
6061
)
6162
{

src/Protocol/Client/WorkDone/LanguageClientWorkDoneManager.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Reactive.Disposables;
4+
using System.Reactive.Linq;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using MediatR;
@@ -96,6 +97,19 @@ public void Dispose()
9697
_progressObservable.Dispose();
9798
}
9899

99-
public IDisposable Subscribe(IObserver<WorkDoneProgress> observer) => _progressObservable.Subscribe(observer);
100+
public IDisposable Subscribe(IObserver<WorkDoneProgress> observer)
101+
{
102+
return _progressObservable.Subscribe(
103+
_ => {
104+
observer.OnNext(_);
105+
if (_ is WorkDoneProgressEnd)
106+
{
107+
observer.OnCompleted();
108+
}
109+
},
110+
observer.OnError,
111+
observer.OnCompleted
112+
);
113+
}
100114
}
101115
}

src/Server/LanguageServerOptions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ ILanguageServerRegistry IJsonRpcHandlerRegistry<ILanguageServerRegistry>.AddHand
4343
ILanguageServerRegistry IJsonRpcHandlerRegistry<ILanguageServerRegistry>.AddHandler(string method, Type type, JsonRpcHandlerOptions options) =>
4444
AddHandler(method, type, options);
4545

46+
ILanguageServerRegistry IJsonRpcHandlerRegistry<ILanguageServerRegistry>.AddHandlerLink(string sourceMethod, string destinationMethod) =>
47+
AddHandlerLink(sourceMethod, destinationMethod);
48+
4649
ILanguageServerRegistry IJsonRpcHandlerRegistry<ILanguageServerRegistry>.OnJsonRequest(string method, Func<JToken, Task<JToken>> handler, JsonRpcHandlerOptions options) =>
4750
OnJsonRequest(method, handler, options);
4851

test/Dap.Tests/Integration/ConnectionAndDisconnectionTests.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ namespace Dap.Tests.Integration
1515
public class ConnectionAndDisconnectionTests : DebugAdapterProtocolTestBase
1616
{
1717
public ConnectionAndDisconnectionTests(ITestOutputHelper outputHelper) : base(
18-
new JsonRpcTestOptions()
19-
.ConfigureForXUnit(outputHelper)
20-
.WithTestTimeout(TimeSpan.FromSeconds(20))
18+
new JsonRpcTestOptions().ConfigureForXUnit(outputHelper)
2119
)
2220
{
2321
}

0 commit comments

Comments
 (0)