| OLD | NEW |
| 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 /** | 5 /** |
| 6 * This test verifies that if reanalysis is performed while reanalysis is in | 6 * This test verifies that if reanalysis is performed while reanalysis is in |
| 7 * progress, no problems occur. | 7 * progress, no problems occur. |
| 8 * | 8 * |
| 9 * See dartbug.com/21448. | 9 * See dartbug.com/21448. |
| 10 */ | 10 */ |
| 11 library test.integration.analysis.reanalyze_concurrent; | 11 library test.integration.analysis.reanalyze_concurrent; |
| 12 | 12 |
| 13 import 'dart:async'; | 13 import 'dart:async'; |
| 14 | 14 |
| 15 import 'package:analysis_server/src/protocol.dart'; | |
| 16 import 'package:unittest/unittest.dart'; | |
| 17 | |
| 18 import '../../reflective_tests.dart'; | 15 import '../../reflective_tests.dart'; |
| 19 import '../integration_tests.dart'; | 16 import '../integration_tests.dart'; |
| 20 | 17 |
| 21 main() { | 18 main() { |
| 22 runReflectiveTests(Test); | 19 runReflectiveTests(Test); |
| 23 } | 20 } |
| 24 | 21 |
| 25 @ReflectiveTestCase() | 22 @ReflectiveTestCase() |
| 26 class Test extends AbstractAnalysisServerIntegrationTest { | 23 class Test extends AbstractAnalysisServerIntegrationTest { |
| 27 test_reanalyze_concurrent() { | 24 test_reanalyze_concurrent() { |
| 28 String pathname = sourcePath('test.dart'); | 25 String pathname = sourcePath('test.dart'); |
| 29 String text = ''' | 26 String text = ''' |
| 30 // Do a bunch of imports so that analysis has some work to do. | 27 // Do a bunch of imports so that analysis has some work to do. |
| 31 import 'dart:io'; | 28 import 'dart:io'; |
| 32 import 'dart:convert'; | 29 import 'dart:convert'; |
| 33 import 'dart:async'; | 30 import 'dart:async'; |
| 34 | 31 |
| 35 main() {}'''; | 32 main() {}'''; |
| 36 writeFile(pathname, text); | 33 writeFile(pathname, text); |
| 37 standardAnalysisSetup(); | 34 standardAnalysisSetup(); |
| 38 return analysisFinished.then((_) { | 35 return analysisFinished.then((_) { |
| 39 sendAnalysisReanalyze(); | 36 sendAnalysisReanalyze(); |
| 40 // Wait for reanalysis to start. | 37 // Wait for reanalysis to start. |
| 41 return onServerStatus.first.then((_) { | 38 return onServerStatus.first.then((_) { |
| 42 sendAnalysisReanalyze(); | 39 sendAnalysisReanalyze(); |
| 43 return analysisFinished.then((_) { | 40 return analysisFinished.then((_) { |
| 44 // Now that reanalysis has finished, no further analysis should occur. | 41 // Now that reanalysis has finished, give the server an extra second |
| 45 onServerStatus.listen((ServerStatusParams data) { | 42 // to make sure it doesn't crash. |
| 46 if (data.analysis != null) { | |
| 47 if (data.analysis.isAnalyzing) { | |
| 48 // Most likely what happened is that the first reanalyze | |
| 49 // completed before the second reanalyze had a chance to start, | |
| 50 // and we are just now starting the second reanalyze. If this | |
| 51 // is the case, then the test isn't testing what it's meant to | |
| 52 // test (because we are trying to test what happens when one | |
| 53 // reanalyze starts while another is in progress). In which | |
| 54 // case we will need to give the analyzer more work to do. | |
| 55 fail('First reanalyze finished before second started.'); | |
| 56 } | |
| 57 } | |
| 58 }); | |
| 59 // Give the server an extra second to make sure it doesn't take any | |
| 60 // more actions. | |
| 61 return new Future.delayed(new Duration(seconds: 1)); | 43 return new Future.delayed(new Duration(seconds: 1)); |
| 62 }); | 44 }); |
| 63 }); | 45 }); |
| 64 }); | 46 }); |
| 65 } | 47 } |
| 66 } | 48 } |
| OLD | NEW |