Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: pkg/analysis_server/test/domain_completion_test.dart

Issue 2876793006: improve code completion abort request tests (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/domain_completion.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.domain.completion; 5 library test.domain.completion;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/protocol/protocol.dart'; 9 import 'package:analysis_server/protocol/protocol.dart';
10 import 'package:analysis_server/protocol/protocol_generated.dart'; 10 import 'package:analysis_server/protocol/protocol_generated.dart';
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 277
278 test_imports_aborted_new_request() async { 278 test_imports_aborted_new_request() async {
279 addTestFile(''' 279 addTestFile('''
280 class foo { } 280 class foo { }
281 c^'''); 281 c^''');
282 282
283 // Make a request for suggestions 283 // Make a request for suggestions
284 Request request1 = 284 Request request1 =
285 new CompletionGetSuggestionsParams(testFile, completionOffset) 285 new CompletionGetSuggestionsParams(testFile, completionOffset)
286 .toRequest('7'); 286 .toRequest('7');
287 Response response1 = await waitResponse(request1); 287 Future<Response> responseFuture1 = waitResponse(request1);
288 var result1 = new CompletionGetSuggestionsResult.fromResponse(response1);
289 var completionId1 = result1.id;
290 assertValidId(completionId1);
291
292 // Perform some analysis but assert that no suggestions have yet been made
293 completionId = completionId1;
294 await pumpEventQueue(25);
295 expect(suggestionsDone, isFalse);
296 expect(suggestions, hasLength(0));
297 288
298 // Make another request before the first request completes 289 // Make another request before the first request completes
299 Request request2 = 290 Request request2 =
300 new CompletionGetSuggestionsParams(testFile, completionOffset) 291 new CompletionGetSuggestionsParams(testFile, completionOffset)
301 .toRequest('8'); 292 .toRequest('8');
302 Response response2 = await waitResponse(request2); 293 Future<Response> responseFuture2 = waitResponse(request2);
294
295 // Await first response
296 Response response1 = await responseFuture1;
297 var result1 = new CompletionGetSuggestionsResult.fromResponse(response1);
298 assertValidId(result1.id);
299
300 // Await second response
301 Response response2 = await responseFuture2;
303 var result2 = new CompletionGetSuggestionsResult.fromResponse(response2); 302 var result2 = new CompletionGetSuggestionsResult.fromResponse(response2);
304 var completionId2 = result2.id; 303 assertValidId(result2.id);
305 assertValidId(completionId2);
306 304
307 // Wait for both sets of suggestions 305 // Wait for all processing to be complete
308 completionId = completionId2; 306 await analysisHandler.server.analysisDriverScheduler.waitForIdle();
309 await pumpEventQueue(); 307 await pumpEventQueue();
310 expect(allSuggestions[completionId1], hasLength(0)); 308
311 expect(allSuggestions[completionId2], same(suggestions)); 309 // Assert that first request has been aborted
310 expect(allSuggestions[result1.id], hasLength(0));
311
312 // Assert valid results for the second request
313 expect(allSuggestions[result2.id], same(suggestions));
312 assertHasResult(CompletionSuggestionKind.KEYWORD, 'class', 314 assertHasResult(CompletionSuggestionKind.KEYWORD, 'class',
313 relevance: DART_RELEVANCE_HIGH); 315 relevance: DART_RELEVANCE_HIGH);
314 } 316 }
315 317
316 @failingTest 318 @failingTest
317 test_imports_aborted_source_changed() async { 319 test_imports_aborted_source_changed() async {
318 // TODO(brianwilkerson) Figure out whether this test makes sense when 320 // TODO(brianwilkerson) Figure out whether this test makes sense when
319 // running the new driver. It waits for an initial empty notification then 321 // running the new driver. It waits for an initial empty notification then
320 // waits for a new notification. But I think that under the driver we only 322 // waits for a new notification. But I think that under the driver we only
321 // ever send one notification. 323 // ever send one notification.
322 addTestFile(''' 324 addTestFile('''
323 class foo { } 325 class foo { }
324 c^'''); 326 c^''');
325 327
326 // Make a request for suggestions 328 // Make a request for suggestions
327 Request request = 329 Request request =
328 new CompletionGetSuggestionsParams(testFile, completionOffset) 330 new CompletionGetSuggestionsParams(testFile, completionOffset)
329 .toRequest('0'); 331 .toRequest('0');
330 Response response = await waitResponse(request); 332 Future<Response> responseFuture = waitResponse(request);
331 completionId = response.id;
332 assertValidId(completionId);
333
334 // Perform some analysis but assert that no suggestions have yet been made
335 await pumpEventQueue(25);
336 expect(suggestionsDone, isFalse);
337 expect(suggestions, hasLength(0));
338 333
339 // Simulate user deleting text after request but before suggestions returned 334 // Simulate user deleting text after request but before suggestions returned
340 server.updateContent('uc1', {testFile: new AddContentOverlay(testCode)}); 335 server.updateContent('uc1', {testFile: new AddContentOverlay(testCode)});
341 server.updateContent('uc2', { 336 server.updateContent('uc2', {
342 testFile: new ChangeContentOverlay( 337 testFile: new ChangeContentOverlay(
343 [new SourceEdit(completionOffset - 1, 1, '')]) 338 [new SourceEdit(completionOffset - 1, 1, '')])
344 }); 339 });
345 340
346 // Expect the completion domain to discard request because source changed 341 // Await a response
347 await pumpEventQueue().then((_) { 342 Response response = await responseFuture;
348 expect(suggestionsDone, isTrue); 343 completionId = response.id;
349 }); 344 assertValidId(completionId);
345
346 // Wait for all processing to be complete
347 await analysisHandler.server.analysisDriverScheduler.waitForIdle();
348 await pumpEventQueue();
349
350 // Assert that request has been aborted
351 expect(suggestionsDone, isTrue);
350 expect(suggestions, hasLength(0)); 352 expect(suggestions, hasLength(0));
351 } 353 }
352 354
353 test_imports_incremental() async { 355 test_imports_incremental() async {
354 addTestFile('''library foo; 356 addTestFile('''library foo;
355 e^ 357 e^
356 import "dart:async"; 358 import "dart:async";
357 import "package:foo/foo.dart"; 359 import "package:foo/foo.dart";
358 class foo { }'''); 360 class foo { }''');
359 await waitForTasksFinished(); 361 await waitForTasksFinished();
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 780
779 @override 781 @override
780 Future sort( 782 Future sort(
781 CompletionRequest request, Iterable<CompletionSuggestion> suggestions) { 783 CompletionRequest request, Iterable<CompletionSuggestion> suggestions) {
782 if (!enabled) { 784 if (!enabled) {
783 throw 'unexpected sort'; 785 throw 'unexpected sort';
784 } 786 }
785 return new Future.value(); 787 return new Future.value();
786 } 788 }
787 } 789 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/domain_completion.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698