Skip to content

worker: add worker name to report #58935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ static void WriteNodeReport(Isolate* isolate,
env->ForEachWorker([&](Worker* w) {
expected_results += w->RequestInterrupt([&](Environment* env) {
std::ostringstream os;

GetNodeReport(
env, "Worker thread subreport", trigger, Local<Value>(), os);
std::string name =
"Worker thread subreport [" + std::string(w->name()) + "]";
GetNodeReport(env, name.c_str(), trigger, Local<Value>(), os);

Mutex::ScopedLock lock(workers_mutex);
worker_infos.emplace_back(os.str());
Expand Down
1 change: 1 addition & 0 deletions src/node_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Worker : public AsyncWrap {
bool is_stopped() const;
const SnapshotData* snapshot_data() const { return snapshot_data_; }
bool is_internal() const { return is_internal_; }
std::string_view name() const { return name_; }

static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CloneParentEnvVars(
Expand Down
6 changes: 4 additions & 2 deletions test/report/test-report-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function basic() {
parentPort.once('message', () => {
/* Wait for message to stop the Worker */
});
`, { eval: true });
`, { eval: true, name: 'hello' });

await once(w, 'online');

Expand All @@ -22,7 +22,9 @@ async function basic() {
assert.strictEqual(report.workers.length, 1);
helper.validateContent(report.workers[0]);
assert.strictEqual(report.workers[0].header.threadId, w.threadId);

assert.strictEqual(report.workers[0].header.event,
'Worker thread subreport [hello]',
report.workers[0].header.event);
w.postMessage({});

await once(w, 'exit');
Expand Down
Loading