Skip to content

Commit

Permalink
Add test for marshalling one object twice
Browse files Browse the repository at this point in the history
Closes #1012
  • Loading branch information
AArnott committed Mar 5, 2024
1 parent 5f21ac8 commit 851d425
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/StreamJsonRpc.Tests/MarshalableProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,24 @@ public async Task IMarshalable_MarshaledBackAndForth()
Assert.True(IsExceptionOrInnerOfType<NotSupportedException>(ex));
}

[Fact]
public async Task OneObjectMarshalledTwiceHasIndependentLifetimes()
{
// The method we call twice returns the same object each time,
// but JsonRpc doesn't recognize this and assigns a unique token and proxy each time.
IMarshalable proxy1 = (await this.client.GetMarshalableAsync().WithCancellation(this.TimeoutToken))!;
IMarshalable proxy2 = (await this.client.GetMarshalableAsync().WithCancellation(this.TimeoutToken))!;

await proxy1.DoSomethingAsync();
await proxy2.DoSomethingAsync();

Assert.NotSame(proxy1, proxy2);
proxy1.Dispose();

await proxy2.DoSomethingAsync();
proxy2.Dispose();
}

[Fact]
public async Task DisposeOnDisconnect()
{
Expand Down Expand Up @@ -892,9 +910,10 @@ public class Server : IServer

public Task<IMarshalable?> GetMarshalableAsync(bool returnNull)
{
var marshalable = returnNull ? null : new Data(() => this.ReturnedMarshalableDisposed.Set());
// The OneObjectMarshalledTwiceHasIndependentLifetimes test depends on us returning the same instance each time.
var marshalable = returnNull ? null : (this.ReturnedMarshalable ?? new Data(() => this.ReturnedMarshalableDisposed.Set()));
this.ReturnedMarshalable = marshalable;
return Task.FromResult<IMarshalable?>(marshalable);
return Task.FromResult(marshalable);
}

public Task<IMarshalableWithOptionalInterfaces?> GetMarshalableWithOptionalInterfacesAsync()
Expand Down

0 comments on commit 851d425

Please sign in to comment.