Fix flaky tests that require an isolate to be runnable

These tests became flaky after 3786c5e5ee
landed as DDS initialization became faster, making it more likely that
an isolate used in the test was not yet runnable.

Partly fixes https://github.com/dart-lang/sdk/issues/55133

Change-Id: Ic919cfa6c8bf2b8274efecfa2a78bc056f7e181e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356340
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Derek Xu <derekx@google.com>
This commit is contained in:
Ben Konyi 2024-03-07 19:32:34 +00:00 committed by Commit Queue
parent 52f996b5bc
commit 9d043ce763
2 changed files with 23 additions and 9 deletions

View file

@ -346,13 +346,17 @@ class IsolateManager {
final combinedBytes = base64Decode(timelineResult['trace']).toList();
for (final isolateId in isolates.keys) {
final samplesResult =
await dds.vmServiceClient.sendRequest('getPerfettoCpuSamples', {
'isolateId': isolateId,
'timeOriginMicros': timeOriginMicros,
'timeExtentMicros': timeExtentMicros
});
combinedBytes.addAll(base64Decode(samplesResult['samples']));
try {
final samplesResult =
await dds.vmServiceClient.sendRequest('getPerfettoCpuSamples', {
'isolateId': isolateId,
'timeOriginMicros': timeOriginMicros,
'timeExtentMicros': timeExtentMicros
});
combinedBytes.addAll(base64Decode(samplesResult['samples']));
} on json_rpc.RpcException {
// The isolate may not yet be runnable.
}
}
timelineResult['trace'] = base64Encode(combinedBytes);
return timelineResult;

View file

@ -116,8 +116,18 @@ void main() {
);
service = await vmServiceConnectUri(dds!.wsUri!.toString());
final isolate = (await service.getVM()).isolates!.first;
final isolateId = isolate.id!;
final isolateRef = (await service.getVM()).isolates!.first;
final isolateId = isolateRef.id!;
// Wait for the isolate to become runnable as `evaluateInFrame` requires
// the isolate to be runnable.
Isolate? isolate;
do {
if (isolate != null) {
await Future.delayed(const Duration(milliseconds: 50));
}
isolate = await service.getIsolate(isolateId);
} while (!isolate.runnable!);
// Get the variable for 'myInstance'.
final originalInstanceRef = (await service.evaluateInFrame(