Skip to content

Commit 0d90ccc

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Use unique request IDs in tests to avoid flaky tests
Some of the LSP-over-Legacy tests were intermittently failing because the test did not correctly wait for the `setClientCapabilities` request to complete. The reason for this was that it used the ID `0` (from `_newRequestId`) but so did `setAnalysisRoots`. If the timing was right, the second request would appear to complete when the first did (because the response had id=0) and the test would start before the capabilities had actually been set (and since the test reads them directly off the server, they would be incorrect). This moves the `_nextRequestId` field down into a base class and updates the helpers for requests like `setAnalysisRoots` to use it too. Change-Id: Ice44191aad39c7ea81c40e501827557fe563e3d5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405760 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 4fce27b commit 0d90ccc

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

pkg/analysis_server/test/analysis_server_base.dart

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ abstract class ContextResolutionTest with ResourceProviderMixin {
8888
/// implementation are still fully verified.
8989
static final MemoryByteStore _sharedByteStore = MemoryByteStore();
9090

91+
/// The next ID to use in a request to the server.
92+
var nextRequestId = 0;
93+
9194
MemoryByteStore _byteStore = _sharedByteStore;
9295

9396
final TestPluginManager pluginManager = TestPluginManager();
@@ -148,15 +151,21 @@ abstract class ContextResolutionTest with ResourceProviderMixin {
148151
handleSuccessfulRequest(
149152
AnalysisSetPriorityFilesParams(
150153
files.map((e) => e.path).toList(),
151-
).toRequest('0', clientUriConverter: server.uriConverter),
154+
).toRequest(
155+
'${nextRequestId++}',
156+
clientUriConverter: server.uriConverter,
157+
),
152158
);
153159
}
154160

155161
Future<void> setPriorityFiles2(List<File> files) async {
156162
await handleSuccessfulRequest(
157163
AnalysisSetPriorityFilesParams(
158164
files.map((e) => e.path).toList(),
159-
).toRequest('0', clientUriConverter: server.uriConverter),
165+
).toRequest(
166+
'${nextRequestId++}',
167+
clientUriConverter: server.uriConverter,
168+
),
160169
);
161170
}
162171

@@ -171,7 +180,10 @@ abstract class ContextResolutionTest with ResourceProviderMixin {
171180
includedConverted,
172181
excludedConverted,
173182
packageRoots: {},
174-
).toRequest('0', clientUriConverter: server.uriConverter),
183+
).toRequest(
184+
'${nextRequestId++}',
185+
clientUriConverter: server.uriConverter,
186+
),
175187
);
176188
}
177189

@@ -214,9 +226,10 @@ abstract class ContextResolutionTest with ResourceProviderMixin {
214226

215227
Future<void> _setGeneralAnalysisSubscriptions() async {
216228
await handleSuccessfulRequest(
217-
AnalysisSetGeneralSubscriptionsParams(
218-
_analysisGeneralServices,
219-
).toRequest('0', clientUriConverter: server.uriConverter),
229+
AnalysisSetGeneralSubscriptionsParams(_analysisGeneralServices).toRequest(
230+
'${nextRequestId++}',
231+
clientUriConverter: server.uriConverter,
232+
),
220233
);
221234
}
222235
}
@@ -264,9 +277,10 @@ class PubPackageAnalysisServerTest extends ContextResolutionTest
264277
) async {
265278
(_analysisFileSubscriptions[service] ??= []).add(file.path);
266279
await handleSuccessfulRequest(
267-
AnalysisSetSubscriptionsParams(
268-
_analysisFileSubscriptions,
269-
).toRequest('0', clientUriConverter: server.uriConverter),
280+
AnalysisSetSubscriptionsParams(_analysisFileSubscriptions).toRequest(
281+
'${nextRequestId++}',
282+
clientUriConverter: server.uriConverter,
283+
),
270284
);
271285
}
272286

pkg/analysis_server/test/lsp_over_legacy/abstract_lsp_over_legacy.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ abstract class LspOverLegacyTest extends PubPackageAnalysisServerTest
150150
LspEditHelpersMixin,
151151
LspVerifyEditHelpersMixin,
152152
ClientCapabilitiesHelperMixin {
153-
/// The next ID to use a request to the server.
154-
var _nextRequestId = 0;
155-
156153
/// The last ID that was used for a legacy request.
157154
late String lastSentLegacyRequestId;
158155

@@ -207,7 +204,7 @@ abstract class LspOverLegacyTest extends PubPackageAnalysisServerTest
207204
AnalysisUpdateContentParams({
208205
convertPath(filePath): AddContentOverlay(content),
209206
}).toRequest(
210-
'${_nextRequestId++}',
207+
'${nextRequestId++}',
211208
clientUriConverter: server.uriConverter,
212209
),
213210
);
@@ -241,7 +238,7 @@ abstract class LspOverLegacyTest extends PubPackageAnalysisServerTest
241238
/// Creates a legacy request with an auto-assigned ID.
242239
Request createLegacyRequest(RequestParams params) {
243240
return params.toRequest(
244-
'${_nextRequestId++}',
241+
'${nextRequestId++}',
245242
clientUriConverter: server.uriConverter,
246243
);
247244
}
@@ -323,7 +320,7 @@ abstract class LspOverLegacyTest extends PubPackageAnalysisServerTest
323320
AnalysisUpdateContentParams({
324321
convertPath(filePath): RemoveContentOverlay(),
325322
}).toRequest(
326-
'${_nextRequestId++}',
323+
'${nextRequestId++}',
327324
clientUriConverter: server.uriConverter,
328325
),
329326
);
@@ -341,7 +338,7 @@ abstract class LspOverLegacyTest extends PubPackageAnalysisServerTest
341338
var request = ServerSetClientCapabilitiesParams(
342339
[],
343340
lspCapabilities: clientCapabilities,
344-
).toRequest('${_nextRequestId++}', clientUriConverter: server.uriConverter);
341+
).toRequest('${nextRequestId++}', clientUriConverter: server.uriConverter);
345342

346343
await handleSuccessfulRequest(request);
347344
}
@@ -377,7 +374,7 @@ abstract class LspOverLegacyTest extends PubPackageAnalysisServerTest
377374
AnalysisUpdateContentParams({
378375
convertPath(filePath): ChangeContentOverlay([edit]),
379376
}).toRequest(
380-
'${_nextRequestId++}',
377+
'${nextRequestId++}',
381378
clientUriConverter: server.uriConverter,
382379
),
383380
);

0 commit comments

Comments
 (0)