nodejs / nodejs/node

Test runner with isolation=none does not work in child process

Đang mở
#60,020 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

child_process test_runner
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

Version

v24.9.0

Platform
Linux home 5.15.0-153-generic #163-Ubuntu SMP Thu Aug 7 16:37:18 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Subsystem

No response

What steps will reproduce the bug?

runner.js

import cluster from 'node:cluster';
import { run } from "node:test";

if (cluster.isPrimary) {
  cluster.fork();
} else {
  const stream = run({
    isolation: "none",
  });

  stream.on("data", (data) => {
    console.log("on data", data.type);
  });

  stream.on("end", () => {
    console.log("on end")
    process.exit(0);
  });

  stream.on("error", (err) => {
    console.log("on error", err);
  });
}

dummy.test.js

import { describe, it } from "node:test";
import * as assert from "node:assert";

describe("suite", () => {
  it("works", ()  => {
    assert.ok(true);
  });
});

How often does it reproduce? Is there a required condition?

Always. No.

What is the expected behavior? Why is that the expected behavior?

With isolation: "process" (the default), here's the output:

on data test:enqueue
on data test:dequeue
on data test:enqueue
on data test:dequeue
on data test:enqueue
on data test:dequeue
on data test:complete
on data test:start
on data test:start
on data test:pass
on data test:complete
on data test:plan
on data test:pass
on data test:summary
on data test:complete
on data test:plan
on data test:diagnostic
on data test:diagnostic
on data test:diagnostic
on data test:diagnostic
on data test:diagnostic
on data test:diagnostic
on data test:diagnostic
on data test:diagnostic
on data test:summary
on end

Process finished with exit code 0

The process cleanly exits at the end of the tests.

What do you see instead?

With isolation: "none", here's the output:

on data test:enqueue
on data test:dequeue
on data test:enqueue
on data test:dequeue
on data test:complete
on data test:start
on data test:start
on data test:pass
on data test:complete
on data test:plan
on data test:pass

And the process hangs.

Additional information

The goal was to use the "cluster" module to run the tests in parallel with the shard option:

import { run } from "node:test";
import { spec } from "node:test/reporters";
import { PassThrough } from "node:stream";
import { availableParallelism } from "node:os";
import cluster from 'node:cluster';

const concurrency = availableParallelism();
let completed = 0;

if (cluster.isPrimary) {
  const mergedStream = new PassThrough({
    objectMode: true
  });

  cluster.on("message", (_worker, message) => {
    mergedStream.emit("data", message);
  });

  mergedStream
    .compose(spec)
    .pipe(process.stdout);

  for (let i = 1; i <= concurrency; i++) {
    cluster.fork({
      SHARD_INDEX: i,
      SHARD_TOTAL: concurrency,
    });
  }

  cluster.on("exit", (worker, code, signal) => {
    if (++completed === concurrency) {
      mergedStream.end();
    }
  });
} else {
  const stream = run({
    isolation: "none",
    shard: {
      index: parseInt(process.env.SHARD_INDEX, 10),
      total: parseInt(process.env.SHARD_TOTAL, 10),
    },
  });

  stream.on("data", (chunk) => {
    process.send(chunk);
  });
}

Related: https://github.com/nodejs/node/issues/55939

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với việc tái hiện trong runner.js và dummy.test.js, sau đó lần theo điểm vào run() của node:test với isolation được đặt thành "none" khi được gọi từ một tiến trình con của cluster. So sánh vòng đời stream của nó với isolation mặc định "process" và issue liên quan 55939. Hoàn thành khi stream của tiến trình con phát ra các event còn lại, kết thúc và thoát sạch sẽ, đồng thời vẫn giữ hỗ trợ shard.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, node.js
Lĩnh vực
testing-qa
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
55/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.