OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 server.performance; | 5 library server.performance; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
11 | 11 |
12 import '../../test/integration/integration_tests.dart'; | 12 import '../../test/integration/integration_tests.dart'; |
13 | 13 |
14 /** | 14 /** |
15 * Base class for analysis server performance tests. | 15 * Base class for analysis server performance tests. |
16 */ | 16 */ |
17 abstract class AbstractAnalysisServerPerformanceTest | 17 abstract class AbstractAnalysisServerPerformanceTest |
18 extends AbstractAnalysisServerIntegrationTest { | 18 extends AbstractAnalysisServerIntegrationTest { |
19 /** | 19 /** |
20 * Stopwatch for timing results; | 20 * Stopwatch for timing results; |
21 */ | 21 */ |
22 Stopwatch stopwatch = new Stopwatch(); | 22 Stopwatch stopwatch = new Stopwatch(); |
23 | 23 |
24 /** | 24 /** |
25 * Send the server an 'analysis.setAnalysisRoots' command directing it to | 25 * Send the server an 'analysis.setAnalysisRoots' command directing it to |
26 * analyze [sourceDirectory]. | 26 * analyze [sourceDirectory]. |
27 */ | 27 */ |
28 Future setAnalysisRoot() => | 28 Future setAnalysisRoot() => |
29 sendAnalysisSetAnalysisRoots([sourceDirectory.path], []); | 29 sendAnalysisSetAnalysisRoots([sourceDirectory.path], []); |
30 | 30 |
31 /** | 31 /** |
32 * Enable [SERVER_STATUS] notifications so that [analysisFinished] | |
33 * can be used. | |
34 */ | |
35 Future subscribeToStatusNotifications() { | |
36 List<Future> futures = <Future>[]; | |
37 futures.add(sendServerSetSubscriptions([ServerService.STATUS])); | |
38 return Future.wait(futures); | |
39 } | |
40 | |
41 /** | |
42 * The server is automatically started before every test. | 32 * The server is automatically started before every test. |
43 */ | 33 */ |
44 @override | 34 @override |
45 Future setUp() { | 35 Future setUp() { |
46 onAnalysisErrors.listen((AnalysisErrorsParams params) { | 36 onAnalysisErrors.listen((AnalysisErrorsParams params) { |
47 currentAnalysisErrors[params.file] = params.errors; | 37 currentAnalysisErrors[params.file] = params.errors; |
48 }); | 38 }); |
49 onServerError.listen((ServerErrorParams params) { | 39 onServerError.listen((ServerErrorParams params) { |
50 // A server error should never happen during an integration test. | 40 // A server error should never happen during an integration test. |
51 fail('${params.message}\n${params.stackTrace}'); | 41 fail('${params.message}\n${params.stackTrace}'); |
52 }); | 42 }); |
53 Completer serverConnected = new Completer(); | 43 Completer serverConnected = new Completer(); |
54 onServerConnected.listen((_) { | 44 onServerConnected.listen((_) { |
55 expect(serverConnected.isCompleted, isFalse); | 45 expect(serverConnected.isCompleted, isFalse); |
56 serverConnected.complete(); | 46 serverConnected.complete(); |
57 }); | 47 }); |
58 return startServer().then((_) { | 48 return startServer().then((_) { |
59 server.listenToOutput(dispatchNotification); | 49 server.listenToOutput(dispatchNotification); |
60 server.exitCode.then((_) { | 50 server.exitCode.then((_) { |
61 skipShutdown = true; | 51 skipShutdown = true; |
62 }); | 52 }); |
63 return serverConnected.future; | 53 return serverConnected.future; |
64 }); | 54 }); |
65 } | 55 } |
66 | 56 |
67 /** | 57 /** |
| 58 * Enable [SERVER_STATUS] notifications so that [analysisFinished] |
| 59 * can be used. |
| 60 */ |
| 61 Future subscribeToStatusNotifications() { |
| 62 List<Future> futures = <Future>[]; |
| 63 futures.add(sendServerSetSubscriptions([ServerService.STATUS])); |
| 64 return Future.wait(futures); |
| 65 } |
| 66 |
| 67 /** |
68 * After every test, the server is stopped. | 68 * After every test, the server is stopped. |
69 */ | 69 */ |
70 @override | 70 @override |
71 Future tearDown() => shutdownIfNeeded(); | 71 Future tearDown() => shutdownIfNeeded(); |
72 } | 72 } |
OLD | NEW |