Repository navigation
Expand file tree
/
Copy pathRpcEventLogE2ETests.cs
More file actions
122 lines (103 loc) · 4.93 KB
/
Copy pathRpcEventLogE2ETests.cs
File metadata and controls
122 lines (103 loc) · 4.93 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using GitHub.Copilot.Rpc;
using GitHub.Copilot.Test.Harness;
using Xunit;
using Xunit.Abstractions;
namespace GitHub.Copilot.Test.E2E;
public class RpcEventLogE2ETests(E2ETestFixture fixture, ITestOutputHelper output)
: E2ETestBase(fixture, "rpc_event_log", output)
{
private static readonly TimeSpan EventLogTimeout = TimeSpan.FromSeconds(30);
private static readonly string[] TitleChangedEventTypes = ["session.title_changed"];
[Fact]
public async Task Should_Read_Persisted_Events_From_Beginning()
{
await using var session = await CreateSessionAsync();
await session.Rpc.Plan.UpdateAsync("# Event log E2E plan\n- persisted event");
EventsReadResult? read = null;
await TestHelper.WaitForConditionAsync(
async () =>
{
read = await session.Rpc.EventLog.ReadAsync(max: 100, waitMs: TimeSpan.Zero);
return read.Events
.OfType<SessionPlanChangedEvent>()
.Any(evt => evt.Data.Operation == PlanChangedOperation.Create && evt.Ephemeral != true);
},
timeout: EventLogTimeout,
timeoutMessage: "Timed out waiting for session.eventLog.read to return the persisted session.plan_changed event.");
Assert.NotNull(read);
Assert.Equal(EventsCursorStatus.Ok, read.CursorStatus);
Assert.False(string.IsNullOrWhiteSpace(read.Cursor));
Assert.Contains(
read.Events.OfType<SessionPlanChangedEvent>(),
evt => evt.Data.Operation == PlanChangedOperation.Create);
}
[Fact]
public async Task Should_Return_Tail_Cursor_And_Read_Empty_When_No_New_Events()
{
await using var session = await CreateSessionAsync();
EventLogTailResult? tail = null;
EventsReadResult? read = null;
await TestHelper.WaitForConditionAsync(
async () =>
{
tail = await session.Rpc.EventLog.TailAsync();
read = await session.Rpc.EventLog.ReadAsync(
cursor: tail.Cursor,
max: 10,
waitMs: TimeSpan.Zero);
return read.CursorStatus == EventsCursorStatus.Ok && read.Events.Count == 0;
},
timeout: EventLogTimeout,
timeoutMessage: "Timed out waiting for a stable event-log tail cursor with no immediately available events.");
Assert.NotNull(tail);
Assert.False(string.IsNullOrWhiteSpace(tail.Cursor));
Assert.NotNull(read);
Assert.Empty(read.Events);
Assert.False(read.HasMore);
}
[Fact]
public async Task Should_Register_And_Release_Event_Interest_Idempotently()
{
await using var session = await CreateSessionAsync();
var registered = await session.Rpc.EventLog.RegisterInterestAsync("session.title_changed");
Assert.False(string.IsNullOrWhiteSpace(registered.Handle));
var released = await session.Rpc.EventLog.ReleaseInterestAsync(registered.Handle);
Assert.True(released.Success);
var releasedAgain = await session.Rpc.EventLog.ReleaseInterestAsync(registered.Handle);
Assert.True(releasedAgain.Success);
}
[Fact]
public async Task Should_LongPoll_With_Types_Filter_For_TitleChanged_Event()
{
await using var session = await CreateSessionAsync();
EventsReadResult? read = null;
string expectedTitle = string.Empty;
await TestHelper.WaitForConditionAsync(
async () =>
{
expectedTitle = $"EventLogTitle-{Guid.NewGuid():N}";
var tail = await session.Rpc.EventLog.TailAsync();
var readTask = session.Rpc.EventLog.ReadAsync(
cursor: tail.Cursor,
max: 10,
waitMs: TimeSpan.FromSeconds(5),
types: TitleChangedEventTypes);
await session.Rpc.Name.SetAsync(expectedTitle);
read = await readTask;
return read.Events
.OfType<SessionTitleChangedEvent>()
.Any(evt => string.Equals(evt.Data.Title, expectedTitle, StringComparison.Ordinal));
},
timeout: EventLogTimeout,
timeoutMessage: "Timed out waiting for filtered session.eventLog.read to return session.title_changed.");
Assert.NotNull(read);
Assert.Equal(EventsCursorStatus.Ok, read.CursorStatus);
Assert.All(read.Events, evt => Assert.Equal("session.title_changed", evt.Type));
Assert.Contains(
read.Events.OfType<SessionTitleChangedEvent>(),
evt => string.Equals(evt.Data.Title, expectedTitle, StringComparison.Ordinal));
}
}