fix race condition between vm test compilation and isolate spawning (#1517)

Fixes #1516
diff --git a/pkgs/test/CHANGELOG.md b/pkgs/test/CHANGELOG.md
index e990855..1eedb1a 100644
--- a/pkgs/test/CHANGELOG.md
+++ b/pkgs/test/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.17.4
+
+* Fix race condition between compilation of vm tests and the running of
+  isolates.
+
 ## 1.17.3
 
 * Forward experiment args from the runner executable to the compiler with the
diff --git a/pkgs/test/pubspec.yaml b/pkgs/test/pubspec.yaml
index f202459..62952cc 100644
--- a/pkgs/test/pubspec.yaml
+++ b/pkgs/test/pubspec.yaml
@@ -1,5 +1,5 @@
 name: test
-version: 1.17.3
+version: 1.17.4
 description: >-
   A full featured library for writing and running Dart tests across platforms.
 repository: https://github.com/dart-lang/test/blob/master/pkgs/test
@@ -34,7 +34,7 @@
   yaml: ^3.0.0
   # Use an exact version until the test_api and test_core package are stable.
   test_api: 0.4.0
-  test_core: 0.3.23
+  test_core: 0.3.24
 
 dev_dependencies:
   fake_async: ^1.0.0
diff --git a/pkgs/test_core/CHANGELOG.md b/pkgs/test_core/CHANGELOG.md
index c483115..b791e0c 100644
--- a/pkgs/test_core/CHANGELOG.md
+++ b/pkgs/test_core/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 0.3.24
+
+* Fix race condition between compilation of vm tests and the running of
+  isolates.
+
 ## 0.3.23
 
 * Forward experiment args from the runner executable to the compiler with the
diff --git a/pkgs/test_core/lib/src/runner/vm/test_compiler.dart b/pkgs/test_core/lib/src/runner/vm/test_compiler.dart
index 6498002..f681c27 100644
--- a/pkgs/test_core/lib/src/runner/vm/test_compiler.dart
+++ b/pkgs/test_core/lib/src/runner/vm/test_compiler.dart
@@ -73,6 +73,8 @@
       File(p.join(_outputDillDirectory.path, 'output.dill'));
   final _outputDillDirectory =
       Directory.systemTemp.createTempSync('dart_test.');
+  // Used to create unique file names for final kernel files.
+  int _compileNumber = 0;
 
   _TestCompilerForLanguageVersion(
       String dillCachePrefix, this._languageVersionComment)
@@ -98,6 +100,7 @@
       _compilePool.withResource(() => _compile(mainUri));
 
   Future<CompilationResponse> _compile(Uri mainUri) async {
+    _compileNumber++;
     if (_closeMemo.hasRun) return CompilationResponse._wasShutdown;
     var firstCompile = false;
     CompileResult? compilerOutput;
@@ -129,7 +132,8 @@
     }
 
     final outputFile = File(outputPath);
-    final kernelReadyToRun = await outputFile.copy('${tempFile.path}.dill');
+    final kernelReadyToRun =
+        await outputFile.copy('${tempFile.path}_$_compileNumber.dill');
     final testCache = File(_dillCachePath);
     // Keep the cache file up-to-date and use the size of the kernel file
     // as an approximation for how many packages are included. Larger files
diff --git a/pkgs/test_core/pubspec.yaml b/pkgs/test_core/pubspec.yaml
index eb9b671..2ae534d 100644
--- a/pkgs/test_core/pubspec.yaml
+++ b/pkgs/test_core/pubspec.yaml
@@ -1,5 +1,5 @@
 name: test_core
-version: 0.3.23
+version: 0.3.24
 description: A basic library for writing tests and running them on the VM.
 homepage: https://github.com/dart-lang/test/blob/master/pkgs/test_core