@@ -122,53 +122,73 @@ class ProtocolServerMCPTest : public PipePairTest {
122
122
public:
123
123
SubsystemRAII<FileSystem, HostInfo, Socket> subsystems;
124
124
125
- std::unique_ptr<lldb_protocol::mcp::Transport> transport_up;
126
- std::unique_ptr<TestServer> server_up;
127
125
MainLoop loop;
126
+
127
+ std::unique_ptr<lldb_protocol::mcp::Transport> from_client;
128
+ std::unique_ptr<lldb_protocol::mcp::Transport> to_client;
129
+ MainLoopBase::ReadHandleUP handles[2 ];
130
+
131
+ std::unique_ptr<TestServer> server_up;
128
132
MockMessageHandler<Request, Response, Notification> message_handler;
129
133
130
134
llvm::Error Write (llvm::StringRef message) {
131
135
llvm::Expected<json::Value> value = json::parse (message);
132
136
if (!value)
133
137
return value.takeError ();
134
- return transport_up ->Write (*value);
138
+ return from_client ->Write (*value);
135
139
}
136
140
137
- llvm::Error Write (json::Value value) { return transport_up ->Write (value); }
141
+ llvm::Error Write (json::Value value) { return from_client ->Write (value); }
138
142
139
143
// / Run the transport MainLoop and return any messages received.
140
- llvm::Error
141
- Run (std::chrono::milliseconds timeout = std::chrono::milliseconds(200 )) {
144
+ llvm::Error Run () {
142
145
loop.AddCallback ([](MainLoopBase &loop) { loop.RequestTermination (); },
143
- timeout);
144
- auto handle = transport_up->RegisterMessageHandler (loop, message_handler);
145
- if (!handle)
146
- return handle.takeError ();
147
-
148
- return server_up->Run ();
146
+ std::chrono::milliseconds (10 ));
147
+ return loop.Run ().takeError ();
149
148
}
150
149
151
150
void SetUp () override {
152
151
PipePairTest::SetUp ();
153
152
154
- transport_up = std::make_unique<lldb_protocol::mcp::Transport>(
153
+ from_client = std::make_unique<lldb_protocol::mcp::Transport>(
155
154
std::make_shared<NativeFile>(input.GetReadFileDescriptor (),
156
155
File::eOpenOptionReadOnly,
157
156
NativeFile::Unowned),
158
157
std::make_shared<NativeFile>(output.GetWriteFileDescriptor (),
159
158
File::eOpenOptionWriteOnly,
160
- NativeFile::Unowned));
161
-
162
- server_up = std::make_unique<TestServer>(
163
- " lldb-mcp" , " 0.1.0" ,
164
- std::make_unique<lldb_protocol::mcp::Transport>(
165
- std::make_shared<NativeFile>(output.GetReadFileDescriptor (),
166
- File::eOpenOptionReadOnly,
167
- NativeFile::Unowned),
168
- std::make_shared<NativeFile>(input.GetWriteFileDescriptor (),
169
- File::eOpenOptionWriteOnly,
170
- NativeFile::Unowned)),
171
- loop);
159
+ NativeFile::Unowned),
160
+ [](StringRef message) {
161
+ // Uncomment for debugging
162
+ // llvm::errs() << "from_client: " << message << '\n';
163
+ });
164
+ to_client = std::make_unique<lldb_protocol::mcp::Transport>(
165
+ std::make_shared<NativeFile>(output.GetReadFileDescriptor (),
166
+ File::eOpenOptionReadOnly,
167
+ NativeFile::Unowned),
168
+ std::make_shared<NativeFile>(input.GetWriteFileDescriptor (),
169
+ File::eOpenOptionWriteOnly,
170
+ NativeFile::Unowned),
171
+ [](StringRef message) {
172
+ // Uncomment for debugging
173
+ // llvm::errs() << "to_client: " << message << '\n';
174
+ });
175
+
176
+ server_up = std::make_unique<TestServer>(" lldb-mcp" , " 0.1.0" , *to_client,
177
+ [](StringRef message) {
178
+ // Uncomment for debugging
179
+ // llvm::errs() << "server: " <<
180
+ // message << '\n';
181
+ });
182
+
183
+ auto maybe_from_client_handle =
184
+ from_client->RegisterMessageHandler (loop, message_handler);
185
+ EXPECT_THAT_EXPECTED (maybe_from_client_handle, Succeeded ());
186
+ handles[0 ] = std::move (*maybe_from_client_handle);
187
+
188
+ auto maybe_to_client_handle =
189
+ to_client->RegisterMessageHandler (loop, *server_up);
190
+ EXPECT_THAT_EXPECTED (maybe_to_client_handle, Succeeded ());
191
+ handles[1 ] = std::move (*maybe_to_client_handle);
172
192
}
173
193
};
174
194
0 commit comments