Skip to content

Commit 7fba5df

Browse files
committed
Disposing the subscription only after the connection closed event was raised
1 parent 16ce86f commit 7fba5df

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.Reactive.Concurrency;
2+
using System.Threading.Tasks;
3+
using NUnit.Framework;
4+
using WampSharp.Binding;
5+
using WampSharp.V2;
6+
using WampSharp.V2.Client;
7+
using WampSharp.V2.Core.Contracts;
8+
using WampSharp.V2.Rpc;
9+
using WampSharp.V2.Transports;
10+
11+
namespace WampSharp.Tests.Wampv2.Integration
12+
{
13+
public class GoodbyeTests
14+
{
15+
[Test]
16+
public async Task InMemoryTest()
17+
{
18+
var transport = new InMemoryTransport(Scheduler.Default);
19+
var binding = new JTokenJsonBinding();
20+
var realm = "some.realm";
21+
22+
var router = new WampHost();
23+
router.RegisterTransport(transport, new[] { binding });
24+
router.Open();
25+
26+
var calleeConnection = transport.CreateClientConnection(binding, Scheduler.Default);
27+
WampChannelFactory factory = new WampChannelFactory();
28+
29+
var callee = factory.CreateChannel(realm, calleeConnection, binding);
30+
await callee.Open();
31+
await callee.RealmProxy.Services.RegisterCallee(new WampTest());
32+
33+
34+
var callerConnection = transport.CreateClientConnection(binding, Scheduler.Default);
35+
var caller = factory.CreateChannel(realm, callerConnection, binding);
36+
await caller.Open();
37+
38+
var proxy = caller.RealmProxy.Services.GetCalleeProxy<IWampTest>();
39+
var result = await proxy.Echo("1");
40+
Assert.That(result, Is.EqualTo("1"));
41+
42+
await caller.Close(WampErrors.CloseNormal, new GoodbyeDetails());
43+
await callee.Close(WampErrors.CloseNormal, new GoodbyeDetails());
44+
45+
router.Dispose();
46+
}
47+
48+
public interface IWampTest
49+
{
50+
[WampProcedure("com.test.echo")]
51+
Task<string> Echo(string message);
52+
}
53+
54+
public class WampTest : IWampTest
55+
{
56+
public Task<string> Echo(string message)
57+
{
58+
return Task.FromResult(message);
59+
}
60+
}
61+
62+
}
63+
}

src/net45/WampSharp/WAMP2/V2/Transports/InMemory/InMemoryConnectionListener.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ private void OnError(Exception exception)
9999
private void OnCompleted()
100100
{
101101
mConnectionClosed.OnNext(Unit.Default);
102+
mSubscription.Dispose();
103+
mSubscription = null;
102104
}
103105

104106
private void OnNewMessage(WampMessage<TMessage> wampMessage)
@@ -113,9 +115,7 @@ public void Connect()
113115

114116
public void Dispose()
115117
{
116-
mSubscription.Dispose();
117118
mOutgoing.OnCompleted();
118-
mSubscription = null;
119119
}
120120

121121
public void Send(WampMessage<object> message)

0 commit comments

Comments
 (0)