Files
sdk/pkg/analysis_server/test/lsp/server_test.dart
T
Danny Tuppeny 73e544ed0b Improve errors when LSP integration tests fail to spawn server
When the server fails to start up (writing to stderr) the tests currently would just hang waiting for responses to messages. This will just throw the message as an exception, failing the test with a more useful message, for example:

```
00:07 +0 -1: ServerTest | test_exit_afterShutdown [E]
  Analysis Server wrote to stderr:

  file:///Users/dantup/Dev/Google/dart-sdk/sdk/third_party/pkg/linter/lib/src/analyzer.dart:106:27: Error: The method 'registerDefault' isn't defined for the class 'Registry'.
   - 'Registry' is from 'package:analyzer/src/lint/registry.dart' ('file:///Users/dantup/Dev/Google/dart-sdk/sdk/pkg/analyzer/lib/src/lint/registry.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'registerDefault'.
      Registry.ruleRegistry.registerDefault(lint);
                            ^^^^^^^^^^^^^^^
```

Change-Id: If64b68b17a0d379f8879891f0346704d4ad360e8

Remove unused imports

Change-Id: I745499f7b038c81320c127410967d939c7756e51
Reviewed-on: https://dart-review.googlesource.com/c/94222
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Danny Tuppeny <dantup@google.com>
2019-02-25 17:13:52 +00:00

105 lines
3.4 KiB
Dart

// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/lsp_protocol/protocol_generated.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'server_abstract.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ServerTest);
});
}
@reflectiveTest
class ServerTest extends AbstractLspAnalysisServerTest {
test_inconsistentStateError() async {
await initialize();
await openFile(mainFileUri, '');
// Attempt to make an illegal modification to the file. This indicates the
// client and server are out of sync and we expect the server to shut down.
final error = await expectErrorNotification<ShowMessageParams>(() async {
await changeFile(222, mainFileUri, [
new TextDocumentContentChangeEvent(
new Range(new Position(99, 99), new Position(99, 99)), null, ' '),
]);
});
expect(error, isNotNull);
expect(error.message, contains('Invalid line'));
// Wait for up to 10 seconds for the server to shutdown.
await server.exited.timeout(const Duration(seconds: 10));
}
test_shutdown_initialized() async {
await initialize();
final response = await sendShutdown();
expect(response, isNull);
}
test_shutdown_uninitialized() async {
final response = await sendShutdown();
expect(response, isNull);
}
test_unknownNotifications_logError() async {
await initialize();
final notification =
makeNotification(new Method.fromJson(r'some/randomNotification'), null);
final notificationParams = await expectErrorNotification<ShowMessageParams>(
() => channel.sendNotificationToServer(notification),
);
expect(notificationParams, isNotNull);
expect(
notificationParams.message,
contains('Unknown method some/randomNotification'),
);
}
test_unknownOptionalNotifications_silentlyDropped() async {
await initialize();
final notification =
makeNotification(new Method.fromJson(r'$/randomNotification'), null);
final firstError = errorNotificationsFromServer.first;
channel.sendNotificationToServer(notification);
// Wait up to 1sec to ensure no error/log notifications were sent back.
var didTimeout = false;
final notificationFromServer = await firstError.timeout(
const Duration(seconds: 1),
onTimeout: () {
didTimeout = true;
},
);
expect(notificationFromServer, isNull);
expect(didTimeout, isTrue);
}
test_unknownRequest_rejected() async {
await initialize();
final request = makeRequest(new Method.fromJson('randomRequest'), null);
final response = await channel.sendRequestToServer(request);
expect(response.id, equals(request.id));
expect(response.error, isNotNull);
expect(response.error.code, equals(ErrorCodes.MethodNotFound));
expect(response.result, isNull);
}
test_unknownOptionalRequest_rejected() async {
await initialize();
final request = makeRequest(new Method.fromJson(r'$/randomRequest'), null);
final response = await channel.sendRequestToServer(request);
expect(response.id, equals(request.id));
expect(response.error, isNotNull);
expect(response.error.code, equals(ErrorCodes.MethodNotFound));
expect(response.result, isNull);
}
}