encodeForWorker method

String encodeForWorker({
  1. Iterable<String> testIds = const [],
  2. Iterable<String> assetPaths = const [],
})

Encodes only the plans assigned to one worker, including session setup definitions required by those plans.

Implementation

String encodeForWorker({
  Iterable<String> testIds = const [],
  Iterable<String> assetPaths = const [],
}) {
  final selectedIds = <String>{...testIds};
  final paths = assetPaths.toSet();
  for (final definition in definitionsById.values) {
    if (paths.contains(definition.assetPath)) {
      selectedIds.add(definition.testCase.id);
    }
  }

  void includeSession(String id) {
    final definition = definitionsById[id];
    if (definition == null) {
      throw StateError('No compiled test definition for worker test "$id".');
    }
    final session = definition.testCase.session;
    if (session != null && selectedIds.add(session)) includeSession(session);
  }

  for (final id in selectedIds.toList(growable: false)) {
    includeSession(id);
  }
  final plans = <String, ExecutionPlan>{};
  final definitions = definitionsById.values
      .where((definition) => selectedIds.contains(definition.testCase.id))
      .toList(growable: false);
  for (final id in selectedIds) {
    final plan = plansById[id];
    if (plan == null) continue;
    plans[id] = plan;
  }
  return CliWorkerBatchWireTransport.encode(
    definitions: definitions,
    config: config,
    plans: plans,
  );
}