Skip to content

Commit

Permalink
Only use single random seed when using sz test. (#1435)
Browse files Browse the repository at this point in the history
Currently when running `sz test` without the
`--test-randomize-ordering-seed` option a new seed is generated for
every package. This makes it hard to know which seed was used for which
package when testing several packages concurrently. WIth this PR only a
single random seed for all packages being tested is generated at the
beginning when running `sz test`.
  • Loading branch information
Jonas-Sander authored Apr 20, 2024
1 parent aeafee7 commit 4fcd51a
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions tools/sz_repo_cli/lib/src/commands/src/test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ If not passed, do not randomize test case execution order.''',
return super.packagesToProcess.where((package) => package.hasTestDirectory);
}

late final int _testRandomizeOrderingSeed;

@override
Future<void> runSetup() async {
final seedArg = argResults!['test-randomize-ordering-seed'] as String;
// Copied from https://github.com/dart-lang/test/blob/ba64bbbaa26f09e139c26f9ad6409995806aac6e/pkgs/test_core/lib/src/runner/configuration/args.dart#L277
_testRandomizeOrderingSeed = seedArg == 'random'
? Random().nextInt(4294967295)
: int.parse(seedArg).toUnsigned(32);
stdout.writeln(
'Using seed for test randomization: $_testRandomizeOrderingSeed');
}

@override
Future<void> runTaskForPackage(Package package) {
return runTests(
Expand All @@ -81,8 +94,7 @@ If not passed, do not randomize test case execution order.''',
excludeGoldens: argResults!['exclude-goldens'] as bool,
onlyGoldens: argResults!['only-goldens'] as bool,
updateGoldens: argResults!['update-goldens'] as bool,
testRandomizeOrderingSeed:
argResults!['test-randomize-ordering-seed'] as String,
testRandomizeOrderingSeed: _testRandomizeOrderingSeed,
);
}
}
Expand All @@ -93,30 +105,24 @@ Future<void> runTests(
required bool excludeGoldens,
required bool onlyGoldens,
required bool updateGoldens,
String testRandomizeOrderingSeed = 'random',
required int testRandomizeOrderingSeed,
}) {
// Copied from https://github.com/dart-lang/test/blob/ba64bbbaa26f09e139c26f9ad6409995806aac6e/pkgs/test_core/lib/src/runner/configuration/args.dart#L277
final seed = testRandomizeOrderingSeed == 'random'
? Random().nextInt(4294967295)
: int.parse(testRandomizeOrderingSeed).toUnsigned(32);
stdout.writeln('Using seed for test randomization: $seed');

if (package.isFlutterPackage) {
return _runTestsFlutter(
processRunner,
package,
excludeGoldens: excludeGoldens,
onlyGoldens: onlyGoldens,
updateGoldens: updateGoldens,
testRandomizeOrderingSeed: seed,
testRandomizeOrderingSeed: testRandomizeOrderingSeed,
);
} else {
return _runTestsDart(
processRunner,
package,
excludeGoldens: excludeGoldens,
onlyGoldens: onlyGoldens,
testRandomizeOrderingSeed: seed,
testRandomizeOrderingSeed: testRandomizeOrderingSeed,
);
}
}
Expand Down

0 comments on commit 4fcd51a

Please sign in to comment.