-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathClientLifecycleE2ETests.cs
More file actions
83 lines (68 loc) · 3.06 KB
/
ClientLifecycleE2ETests.cs
File metadata and controls
83 lines (68 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using Xunit;
using Xunit.Abstractions;
namespace GitHub.Copilot.SDK.Test.E2E;
public class ClientLifecycleE2ETests(E2ETestFixture fixture, ITestOutputHelper output)
: E2ETestBase(fixture, "client_lifecycle", output)
{
[Fact]
public async Task Should_Receive_Session_Created_Lifecycle_Event()
{
var created = new TaskCompletionSource<SessionLifecycleEvent>(TaskCreationOptions.RunContinuationsAsynchronously);
using var subscription = Client.On(evt =>
{
if (evt.Type == SessionLifecycleEventTypes.Created)
{
created.TrySetResult(evt);
}
});
var session = await CreateSessionAsync();
var evt = await created.Task.WaitAsync(TimeSpan.FromSeconds(10));
Assert.Equal(SessionLifecycleEventTypes.Created, evt.Type);
Assert.Equal(session.SessionId, evt.SessionId);
}
[Fact]
public async Task Should_Filter_Session_Lifecycle_Events_By_Type()
{
var created = new TaskCompletionSource<SessionLifecycleEvent>(TaskCreationOptions.RunContinuationsAsynchronously);
using var subscription = Client.On(SessionLifecycleEventTypes.Created, evt => created.TrySetResult(evt));
var session = await CreateSessionAsync();
var evt = await created.Task.WaitAsync(TimeSpan.FromSeconds(10));
Assert.Equal(SessionLifecycleEventTypes.Created, evt.Type);
Assert.Equal(session.SessionId, evt.SessionId);
}
[Fact]
public async Task Disposing_Lifecycle_Subscription_Stops_Receiving_Events()
{
var count = 0;
var created = new TaskCompletionSource<SessionLifecycleEvent>(TaskCreationOptions.RunContinuationsAsynchronously);
var subscription = Client.On(_ => Interlocked.Increment(ref count));
subscription.Dispose();
using var activeSubscription = Client.On(SessionLifecycleEventTypes.Created, evt => created.TrySetResult(evt));
var session = await CreateSessionAsync();
var evt = await created.Task.WaitAsync(TimeSpan.FromSeconds(10));
Assert.Equal(session.SessionId, evt.SessionId);
Assert.Equal(0, Interlocked.CompareExchange(ref count, 0, 0));
}
[Theory]
[InlineData(true)] // async dispose path (DisposeAsync)
[InlineData(false)] // sync dispose path (Dispose)
public async Task Dispose_Disconnects_Client_And_Disposes_Rpc_Surface(bool useAsyncDispose)
{
var client = Ctx.CreateClient();
await client.StartAsync();
Assert.Equal(ConnectionState.Connected, client.State);
if (useAsyncDispose)
{
await client.DisposeAsync();
}
else
{
client.Dispose();
}
Assert.Equal(ConnectionState.Disconnected, client.State);
Assert.Throws<ObjectDisposedException>(() => client.Rpc);
}
}