| 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 test.src.task.driver_test; | 5 library test.src.task.driver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart' | 8 import 'package:analyzer/src/generated/engine.dart' |
| 9 hide | 9 hide |
| 10 AnalysisCache, | 10 AnalysisCache, |
| 11 AnalysisContextImpl, | 11 AnalysisContextImpl, |
| 12 AnalysisTask, | 12 AnalysisTask, |
| 13 UniversalCachePartition, | 13 UniversalCachePartition, |
| 14 WorkManager; | 14 WorkManager; |
| 15 import 'package:analyzer/src/generated/java_engine.dart'; | 15 import 'package:analyzer/src/generated/java_engine.dart'; |
| 16 import 'package:analyzer/src/task/driver.dart'; | 16 import 'package:analyzer/src/task/driver.dart'; |
| 17 import 'package:analyzer/src/task/inputs.dart'; | 17 import 'package:analyzer/src/task/inputs.dart'; |
| 18 import 'package:analyzer/src/task/manager.dart'; | 18 import 'package:analyzer/src/task/manager.dart'; |
| 19 import 'package:analyzer/task/model.dart'; | 19 import 'package:analyzer/task/model.dart'; |
| 20 import 'package:typed_mock/typed_mock.dart'; | 20 import 'package:typed_mock/typed_mock.dart'; |
| 21 import 'package:unittest/unittest.dart'; | 21 import 'package:unittest/unittest.dart'; |
| 22 | 22 |
| 23 import '../../generated/test_support.dart'; | 23 import '../../generated/test_support.dart'; |
| 24 import '../../reflective_tests.dart'; | 24 import '../../reflective_tests.dart'; |
| 25 import '../../utils.dart'; |
| 25 import 'test_support.dart'; | 26 import 'test_support.dart'; |
| 26 | 27 |
| 27 main() { | 28 main() { |
| 28 groupSep = ' | '; | 29 initializeTestEnvironment(); |
| 29 runReflectiveTests(AnalysisDriverTest); | 30 runReflectiveTests(AnalysisDriverTest); |
| 30 runReflectiveTests(CycleAwareDependencyWalkerTest); | 31 runReflectiveTests(CycleAwareDependencyWalkerTest); |
| 31 runReflectiveTests(WorkItemTest); | 32 runReflectiveTests(WorkItemTest); |
| 32 runReflectiveTests(WorkOrderTest); | 33 runReflectiveTests(WorkOrderTest); |
| 33 } | 34 } |
| 34 | 35 |
| 35 class AbstractDriverTest { | 36 class AbstractDriverTest { |
| 36 TaskManager taskManager = new TaskManager(); | 37 TaskManager taskManager = new TaskManager(); |
| 37 List<WorkManager> workManagers = <WorkManager>[]; | 38 List<WorkManager> workManagers = <WorkManager>[]; |
| 38 InternalAnalysisContext context = new _InternalAnalysisContextMock(); | 39 InternalAnalysisContext context = new _InternalAnalysisContextMock(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 .thenReturn(WorkOrderPriority.NONE); | 126 .thenReturn(WorkOrderPriority.NONE); |
| 126 when(workManager2.getNextResultPriority()) | 127 when(workManager2.getNextResultPriority()) |
| 127 .thenReturn(WorkOrderPriority.NONE); | 128 .thenReturn(WorkOrderPriority.NONE); |
| 128 expect(analysisDriver.createNextWorkOrder(), isNull); | 129 expect(analysisDriver.createNextWorkOrder(), isNull); |
| 129 } | 130 } |
| 130 | 131 |
| 131 test_createWorkOrderForResult_error() { | 132 test_createWorkOrderForResult_error() { |
| 132 AnalysisTarget target = new TestSource(); | 133 AnalysisTarget target = new TestSource(); |
| 133 ResultDescriptor result = new ResultDescriptor('result', null); | 134 ResultDescriptor result = new ResultDescriptor('result', null); |
| 134 CaughtException exception = new CaughtException(null, null); | 135 CaughtException exception = new CaughtException(null, null); |
| 135 context.getCacheEntry(target).setErrorState( | 136 context |
| 136 exception, <ResultDescriptor>[result]); | 137 .getCacheEntry(target) |
| 138 .setErrorState(exception, <ResultDescriptor>[result]); |
| 137 | 139 |
| 138 expect(analysisDriver.createWorkOrderForResult(target, result), isNull); | 140 expect(analysisDriver.createWorkOrderForResult(target, result), isNull); |
| 139 } | 141 } |
| 140 | 142 |
| 141 test_createWorkOrderForResult_inProcess() { | 143 test_createWorkOrderForResult_inProcess() { |
| 142 AnalysisTarget target = new TestSource(); | 144 AnalysisTarget target = new TestSource(); |
| 143 ResultDescriptor result = new ResultDescriptor('result', null); | 145 ResultDescriptor result = new ResultDescriptor('result', null); |
| 144 context.getCacheEntry(target).setState(result, CacheState.IN_PROCESS); | 146 context.getCacheEntry(target).setState(result, CacheState.IN_PROCESS); |
| 145 | 147 |
| 146 expect(analysisDriver.createWorkOrderForResult(target, result), isNull); | 148 expect(analysisDriver.createWorkOrderForResult(target, result), isNull); |
| 147 } | 149 } |
| 148 | 150 |
| 149 test_createWorkOrderForResult_invalid() { | 151 test_createWorkOrderForResult_invalid() { |
| 150 AnalysisTarget target = new TestSource(); | 152 AnalysisTarget target = new TestSource(); |
| 151 ResultDescriptor result = new ResultDescriptor('result', null); | 153 ResultDescriptor result = new ResultDescriptor('result', null); |
| 152 TaskDescriptor descriptor = new TaskDescriptor('task', | 154 TaskDescriptor descriptor = new TaskDescriptor( |
| 155 'task', |
| 153 (context, target) => new TestAnalysisTask(context, target), | 156 (context, target) => new TestAnalysisTask(context, target), |
| 154 (target) => {}, [result]); | 157 (target) => {}, |
| 158 [result]); |
| 155 taskManager.addTaskDescriptor(descriptor); | 159 taskManager.addTaskDescriptor(descriptor); |
| 156 context.getCacheEntry(target).setState(result, CacheState.INVALID); | 160 context.getCacheEntry(target).setState(result, CacheState.INVALID); |
| 157 | 161 |
| 158 WorkOrder workOrder = | 162 WorkOrder workOrder = |
| 159 analysisDriver.createWorkOrderForResult(target, result); | 163 analysisDriver.createWorkOrderForResult(target, result); |
| 160 expect(workOrder, isNotNull); | 164 expect(workOrder, isNotNull); |
| 161 } | 165 } |
| 162 | 166 |
| 163 test_createWorkOrderForResult_valid() { | 167 test_createWorkOrderForResult_valid() { |
| 164 AnalysisTarget target = new TestSource(); | 168 AnalysisTarget target = new TestSource(); |
| 165 ResultDescriptor result = new ResultDescriptor('result', null); | 169 ResultDescriptor result = new ResultDescriptor('result', null); |
| 166 context.getCacheEntry(target).setValue( | 170 context |
| 167 result, '', TargetedResult.EMPTY_LIST); | 171 .getCacheEntry(target) |
| 172 .setValue(result, '', TargetedResult.EMPTY_LIST); |
| 168 | 173 |
| 169 expect(analysisDriver.createWorkOrderForResult(target, result), isNull); | 174 expect(analysisDriver.createWorkOrderForResult(target, result), isNull); |
| 170 } | 175 } |
| 171 | 176 |
| 172 test_createWorkOrderForTarget_complete_generalTarget_generalResult() { | 177 test_createWorkOrderForTarget_complete_generalTarget_generalResult() { |
| 173 _createWorkOrderForTarget(true, false, false); | 178 _createWorkOrderForTarget(true, false, false); |
| 174 } | 179 } |
| 175 | 180 |
| 176 test_createWorkOrderForTarget_complete_generalTarget_priorityResult() { | 181 test_createWorkOrderForTarget_complete_generalTarget_priorityResult() { |
| 177 _createWorkOrderForTarget(true, false, true); | 182 _createWorkOrderForTarget(true, false, true); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 expect(analysisDriver.performAnalysisTask(), false); | 218 expect(analysisDriver.performAnalysisTask(), false); |
| 214 } | 219 } |
| 215 | 220 |
| 216 test_performAnalysisTask_infiniteLoop_handled() { | 221 test_performAnalysisTask_infiniteLoop_handled() { |
| 217 AnalysisTarget target = new TestSource(); | 222 AnalysisTarget target = new TestSource(); |
| 218 ResultDescriptor resultA = new ResultDescriptor('resultA', -1); | 223 ResultDescriptor resultA = new ResultDescriptor('resultA', -1); |
| 219 ResultDescriptor resultB = new ResultDescriptor('resultB', -2); | 224 ResultDescriptor resultB = new ResultDescriptor('resultB', -2); |
| 220 // configure tasks | 225 // configure tasks |
| 221 TestAnalysisTask task1; | 226 TestAnalysisTask task1; |
| 222 TestAnalysisTask task2; | 227 TestAnalysisTask task2; |
| 223 TaskDescriptor descriptor1 = new TaskDescriptor('task1', | 228 TaskDescriptor descriptor1 = new TaskDescriptor( |
| 224 (context, target) => task1, (target) => { | 229 'task1', |
| 225 'inputB': new SimpleTaskInput<int>(target, resultB) | 230 (context, target) => task1, |
| 226 }, [resultA]); | 231 (target) => {'inputB': new SimpleTaskInput<int>(target, resultB)}, |
| 227 TaskDescriptor descriptor2 = new TaskDescriptor('task2', | 232 [resultA]); |
| 228 (context, target) => task2, (target) => { | 233 TaskDescriptor descriptor2 = new TaskDescriptor( |
| 229 'inputA': new SimpleTaskInput<int>(target, resultA) | 234 'task2', |
| 230 }, [resultB]); | 235 (context, target) => task2, |
| 236 (target) => {'inputA': new SimpleTaskInput<int>(target, resultA)}, |
| 237 [resultB]); |
| 231 task1 = new TestAnalysisTask(context, target, | 238 task1 = new TestAnalysisTask(context, target, |
| 232 descriptor: descriptor1, | 239 descriptor: descriptor1, |
| 233 results: [resultA], | 240 results: [resultA], |
| 234 value: 10, | 241 value: 10, |
| 235 handlesDependencyCycles: true); | 242 handlesDependencyCycles: true); |
| 236 task2 = new TestAnalysisTask(context, target, | 243 task2 = new TestAnalysisTask(context, target, |
| 237 descriptor: descriptor2, | 244 descriptor: descriptor2, |
| 238 results: [resultB], | 245 results: [resultB], |
| 239 value: 20, | 246 value: 20, |
| 240 handlesDependencyCycles: true); | 247 handlesDependencyCycles: true); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 260 expect(context.getCacheEntry(target).getValue(resultB), 20); | 267 expect(context.getCacheEntry(target).getValue(resultB), 20); |
| 261 } | 268 } |
| 262 | 269 |
| 263 test_performAnalysisTask_infiniteLoop_unhandled() { | 270 test_performAnalysisTask_infiniteLoop_unhandled() { |
| 264 AnalysisTarget target = new TestSource(); | 271 AnalysisTarget target = new TestSource(); |
| 265 ResultDescriptor resultA = new ResultDescriptor('resultA', -1); | 272 ResultDescriptor resultA = new ResultDescriptor('resultA', -1); |
| 266 ResultDescriptor resultB = new ResultDescriptor('resultB', -2); | 273 ResultDescriptor resultB = new ResultDescriptor('resultB', -2); |
| 267 // configure tasks | 274 // configure tasks |
| 268 TestAnalysisTask task1; | 275 TestAnalysisTask task1; |
| 269 TestAnalysisTask task2; | 276 TestAnalysisTask task2; |
| 270 TaskDescriptor descriptor1 = new TaskDescriptor('task1', | 277 TaskDescriptor descriptor1 = new TaskDescriptor( |
| 271 (context, target) => task1, (target) => { | 278 'task1', |
| 272 'inputB': new SimpleTaskInput<int>(target, resultB) | 279 (context, target) => task1, |
| 273 }, [resultA]); | 280 (target) => {'inputB': new SimpleTaskInput<int>(target, resultB)}, |
| 274 TaskDescriptor descriptor2 = new TaskDescriptor('task2', | 281 [resultA]); |
| 275 (context, target) => task2, (target) => { | 282 TaskDescriptor descriptor2 = new TaskDescriptor( |
| 276 'inputA': new SimpleTaskInput<int>(target, resultA) | 283 'task2', |
| 277 }, [resultB]); | 284 (context, target) => task2, |
| 285 (target) => {'inputA': new SimpleTaskInput<int>(target, resultA)}, |
| 286 [resultB]); |
| 278 task1 = new TestAnalysisTask(context, target, descriptor: descriptor1); | 287 task1 = new TestAnalysisTask(context, target, descriptor: descriptor1); |
| 279 task2 = new TestAnalysisTask(context, target, descriptor: descriptor2); | 288 task2 = new TestAnalysisTask(context, target, descriptor: descriptor2); |
| 280 taskManager.addTaskDescriptor(descriptor1); | 289 taskManager.addTaskDescriptor(descriptor1); |
| 281 taskManager.addTaskDescriptor(descriptor2); | 290 taskManager.addTaskDescriptor(descriptor2); |
| 282 // configure WorkManager | 291 // configure WorkManager |
| 283 when(workManager1.getNextResultPriority()).thenReturnList( | 292 when(workManager1.getNextResultPriority()).thenReturnList( |
| 284 <WorkOrderPriority>[WorkOrderPriority.NORMAL, WorkOrderPriority.NONE]); | 293 <WorkOrderPriority>[WorkOrderPriority.NORMAL, WorkOrderPriority.NONE]); |
| 285 when(workManager1.getNextResult()) | 294 when(workManager1.getNextResult()) |
| 286 .thenReturn(new TargetedResult(target, resultB)); | 295 .thenReturn(new TargetedResult(target, resultB)); |
| 287 // prepare work order | 296 // prepare work order |
| 288 expect(analysisDriver.performAnalysisTask(), true); | 297 expect(analysisDriver.performAnalysisTask(), true); |
| 289 expect(analysisDriver.performAnalysisTask(), true); | 298 expect(analysisDriver.performAnalysisTask(), true); |
| 290 CaughtException exception = context.getCacheEntry(target).exception; | 299 CaughtException exception = context.getCacheEntry(target).exception; |
| 291 expect(exception, isNotNull); | 300 expect(exception, isNotNull); |
| 292 expect(exception.exception, new isInstanceOf<InfiniteTaskLoopException>()); | 301 expect(exception.exception, new isInstanceOf<InfiniteTaskLoopException>()); |
| 293 } | 302 } |
| 294 | 303 |
| 295 test_performAnalysisTask_inputsFirst() { | 304 test_performAnalysisTask_inputsFirst() { |
| 296 AnalysisTarget target = new TestSource(); | 305 AnalysisTarget target = new TestSource(); |
| 297 ResultDescriptor resultA = new ResultDescriptor('resultA', -1); | 306 ResultDescriptor resultA = new ResultDescriptor('resultA', -1); |
| 298 ResultDescriptor resultB = new ResultDescriptor('resultB', -2); | 307 ResultDescriptor resultB = new ResultDescriptor('resultB', -2); |
| 299 // configure tasks | 308 // configure tasks |
| 300 TestAnalysisTask task1; | 309 TestAnalysisTask task1; |
| 301 TestAnalysisTask task2; | 310 TestAnalysisTask task2; |
| 302 TaskDescriptor descriptor1 = new TaskDescriptor( | 311 TaskDescriptor descriptor1 = new TaskDescriptor( |
| 303 'task1', (context, target) => task1, (target) => {}, [resultA]); | 312 'task1', (context, target) => task1, (target) => {}, [resultA]); |
| 304 TaskDescriptor descriptor2 = new TaskDescriptor('task2', | 313 TaskDescriptor descriptor2 = new TaskDescriptor( |
| 305 (context, target) => task2, (target) => { | 314 'task2', |
| 306 'inputA': new SimpleTaskInput<int>(target, resultA) | 315 (context, target) => task2, |
| 307 }, [resultB]); | 316 (target) => {'inputA': new SimpleTaskInput<int>(target, resultA)}, |
| 317 [resultB]); |
| 308 task1 = new TestAnalysisTask(context, target, | 318 task1 = new TestAnalysisTask(context, target, |
| 309 descriptor: descriptor1, results: [resultA], value: 10); | 319 descriptor: descriptor1, results: [resultA], value: 10); |
| 310 task2 = new TestAnalysisTask(context, target, | 320 task2 = new TestAnalysisTask(context, target, |
| 311 descriptor: descriptor2, value: 20); | 321 descriptor: descriptor2, value: 20); |
| 312 taskManager.addTaskDescriptor(descriptor1); | 322 taskManager.addTaskDescriptor(descriptor1); |
| 313 taskManager.addTaskDescriptor(descriptor2); | 323 taskManager.addTaskDescriptor(descriptor2); |
| 314 // configure WorkManager | 324 // configure WorkManager |
| 315 when(workManager1.getNextResultPriority()).thenReturnList( | 325 when(workManager1.getNextResultPriority()).thenReturnList( |
| 316 <WorkOrderPriority>[WorkOrderPriority.NORMAL, WorkOrderPriority.NONE]); | 326 <WorkOrderPriority>[WorkOrderPriority.NORMAL, WorkOrderPriority.NONE]); |
| 317 when(workManager1.getNextResult()) | 327 when(workManager1.getNextResult()) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 393 |
| 384 analysisDriver.performWorkItem(item); | 394 analysisDriver.performWorkItem(item); |
| 385 CacheEntry targetEntry = context.getCacheEntry(item.target); | 395 CacheEntry targetEntry = context.getCacheEntry(item.target); |
| 386 expect(targetEntry.exception, isNull); | 396 expect(targetEntry.exception, isNull); |
| 387 expect(targetEntry.getState(result), CacheState.VALID); | 397 expect(targetEntry.getState(result), CacheState.VALID); |
| 388 } | 398 } |
| 389 | 399 |
| 390 test_performWorkItem_preExistingException() { | 400 test_performWorkItem_preExistingException() { |
| 391 AnalysisTarget target = new TestSource(); | 401 AnalysisTarget target = new TestSource(); |
| 392 ResultDescriptor result = new ResultDescriptor('result', null); | 402 ResultDescriptor result = new ResultDescriptor('result', null); |
| 393 TaskDescriptor descriptor = new TaskDescriptor('task', | 403 TaskDescriptor descriptor = new TaskDescriptor( |
| 404 'task', |
| 394 (context, target) => new TestAnalysisTask(context, target), | 405 (context, target) => new TestAnalysisTask(context, target), |
| 395 (target) => {}, [result]); | 406 (target) => {}, |
| 407 [result]); |
| 396 CaughtException exception = | 408 CaughtException exception = |
| 397 new CaughtException(new AnalysisException(), null); | 409 new CaughtException(new AnalysisException(), null); |
| 398 WorkItem item = new WorkItem(context, target, descriptor, null); | 410 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 399 item.exception = exception; | 411 item.exception = exception; |
| 400 | 412 |
| 401 analysisDriver.performWorkItem(item); | 413 analysisDriver.performWorkItem(item); |
| 402 CacheEntry targetEntry = context.getCacheEntry(item.target); | 414 CacheEntry targetEntry = context.getCacheEntry(item.target); |
| 403 expect(targetEntry.exception, exception); | 415 expect(targetEntry.exception, exception); |
| 404 expect(targetEntry.getState(result), CacheState.ERROR); | 416 expect(targetEntry.getState(result), CacheState.ERROR); |
| 405 } | 417 } |
| 406 | 418 |
| 407 test_reset() { | 419 test_reset() { |
| 408 ResultDescriptor inputResult = new ResultDescriptor('input', null); | 420 ResultDescriptor inputResult = new ResultDescriptor('input', null); |
| 409 TaskDescriptor descriptor = new TaskDescriptor('task', | 421 TaskDescriptor descriptor = new TaskDescriptor( |
| 422 'task', |
| 410 (context, target) => new TestAnalysisTask(context, target), | 423 (context, target) => new TestAnalysisTask(context, target), |
| 411 (target) => {'one': inputResult.of(target)}, | 424 (target) => {'one': inputResult.of(target)}, |
| 412 [new ResultDescriptor('output', null)]); | 425 [new ResultDescriptor('output', null)]); |
| 413 analysisDriver.currentWorkOrder = | 426 analysisDriver.currentWorkOrder = |
| 414 new WorkOrder(taskManager, new WorkItem(null, null, descriptor, null)); | 427 new WorkOrder(taskManager, new WorkItem(null, null, descriptor, null)); |
| 415 | 428 |
| 416 analysisDriver.reset(); | 429 analysisDriver.reset(); |
| 417 expect(analysisDriver.currentWorkOrder, isNull); | 430 expect(analysisDriver.currentWorkOrder, isNull); |
| 418 } | 431 } |
| 419 | 432 |
| 420 void _configureDescriptors12() { | 433 void _configureDescriptors12() { |
| 421 descriptor1 = new TaskDescriptor('task1', (context, target) => | 434 descriptor1 = new TaskDescriptor( |
| 435 'task1', |
| 436 (context, target) => |
| 422 new TestAnalysisTask(context, target, descriptor: descriptor1), | 437 new TestAnalysisTask(context, target, descriptor: descriptor1), |
| 423 (target) => {}, [result1]); | 438 (target) => {}, |
| 439 [result1]); |
| 424 taskManager.addTaskDescriptor(descriptor1); | 440 taskManager.addTaskDescriptor(descriptor1); |
| 425 | 441 |
| 426 descriptor2 = new TaskDescriptor('task2', (context, target) => | 442 descriptor2 = new TaskDescriptor( |
| 443 'task2', |
| 444 (context, target) => |
| 427 new TestAnalysisTask(context, target, descriptor: descriptor1), | 445 new TestAnalysisTask(context, target, descriptor: descriptor1), |
| 428 (target) => {}, [result2]); | 446 (target) => {}, |
| 447 [result2]); |
| 429 taskManager.addTaskDescriptor(descriptor2); | 448 taskManager.addTaskDescriptor(descriptor2); |
| 430 } | 449 } |
| 431 | 450 |
| 432 /** | 451 /** |
| 433 * [complete] is `true` if the value of the result has already been computed. | 452 * [complete] is `true` if the value of the result has already been computed. |
| 434 * [priorityTarget] is `true` if the target is in the list of priority | 453 * [priorityTarget] is `true` if the target is in the list of priority |
| 435 * targets. | 454 * targets. |
| 436 * [priorityResult] is `true` if the result should only be computed for | 455 * [priorityResult] is `true` if the result should only be computed for |
| 437 * priority targets. | 456 * priority targets. |
| 438 */ | 457 */ |
| 439 _createWorkOrderForTarget( | 458 _createWorkOrderForTarget( |
| 440 bool complete, bool priorityTarget, bool priorityResult) { | 459 bool complete, bool priorityTarget, bool priorityResult) { |
| 441 AnalysisTarget target = new TestSource(); | 460 AnalysisTarget target = new TestSource(); |
| 442 ResultDescriptor result = new ResultDescriptor('result', null); | 461 ResultDescriptor result = new ResultDescriptor('result', null); |
| 443 TaskDescriptor descriptor = new TaskDescriptor('task', | 462 TaskDescriptor descriptor = new TaskDescriptor( |
| 463 'task', |
| 444 (context, target) => new TestAnalysisTask(context, target), | 464 (context, target) => new TestAnalysisTask(context, target), |
| 445 (target) => {}, [result]); | 465 (target) => {}, |
| 466 [result]); |
| 446 if (priorityResult) { | 467 if (priorityResult) { |
| 447 taskManager.addPriorityResult(result); | 468 taskManager.addPriorityResult(result); |
| 448 } else { | 469 } else { |
| 449 taskManager.addGeneralResult(result); | 470 taskManager.addGeneralResult(result); |
| 450 } | 471 } |
| 451 taskManager.addTaskDescriptor(descriptor); | 472 taskManager.addTaskDescriptor(descriptor); |
| 452 if (priorityTarget) { | 473 if (priorityTarget) { |
| 453 context.priorityTargets.add(target); | 474 context.priorityTargets.add(target); |
| 454 } else { | 475 } else { |
| 455 context.explicitTargets.add(target); | 476 context.explicitTargets.add(target); |
| 456 } | 477 } |
| 457 if (complete) { | 478 if (complete) { |
| 458 context.getCacheEntry(target).setValue( | 479 context |
| 459 result, '', TargetedResult.EMPTY_LIST); | 480 .getCacheEntry(target) |
| 481 .setValue(result, '', TargetedResult.EMPTY_LIST); |
| 460 } else { | 482 } else { |
| 461 context.getCacheEntry(target).setState(result, CacheState.INVALID); | 483 context.getCacheEntry(target).setState(result, CacheState.INVALID); |
| 462 } | 484 } |
| 463 | 485 |
| 464 WorkOrder workOrder = | 486 WorkOrder workOrder = |
| 465 analysisDriver.createWorkOrderForTarget(target, priorityTarget); | 487 analysisDriver.createWorkOrderForTarget(target, priorityTarget); |
| 466 if (complete) { | 488 if (complete) { |
| 467 expect(workOrder, isNull); | 489 expect(workOrder, isNull); |
| 468 } else if (priorityResult) { | 490 } else if (priorityResult) { |
| 469 expect(workOrder, priorityTarget ? isNotNull : isNull); | 491 expect(workOrder, priorityTarget ? isNotNull : isNull); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 499 expect(cycleIndicators, expectedCycleIndicators); | 521 expect(cycleIndicators, expectedCycleIndicators); |
| 500 } | 522 } |
| 501 | 523 |
| 502 StronglyConnectedComponent<int> cycle(List<int> nodes) => | 524 StronglyConnectedComponent<int> cycle(List<int> nodes) => |
| 503 new StronglyConnectedComponent(nodes, true); | 525 new StronglyConnectedComponent(nodes, true); |
| 504 | 526 |
| 505 StronglyConnectedComponent<int> singleton(int node) => | 527 StronglyConnectedComponent<int> singleton(int node) => |
| 506 new StronglyConnectedComponent(<int>[node], false); | 528 new StronglyConnectedComponent(<int>[node], false); |
| 507 | 529 |
| 508 void test_complex_graph() { | 530 void test_complex_graph() { |
| 509 checkGraph({ | 531 checkGraph( |
| 510 1: [2, 3], | 532 { |
| 511 2: [3, 4], | 533 1: [2, 3], |
| 512 3: [], | 534 2: [3, 4], |
| 513 4: [3, 5], | 535 3: [], |
| 514 5: [2, 6], | 536 4: [3, 5], |
| 515 6: [3, 4] | 537 5: [2, 6], |
| 516 }, 1, [singleton(3), cycle([2, 4, 5, 6]), singleton(1)]); | 538 6: [3, 4] |
| 539 }, |
| 540 1, |
| 541 [ |
| 542 singleton(3), |
| 543 cycle([2, 4, 5, 6]), |
| 544 singleton(1) |
| 545 ]); |
| 517 } | 546 } |
| 518 | 547 |
| 519 void test_cycle_depends_on_other_nodes() { | 548 void test_cycle_depends_on_other_nodes() { |
| 520 checkGraph({1: [2, 3], 2: [4, 1], 3: [], 4: []}, 1, [ | 549 checkGraph( |
| 521 singleton(4), | 550 { |
| 522 singleton(3), | 551 1: [2, 3], |
| 523 cycle([1, 2]) | 552 2: [4, 1], |
| 524 ]); | 553 3: [], |
| 554 4: [] |
| 555 }, |
| 556 1, |
| 557 [ |
| 558 singleton(4), |
| 559 singleton(3), |
| 560 cycle([1, 2]) |
| 561 ]); |
| 525 } | 562 } |
| 526 | 563 |
| 527 void test_initial_node_depends_on_cycle() { | 564 void test_initial_node_depends_on_cycle() { |
| 528 checkGraph({1: [2], 2: [3], 3: [2]}, 1, [cycle([2, 3]), singleton(1)]); | 565 checkGraph( |
| 566 { |
| 567 1: [2], |
| 568 2: [3], |
| 569 3: [2] |
| 570 }, |
| 571 1, |
| 572 [ |
| 573 cycle([2, 3]), |
| 574 singleton(1) |
| 575 ]); |
| 529 } | 576 } |
| 530 | 577 |
| 531 void test_simple_cycle() { | 578 void test_simple_cycle() { |
| 532 checkGraph({1: [2], 2: [1]}, 1, [cycle([1, 2])]); | 579 checkGraph( |
| 580 { |
| 581 1: [2], |
| 582 2: [1] |
| 583 }, |
| 584 1, |
| 585 [ |
| 586 cycle([1, 2]) |
| 587 ]); |
| 533 } | 588 } |
| 534 | 589 |
| 535 void test_simple_dependency_chain() { | 590 void test_simple_dependency_chain() { |
| 536 checkGraph({1: [2], 2: []}, 1, [singleton(2), singleton(1)]); | 591 checkGraph( |
| 592 { |
| 593 1: [2], |
| 594 2: [] |
| 595 }, |
| 596 1, |
| 597 [singleton(2), singleton(1)]); |
| 537 } | 598 } |
| 538 | 599 |
| 539 void test_single_node() { | 600 void test_single_node() { |
| 540 checkGraph({1: []}, 1, [singleton(1)]); | 601 checkGraph({1: []}, 1, [singleton(1)]); |
| 541 } | 602 } |
| 542 | 603 |
| 543 void test_single_node_cycle() { | 604 void test_single_node_cycle() { |
| 544 checkGraph({1: [1]}, 1, [cycle([1])]); | 605 checkGraph( |
| 606 { |
| 607 1: [1] |
| 608 }, |
| 609 1, |
| 610 [ |
| 611 cycle([1]) |
| 612 ]); |
| 545 } | 613 } |
| 546 } | 614 } |
| 547 | 615 |
| 548 @reflectiveTest | 616 @reflectiveTest |
| 549 class WorkItemTest extends AbstractDriverTest { | 617 class WorkItemTest extends AbstractDriverTest { |
| 550 test_buildTask_complete() { | 618 test_buildTask_complete() { |
| 551 AnalysisTarget target = new TestSource(); | 619 AnalysisTarget target = new TestSource(); |
| 552 TaskDescriptor descriptor = new TaskDescriptor('task', | 620 TaskDescriptor descriptor = new TaskDescriptor( |
| 621 'task', |
| 553 (context, target) => new TestAnalysisTask(context, target), | 622 (context, target) => new TestAnalysisTask(context, target), |
| 554 (target) => {}, [new ResultDescriptor('output', null)]); | 623 (target) => {}, |
| 624 [new ResultDescriptor('output', null)]); |
| 555 WorkItem item = new WorkItem(context, target, descriptor, null); | 625 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 556 AnalysisTask task = item.buildTask(); | 626 AnalysisTask task = item.buildTask(); |
| 557 expect(task, isNotNull); | 627 expect(task, isNotNull); |
| 558 } | 628 } |
| 559 | 629 |
| 560 test_buildTask_incomplete() { | 630 test_buildTask_incomplete() { |
| 561 AnalysisTarget target = new TestSource(); | 631 AnalysisTarget target = new TestSource(); |
| 562 ResultDescriptor inputResult = new ResultDescriptor('input', null); | 632 ResultDescriptor inputResult = new ResultDescriptor('input', null); |
| 563 List<ResultDescriptor> outputResults = | 633 List<ResultDescriptor> outputResults = <ResultDescriptor>[ |
| 564 <ResultDescriptor>[new ResultDescriptor('output', null)]; | 634 new ResultDescriptor('output', null) |
| 565 TaskDescriptor descriptor = new TaskDescriptor('task', (context, target) => | 635 ]; |
| 636 TaskDescriptor descriptor = new TaskDescriptor( |
| 637 'task', |
| 638 (context, target) => |
| 566 new TestAnalysisTask(context, target, results: outputResults), | 639 new TestAnalysisTask(context, target, results: outputResults), |
| 567 (target) => {'one': inputResult.of(target)}, outputResults); | 640 (target) => {'one': inputResult.of(target)}, |
| 641 outputResults); |
| 568 WorkItem item = new WorkItem(context, target, descriptor, null); | 642 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 569 expect(() => item.buildTask(), throwsStateError); | 643 expect(() => item.buildTask(), throwsStateError); |
| 570 } | 644 } |
| 571 | 645 |
| 572 test_create() { | 646 test_create() { |
| 573 AnalysisTarget target = new TestSource(); | 647 AnalysisTarget target = new TestSource(); |
| 574 TaskDescriptor descriptor = new TaskDescriptor( | 648 TaskDescriptor descriptor = new TaskDescriptor( |
| 575 'task', null, (target) => {}, [new ResultDescriptor('result', null)]); | 649 'task', null, (target) => {}, [new ResultDescriptor('result', null)]); |
| 576 WorkItem item = new WorkItem(context, target, descriptor, null); | 650 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 577 expect(item, isNotNull); | 651 expect(item, isNotNull); |
| 578 expect(item.context, context); | 652 expect(item.context, context); |
| 579 expect(item.descriptor, descriptor); | 653 expect(item.descriptor, descriptor); |
| 580 expect(item.target, target); | 654 expect(item.target, target); |
| 581 } | 655 } |
| 582 | 656 |
| 583 test_gatherInputs_complete() { | 657 test_gatherInputs_complete() { |
| 584 AnalysisTarget target = new TestSource(); | 658 AnalysisTarget target = new TestSource(); |
| 585 TaskDescriptor descriptor = new TaskDescriptor('task', | 659 TaskDescriptor descriptor = new TaskDescriptor( |
| 660 'task', |
| 586 (context, target) => new TestAnalysisTask(context, target), | 661 (context, target) => new TestAnalysisTask(context, target), |
| 587 (target) => {}, [new ResultDescriptor('output', null)]); | 662 (target) => {}, |
| 663 [new ResultDescriptor('output', null)]); |
| 588 WorkItem item = new WorkItem(context, target, descriptor, null); | 664 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 589 WorkItem result = item.gatherInputs(taskManager, []); | 665 WorkItem result = item.gatherInputs(taskManager, []); |
| 590 expect(result, isNull); | 666 expect(result, isNull); |
| 591 expect(item.exception, isNull); | 667 expect(item.exception, isNull); |
| 592 } | 668 } |
| 593 | 669 |
| 594 test_gatherInputs_incomplete() { | 670 test_gatherInputs_incomplete() { |
| 595 AnalysisTarget target = new TestSource(); | 671 AnalysisTarget target = new TestSource(); |
| 596 ResultDescriptor resultA = new ResultDescriptor('resultA', null); | 672 ResultDescriptor resultA = new ResultDescriptor('resultA', null); |
| 597 ResultDescriptor resultB = new ResultDescriptor('resultB', null); | 673 ResultDescriptor resultB = new ResultDescriptor('resultB', null); |
| 598 // prepare tasks | 674 // prepare tasks |
| 599 TaskDescriptor task1 = new TaskDescriptor('task', (context, target) => | 675 TaskDescriptor task1 = new TaskDescriptor( |
| 676 'task', |
| 677 (context, target) => |
| 600 new TestAnalysisTask(context, target, results: [resultA]), | 678 new TestAnalysisTask(context, target, results: [resultA]), |
| 601 (target) => {}, [resultA]); | 679 (target) => {}, |
| 602 TaskDescriptor task2 = new TaskDescriptor('task', | 680 [resultA]); |
| 681 TaskDescriptor task2 = new TaskDescriptor( |
| 682 'task', |
| 603 (context, target) => new TestAnalysisTask(context, target), | 683 (context, target) => new TestAnalysisTask(context, target), |
| 604 (target) => {'one': resultA.of(target)}, [resultB]); | 684 (target) => {'one': resultA.of(target)}, |
| 685 [resultB]); |
| 605 taskManager.addTaskDescriptor(task1); | 686 taskManager.addTaskDescriptor(task1); |
| 606 taskManager.addTaskDescriptor(task2); | 687 taskManager.addTaskDescriptor(task2); |
| 607 // gather inputs | 688 // gather inputs |
| 608 WorkItem item = new WorkItem(context, target, task2, null); | 689 WorkItem item = new WorkItem(context, target, task2, null); |
| 609 WorkItem inputItem = item.gatherInputs(taskManager, []); | 690 WorkItem inputItem = item.gatherInputs(taskManager, []); |
| 610 expect(inputItem, isNotNull); | 691 expect(inputItem, isNotNull); |
| 611 } | 692 } |
| 612 | 693 |
| 613 test_gatherInputs_invalid() { | 694 test_gatherInputs_invalid() { |
| 614 AnalysisTarget target = new TestSource(); | 695 AnalysisTarget target = new TestSource(); |
| 615 ResultDescriptor inputResult = new ResultDescriptor('input', null); | 696 ResultDescriptor inputResult = new ResultDescriptor('input', null); |
| 616 TaskDescriptor descriptor = new TaskDescriptor('task', | 697 TaskDescriptor descriptor = new TaskDescriptor( |
| 698 'task', |
| 617 (context, target) => new TestAnalysisTask(context, target), | 699 (context, target) => new TestAnalysisTask(context, target), |
| 618 (target) => {'one': inputResult.of(target)}, | 700 (target) => {'one': inputResult.of(target)}, |
| 619 [new ResultDescriptor('output', null)]); | 701 [new ResultDescriptor('output', null)]); |
| 620 WorkItem item = new WorkItem(context, target, descriptor, null); | 702 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 621 WorkItem result = item.gatherInputs(taskManager, []); | 703 WorkItem result = item.gatherInputs(taskManager, []); |
| 622 expect(result, isNull); | 704 expect(result, isNull); |
| 623 expect(item.exception, isNotNull); | 705 expect(item.exception, isNotNull); |
| 624 } | 706 } |
| 625 } | 707 } |
| 626 | 708 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 return dependency; | 784 return dependency; |
| 703 } | 785 } |
| 704 } | 786 } |
| 705 return null; | 787 return null; |
| 706 } | 788 } |
| 707 } | 789 } |
| 708 | 790 |
| 709 class _WorkManagerMock extends TypedMock implements WorkManager { | 791 class _WorkManagerMock extends TypedMock implements WorkManager { |
| 710 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 792 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 711 } | 793 } |
| OLD | NEW |