Skip to content

Commit f0de955

Browse files
danbevitaloacasas
authored andcommitted
src: reduce test_inspector_socket_server output
Currently, when test/cctest/test_inspector_socket_server.cc is run there is output written to stderr by src/inspector_socket_server.cc which is interleaved with the gtest report: Debugger listening on port 9229. Warning: This is an experimental feature and could change at any time. To start debugging, open the following URLs in Chrome: ... The goal of this commit is to remove the above logged information by introducing an out_ member in the InspectorSocketServer class which defaults to stderr (keeping the current behavior). Setting out_ to NULL is supported in which case nothing will be written and is what the test has been configured with. When working on specific test case the appropriate output stream can be specified for the ServerHolder constructor to limit logging to that test case. PR-URL: #10537 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Eugene Ostroukhov <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 06a8243 commit f0de955

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

src/inspector_socket_server.cc

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,27 @@ void OnBufferAlloc(uv_handle_t* handle, size_t len, uv_buf_t* buf) {
7474
buf->len = len;
7575
}
7676

77-
void PrintDebuggerReadyMessage(int port, const std::vector<std::string>& ids) {
78-
fprintf(stderr,
77+
void PrintDebuggerReadyMessage(int port,
78+
const std::vector<std::string>& ids,
79+
FILE* out) {
80+
if (out == NULL) {
81+
return;
82+
}
83+
fprintf(out,
7984
"Debugger listening on port %d.\n"
8085
"Warning: This is an experimental feature "
8186
"and could change at any time.\n",
8287
port);
8388
if (ids.size() == 1)
84-
fprintf(stderr, "To start debugging, open the following URL in Chrome:\n");
89+
fprintf(out, "To start debugging, open the following URL in Chrome:\n");
8590
if (ids.size() > 1)
86-
fprintf(stderr, "To start debugging, open the following URLs in Chrome:\n");
91+
fprintf(out, "To start debugging, open the following URLs in Chrome:\n");
8792
for (const std::string& id : ids) {
88-
fprintf(stderr,
93+
fprintf(out,
8994
" chrome-devtools://devtools/bundled/inspector.html?"
9095
"experiments=true&v8only=true&ws=%s\n", GetWsUrl(port, id).c_str());
9196
}
92-
fflush(stderr);
97+
fflush(out);
9398
}
9499

95100
void SendHttpResponse(InspectorSocket* socket, const std::string& response) {
@@ -207,12 +212,14 @@ class SocketSession {
207212
};
208213

209214
InspectorSocketServer::InspectorSocketServer(SocketServerDelegate* delegate,
210-
int port) : loop_(nullptr),
211-
delegate_(delegate),
212-
port_(port),
213-
server_(uv_tcp_t()),
214-
closer_(nullptr),
215-
next_session_id_(0) { }
215+
int port,
216+
FILE* out) : loop_(nullptr),
217+
delegate_(delegate),
218+
port_(port),
219+
server_(uv_tcp_t()),
220+
closer_(nullptr),
221+
next_session_id_(0),
222+
out_(out) { }
216223

217224

218225
// static
@@ -260,7 +267,7 @@ void InspectorSocketServer::SessionTerminated(int session_id) {
260267
delegate_->EndSession(session_id);
261268
if (connected_sessions_.empty() &&
262269
uv_is_active(reinterpret_cast<uv_handle_t*>(&server_))) {
263-
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds());
270+
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds(), out_);
264271
}
265272
}
266273

@@ -337,10 +344,12 @@ bool InspectorSocketServer::Start(uv_loop_t* loop) {
337344
SocketConnectedCallback);
338345
}
339346
if (err == 0 && connected_sessions_.empty()) {
340-
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds());
347+
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds(), out_);
341348
}
342349
if (err != 0 && connected_sessions_.empty()) {
343-
fprintf(stderr, "Unable to open devtools socket: %s\n", uv_strerror(err));
350+
if (out_ != NULL) {
351+
fprintf(out_, "Unable to open devtools socket: %s\n", uv_strerror(err));
352+
}
344353
uv_close(reinterpret_cast<uv_handle_t*>(&server_), nullptr);
345354
return false;
346355
}

src/inspector_socket_server.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class SocketServerDelegate {
3232
class InspectorSocketServer {
3333
public:
3434
using ServerCallback = void (*)(InspectorSocketServer*);
35-
InspectorSocketServer(SocketServerDelegate* delegate, int port);
35+
InspectorSocketServer(SocketServerDelegate* delegate,
36+
int port,
37+
FILE* out = stderr);
3638
bool Start(uv_loop_t* loop);
3739
void Stop(ServerCallback callback);
3840
void Send(int session_id, const std::string& message);
@@ -66,6 +68,7 @@ class InspectorSocketServer {
6668
Closer* closer_;
6769
std::map<int, SocketSession*> connected_sessions_;
6870
int next_session_id_;
71+
FILE* out_;
6972

7073
friend class SocketSession;
7174
friend class Closer;

test/cctest/test_inspector_socket_server.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ class SocketWrapper {
300300
class ServerHolder {
301301
public:
302302
template <typename Delegate>
303-
ServerHolder(Delegate* delegate, int port)
303+
ServerHolder(Delegate* delegate, int port, FILE* out = NULL)
304304
: closed(false), paused(false), sessions_terminated(false),
305-
server_(delegate, port) {
305+
server_(delegate, port, out) {
306306
delegate->Connect(&server_);
307307
}
308308

0 commit comments

Comments
 (0)