Skip to content

Commit f259bcf

Browse files
Synchronize tests using stdio access.
1 parent 14b2681 commit f259bcf

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tests/ModelContextProtocol.Tests/Transport/StdioServerTransportTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace ModelContextProtocol.Tests.Transport;
1010

1111
public class StdioServerTransportTests
1212
{
13+
private static readonly SemaphoreSlim s_consoleSemaphore = new(initialCount: 1);
1314
private readonly McpServerOptions _serverOptions;
1415

1516
public StdioServerTransportTests()
@@ -60,6 +61,8 @@ public async Task StartListeningAsync_Should_Set_Connected_State()
6061
[Fact]
6162
public async Task SendMessageAsync_Should_Send_Message()
6263
{
64+
await s_consoleSemaphore.WaitAsync();
65+
6366
TextReader oldIn = Console.In;
6467
TextWriter oldOut = Console.Out;
6568
try
@@ -86,6 +89,7 @@ public async Task SendMessageAsync_Should_Send_Message()
8689
{
8790
Console.SetOut(oldOut);
8891
Console.SetIn(oldIn);
92+
s_consoleSemaphore.Release();
8993
}
9094
}
9195

@@ -112,6 +116,8 @@ public async Task DisposeAsync_Should_Dispose_Resources()
112116
[Fact]
113117
public async Task ReadMessagesAsync_Should_Read_Messages()
114118
{
119+
await s_consoleSemaphore.WaitAsync();
120+
115121
var message = new JsonRpcRequest { Method = "test", Id = RequestId.FromNumber(44) };
116122
var json = JsonSerializer.Serialize(message, JsonSerializerOptionsExtensions.DefaultOptions);
117123

@@ -137,6 +143,7 @@ public async Task ReadMessagesAsync_Should_Read_Messages()
137143
{
138144
Console.SetOut(oldOut);
139145
Console.SetIn(oldIn);
146+
s_consoleSemaphore.Release();
140147
}
141148
}
142149

0 commit comments

Comments
 (0)