Skip to content

isolateIds parameter does not work #533

Open
@gogolon

Description

@gogolon

Doc comment for the collect function states:
If [isolateIds] is set, the coverage gathering will be restricted to only those VM isolates.
This does not seem to be true. I'm trying to collect coverage from a single isolate, but the filter simply does not work and code executed on all isolates is included in the report.

Reproduction

  1. Create a new dart project with dart create isolate_coverage_sample
  2. Replace the code inside bin/isolate_coverage_sample.dart with the code below:
import 'dart:developer';
import 'dart:isolate';

import 'package:coverage/coverage.dart';
import 'package:isolate_coverage_sample/calculate.dart';
import 'package:isolate_coverage_sample/isolate_calculate.dart';

Future<void> main(List<String> arguments) async {
  calculate(); // This function is included by default in packages created using dart create

  final isolate = await Isolate.spawn(
    (_) => isolateCalculate(),
    null,
    paused: true,
  );
  final isolateId = Service.getIsolateId(isolate)!;
  final info = await Service.controlWebServer(enable: true);
  isolate.resume(isolate.pauseCapability!);

  final coverage = await collect(
    info.serverUri!,
    true,
    false,
    false,
    {'isolate_coverage_sample'},
    isolateIds: {isolateId},
  );

  print(coverage.entries);
}
  1. Add a file lib/isolate_calculate.dart containing this code:
int isolateCalculate() {
  return 6 * 7;
}
  1. While at the package's root, run:
    dart --pause-isolates-on-exit bin/isolate_coverage_sample.dart
  2. Inspect the entries on the output. The file package:isolate_coverage_sample/calculate.dart is included in the coverage even though it was called on the main isolate.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions