mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
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: https://github.com/nodejs/node/pull/10537 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
e5499b32cf
commit
6d3c5b78c8
@ -74,22 +74,27 @@ void OnBufferAlloc(uv_handle_t* handle, size_t len, uv_buf_t* buf) {
|
||||
buf->len = len;
|
||||
}
|
||||
|
||||
void PrintDebuggerReadyMessage(int port, const std::vector<std::string>& ids) {
|
||||
fprintf(stderr,
|
||||
void PrintDebuggerReadyMessage(int port,
|
||||
const std::vector<std::string>& ids,
|
||||
FILE* out) {
|
||||
if (out == NULL) {
|
||||
return;
|
||||
}
|
||||
fprintf(out,
|
||||
"Debugger listening on port %d.\n"
|
||||
"Warning: This is an experimental feature "
|
||||
"and could change at any time.\n",
|
||||
port);
|
||||
if (ids.size() == 1)
|
||||
fprintf(stderr, "To start debugging, open the following URL in Chrome:\n");
|
||||
fprintf(out, "To start debugging, open the following URL in Chrome:\n");
|
||||
if (ids.size() > 1)
|
||||
fprintf(stderr, "To start debugging, open the following URLs in Chrome:\n");
|
||||
fprintf(out, "To start debugging, open the following URLs in Chrome:\n");
|
||||
for (const std::string& id : ids) {
|
||||
fprintf(stderr,
|
||||
fprintf(out,
|
||||
" chrome-devtools://devtools/bundled/inspector.html?"
|
||||
"experiments=true&v8only=true&ws=%s\n", GetWsUrl(port, id).c_str());
|
||||
}
|
||||
fflush(stderr);
|
||||
fflush(out);
|
||||
}
|
||||
|
||||
void SendHttpResponse(InspectorSocket* socket, const std::string& response) {
|
||||
@ -207,12 +212,14 @@ class SocketSession {
|
||||
};
|
||||
|
||||
InspectorSocketServer::InspectorSocketServer(SocketServerDelegate* delegate,
|
||||
int port) : loop_(nullptr),
|
||||
delegate_(delegate),
|
||||
port_(port),
|
||||
server_(uv_tcp_t()),
|
||||
closer_(nullptr),
|
||||
next_session_id_(0) { }
|
||||
int port,
|
||||
FILE* out) : loop_(nullptr),
|
||||
delegate_(delegate),
|
||||
port_(port),
|
||||
server_(uv_tcp_t()),
|
||||
closer_(nullptr),
|
||||
next_session_id_(0),
|
||||
out_(out) { }
|
||||
|
||||
|
||||
// static
|
||||
@ -260,7 +267,7 @@ void InspectorSocketServer::SessionTerminated(int session_id) {
|
||||
delegate_->EndSession(session_id);
|
||||
if (connected_sessions_.empty() &&
|
||||
uv_is_active(reinterpret_cast<uv_handle_t*>(&server_))) {
|
||||
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds());
|
||||
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds(), out_);
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,10 +344,12 @@ bool InspectorSocketServer::Start(uv_loop_t* loop) {
|
||||
SocketConnectedCallback);
|
||||
}
|
||||
if (err == 0 && connected_sessions_.empty()) {
|
||||
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds());
|
||||
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds(), out_);
|
||||
}
|
||||
if (err != 0 && connected_sessions_.empty()) {
|
||||
fprintf(stderr, "Unable to open devtools socket: %s\n", uv_strerror(err));
|
||||
if (out_ != NULL) {
|
||||
fprintf(out_, "Unable to open devtools socket: %s\n", uv_strerror(err));
|
||||
}
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&server_), nullptr);
|
||||
return false;
|
||||
}
|
||||
|
@ -32,7 +32,9 @@ class SocketServerDelegate {
|
||||
class InspectorSocketServer {
|
||||
public:
|
||||
using ServerCallback = void (*)(InspectorSocketServer*);
|
||||
InspectorSocketServer(SocketServerDelegate* delegate, int port);
|
||||
InspectorSocketServer(SocketServerDelegate* delegate,
|
||||
int port,
|
||||
FILE* out = stderr);
|
||||
bool Start(uv_loop_t* loop);
|
||||
void Stop(ServerCallback callback);
|
||||
void Send(int session_id, const std::string& message);
|
||||
@ -66,6 +68,7 @@ class InspectorSocketServer {
|
||||
Closer* closer_;
|
||||
std::map<int, SocketSession*> connected_sessions_;
|
||||
int next_session_id_;
|
||||
FILE* out_;
|
||||
|
||||
friend class SocketSession;
|
||||
friend class Closer;
|
||||
|
@ -300,9 +300,9 @@ class SocketWrapper {
|
||||
class ServerHolder {
|
||||
public:
|
||||
template <typename Delegate>
|
||||
ServerHolder(Delegate* delegate, int port)
|
||||
ServerHolder(Delegate* delegate, int port, FILE* out = NULL)
|
||||
: closed(false), paused(false), sessions_terminated(false),
|
||||
server_(delegate, port) {
|
||||
server_(delegate, port, out) {
|
||||
delegate->Connect(&server_);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user