wait for SDK suggestions

Change-Id: I7439daff3bf828406520a5a3c061928695258c84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135240
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/test/client/completion_driver_test.dart b/pkg/analysis_server/test/client/completion_driver_test.dart
index ecdaec7..d207b6e 100644
--- a/pkg/analysis_server/test/client/completion_driver_test.dart
+++ b/pkg/analysis_server/test/client/completion_driver_test.dart
@@ -47,6 +47,21 @@
   }
 
   Future<List<CompletionSuggestion>> getSuggestions() async {
+    if (supportsAvailableSuggestions) {
+      // todo (pq): consider moving
+      const internalLibs = [
+        'dart:async2',
+        'dart:_interceptors',
+        'dart:_internal',
+      ];
+      for (var lib in driver.sdk.sdkLibraries) {
+        var uri = lib.shortName;
+        if (!internalLibs.contains(uri)) {
+          await driver.waitForSetWithUri(uri);
+        }
+      }
+    }
+
     suggestions = await driver.getSuggestions();
     return suggestions;
   }
@@ -177,7 +192,26 @@
 }
 ''');
 
-    // todo (pq): replace with a "real test"; this just proves we're getting end to end.
+    // A set of SDK suggestions.
+    expect(
+        // from dart:async (StreamSubscription)
+        suggestionWith(
+            completion: 'asFuture', kind: CompletionSuggestionKind.INVOCATION),
+        isNotNull);
+
+    expect(
+        // from dart:core
+        suggestionWith(
+            completion: 'print', kind: CompletionSuggestionKind.INVOCATION),
+        isNotNull);
+
+    expect(
+        // from dart:collection (ListMixin)
+        suggestionWith(
+            completion: 'firstWhere',
+            kind: CompletionSuggestionKind.INVOCATION),
+        isNotNull);
+
     expect(
         // from dart:math
         suggestionWith(
diff --git a/pkg/analysis_server/test/client/impl/abstract_client.dart b/pkg/analysis_server/test/client/impl/abstract_client.dart
index afe85d1..3c5286b 100644
--- a/pkg/analysis_server/test/client/impl/abstract_client.dart
+++ b/pkg/analysis_server/test/client/impl/abstract_client.dart
@@ -35,6 +35,8 @@
   final String testFilePath;
   String testCode;
 
+  MockSdk sdk;
+
   AbstractClient({
     @required this.projectPath,
     @required this.testFilePath,
@@ -100,7 +102,7 @@
 
   /// Create an analysis server with the given [sdkPath].
   AnalysisServer createAnalysisServer(String sdkPath) {
-    MockSdk(resourceProvider: resourceProvider);
+    sdk = MockSdk(resourceProvider: resourceProvider);
     var options = AnalysisServerOptions();
     return AnalysisServer(serverChannel, resourceProvider, options,
         DartSdkManager(sdkPath, true), InstrumentationService.NULL_SERVICE);