| 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, |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 when(workManager1.getNextResultPriority()).thenReturnList( | 206 when(workManager1.getNextResultPriority()).thenReturnList( |
| 207 <WorkOrderPriority>[WorkOrderPriority.NORMAL, WorkOrderPriority.NONE]); | 207 <WorkOrderPriority>[WorkOrderPriority.NORMAL, WorkOrderPriority.NONE]); |
| 208 when(workManager1.getNextResult()) | 208 when(workManager1.getNextResult()) |
| 209 .thenReturn(new TargetedResult(target1, result1)); | 209 .thenReturn(new TargetedResult(target1, result1)); |
| 210 | 210 |
| 211 expect(analysisDriver.performAnalysisTask(), true); | 211 expect(analysisDriver.performAnalysisTask(), true); |
| 212 expect(analysisDriver.performAnalysisTask(), true); | 212 expect(analysisDriver.performAnalysisTask(), true); |
| 213 expect(analysisDriver.performAnalysisTask(), false); | 213 expect(analysisDriver.performAnalysisTask(), false); |
| 214 } | 214 } |
| 215 | 215 |
| 216 test_performAnalysisTask_infiniteLoop() { | 216 test_performAnalysisTask_infiniteLoop_handled() { |
| 217 AnalysisTarget target = new TestSource(); | 217 AnalysisTarget target = new TestSource(); |
| 218 ResultDescriptor resultA = new ResultDescriptor('resultA', -1); | 218 ResultDescriptor resultA = new ResultDescriptor('resultA', -1); |
| 219 ResultDescriptor resultB = new ResultDescriptor('resultB', -2); | 219 ResultDescriptor resultB = new ResultDescriptor('resultB', -2); |
| 220 // configure tasks |
| 221 TestAnalysisTask task1; |
| 222 TestAnalysisTask task2; |
| 223 TaskDescriptor descriptor1 = new TaskDescriptor('task1', |
| 224 (context, target) => task1, (target) => { |
| 225 'inputB': new SimpleTaskInput<int>(target, resultB) |
| 226 }, [resultA]); |
| 227 TaskDescriptor descriptor2 = new TaskDescriptor('task2', |
| 228 (context, target) => task2, (target) => { |
| 229 'inputA': new SimpleTaskInput<int>(target, resultA) |
| 230 }, [resultB]); |
| 231 task1 = new TestAnalysisTask(context, target, |
| 232 descriptor: descriptor1, |
| 233 results: [resultA], |
| 234 value: 10, |
| 235 handlesDependencyCycles: true); |
| 236 task2 = new TestAnalysisTask(context, target, |
| 237 descriptor: descriptor2, |
| 238 results: [resultB], |
| 239 value: 20, |
| 240 handlesDependencyCycles: true); |
| 241 taskManager.addTaskDescriptor(descriptor1); |
| 242 taskManager.addTaskDescriptor(descriptor2); |
| 243 // configure WorkManager |
| 244 when(workManager1.getNextResultPriority()).thenReturnList( |
| 245 <WorkOrderPriority>[WorkOrderPriority.NORMAL, WorkOrderPriority.NONE]); |
| 246 when(workManager1.getNextResult()) |
| 247 .thenReturn(new TargetedResult(target, resultB)); |
| 248 // prepare work order |
| 249 while (analysisDriver.performAnalysisTask()) {} |
| 250 Set<TaskDescriptor> expectedCycle = [descriptor1, descriptor2].toSet(); |
| 251 expect(task1.dependencyCycle, isNotNull); |
| 252 expect(task1.dependencyCycle.map((workItem) => workItem.descriptor).toSet(), |
| 253 expectedCycle); |
| 254 expect(task2.dependencyCycle, isNotNull); |
| 255 expect(task2.dependencyCycle.map((workItem) => workItem.descriptor).toSet(), |
| 256 expectedCycle); |
| 257 CaughtException exception = context.getCacheEntry(target).exception; |
| 258 expect(exception, isNull); |
| 259 expect(context.getCacheEntry(target).getValue(resultA), 10); |
| 260 expect(context.getCacheEntry(target).getValue(resultB), 20); |
| 261 } |
| 262 |
| 263 test_performAnalysisTask_infiniteLoop_unhandled() { |
| 264 AnalysisTarget target = new TestSource(); |
| 265 ResultDescriptor resultA = new ResultDescriptor('resultA', -1); |
| 266 ResultDescriptor resultB = new ResultDescriptor('resultB', -2); |
| 220 // configure tasks | 267 // configure tasks |
| 221 TestAnalysisTask task1; | 268 TestAnalysisTask task1; |
| 222 TestAnalysisTask task2; | 269 TestAnalysisTask task2; |
| 223 TaskDescriptor descriptor1 = new TaskDescriptor('task1', | 270 TaskDescriptor descriptor1 = new TaskDescriptor('task1', |
| 224 (context, target) => task1, (target) => { | 271 (context, target) => task1, (target) => { |
| 225 'inputB': new SimpleTaskInput<int>(target, resultB) | 272 'inputB': new SimpleTaskInput<int>(target, resultB) |
| 226 }, [resultA]); | 273 }, [resultA]); |
| 227 TaskDescriptor descriptor2 = new TaskDescriptor('task2', | 274 TaskDescriptor descriptor2 = new TaskDescriptor('task2', |
| 228 (context, target) => task2, (target) => { | 275 (context, target) => task2, (target) => { |
| 229 'inputA': new SimpleTaskInput<int>(target, resultA) | 276 'inputA': new SimpleTaskInput<int>(target, resultA) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 test_performWorkItem_exceptionInTask() { | 335 test_performWorkItem_exceptionInTask() { |
| 289 AnalysisTarget target = new TestSource(); | 336 AnalysisTarget target = new TestSource(); |
| 290 ResultDescriptor result = new ResultDescriptor('result', null); | 337 ResultDescriptor result = new ResultDescriptor('result', null); |
| 291 CaughtException exception = | 338 CaughtException exception = |
| 292 new CaughtException(new AnalysisException(), null); | 339 new CaughtException(new AnalysisException(), null); |
| 293 TestAnalysisTask task; | 340 TestAnalysisTask task; |
| 294 TaskDescriptor descriptor = new TaskDescriptor( | 341 TaskDescriptor descriptor = new TaskDescriptor( |
| 295 'task', (context, target) => task, (target) => {}, [result]); | 342 'task', (context, target) => task, (target) => {}, [result]); |
| 296 task = new TestAnalysisTask(context, target, | 343 task = new TestAnalysisTask(context, target, |
| 297 descriptor: descriptor, exception: exception); | 344 descriptor: descriptor, exception: exception); |
| 298 WorkItem item = new WorkItem(context, target, descriptor); | 345 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 299 | 346 |
| 300 analysisDriver.performWorkItem(item); | 347 analysisDriver.performWorkItem(item); |
| 301 CacheEntry targetEntry = context.getCacheEntry(item.target); | 348 CacheEntry targetEntry = context.getCacheEntry(item.target); |
| 302 expect(targetEntry.exception, exception); | 349 expect(targetEntry.exception, exception); |
| 303 expect(targetEntry.getState(result), CacheState.ERROR); | 350 expect(targetEntry.getState(result), CacheState.ERROR); |
| 304 } | 351 } |
| 305 | 352 |
| 306 test_performWorkItem_noException() { | 353 test_performWorkItem_noException() { |
| 307 AnalysisTarget target = new TestSource(); | 354 AnalysisTarget target = new TestSource(); |
| 308 ResultDescriptor result = new ResultDescriptor('result', null); | 355 ResultDescriptor result = new ResultDescriptor('result', null); |
| 309 TestAnalysisTask task; | 356 TestAnalysisTask task; |
| 310 TaskDescriptor descriptor = new TaskDescriptor( | 357 TaskDescriptor descriptor = new TaskDescriptor( |
| 311 'task', (context, target) => task, (target) => {}, [result]); | 358 'task', (context, target) => task, (target) => {}, [result]); |
| 312 task = new TestAnalysisTask(context, target, descriptor: descriptor); | 359 task = new TestAnalysisTask(context, target, descriptor: descriptor); |
| 313 WorkItem item = new WorkItem(context, target, descriptor); | 360 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 314 | 361 |
| 315 analysisDriver.performWorkItem(item); | 362 analysisDriver.performWorkItem(item); |
| 316 CacheEntry targetEntry = context.getCacheEntry(item.target); | 363 CacheEntry targetEntry = context.getCacheEntry(item.target); |
| 317 expect(targetEntry.exception, isNull); | 364 expect(targetEntry.exception, isNull); |
| 318 expect(targetEntry.getState(result), CacheState.VALID); | 365 expect(targetEntry.getState(result), CacheState.VALID); |
| 319 } | 366 } |
| 320 | 367 |
| 321 test_performWorkItem_preExistingException() { | 368 test_performWorkItem_preExistingException() { |
| 322 AnalysisTarget target = new TestSource(); | 369 AnalysisTarget target = new TestSource(); |
| 323 ResultDescriptor result = new ResultDescriptor('result', null); | 370 ResultDescriptor result = new ResultDescriptor('result', null); |
| 324 TaskDescriptor descriptor = new TaskDescriptor('task', | 371 TaskDescriptor descriptor = new TaskDescriptor('task', |
| 325 (context, target) => new TestAnalysisTask(context, target), | 372 (context, target) => new TestAnalysisTask(context, target), |
| 326 (target) => {}, [result]); | 373 (target) => {}, [result]); |
| 327 CaughtException exception = | 374 CaughtException exception = |
| 328 new CaughtException(new AnalysisException(), null); | 375 new CaughtException(new AnalysisException(), null); |
| 329 WorkItem item = new WorkItem(context, target, descriptor); | 376 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 330 item.exception = exception; | 377 item.exception = exception; |
| 331 | 378 |
| 332 analysisDriver.performWorkItem(item); | 379 analysisDriver.performWorkItem(item); |
| 333 CacheEntry targetEntry = context.getCacheEntry(item.target); | 380 CacheEntry targetEntry = context.getCacheEntry(item.target); |
| 334 expect(targetEntry.exception, exception); | 381 expect(targetEntry.exception, exception); |
| 335 expect(targetEntry.getState(result), CacheState.ERROR); | 382 expect(targetEntry.getState(result), CacheState.ERROR); |
| 336 } | 383 } |
| 337 | 384 |
| 338 test_reset() { | 385 test_reset() { |
| 339 ResultDescriptor inputResult = new ResultDescriptor('input', null); | 386 ResultDescriptor inputResult = new ResultDescriptor('input', null); |
| 340 TaskDescriptor descriptor = new TaskDescriptor('task', | 387 TaskDescriptor descriptor = new TaskDescriptor('task', |
| 341 (context, target) => new TestAnalysisTask(context, target), | 388 (context, target) => new TestAnalysisTask(context, target), |
| 342 (target) => {'one': inputResult.of(target)}, | 389 (target) => {'one': inputResult.of(target)}, |
| 343 [new ResultDescriptor('output', null)]); | 390 [new ResultDescriptor('output', null)]); |
| 344 analysisDriver.currentWorkOrder = | 391 analysisDriver.currentWorkOrder = |
| 345 new WorkOrder(taskManager, new WorkItem(null, null, descriptor)); | 392 new WorkOrder(taskManager, new WorkItem(null, null, descriptor, null)); |
| 346 | 393 |
| 347 analysisDriver.reset(); | 394 analysisDriver.reset(); |
| 348 expect(analysisDriver.currentWorkOrder, isNull); | 395 expect(analysisDriver.currentWorkOrder, isNull); |
| 349 } | 396 } |
| 350 | 397 |
| 351 void _configureDescriptors12() { | 398 void _configureDescriptors12() { |
| 352 descriptor1 = new TaskDescriptor('task1', (context, target) => | 399 descriptor1 = new TaskDescriptor('task1', (context, target) => |
| 353 new TestAnalysisTask(context, target, descriptor: descriptor1), | 400 new TestAnalysisTask(context, target, descriptor: descriptor1), |
| 354 (target) => {}, [result1]); | 401 (target) => {}, [result1]); |
| 355 taskManager.addTaskDescriptor(descriptor1); | 402 taskManager.addTaskDescriptor(descriptor1); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } | 503 } |
| 457 } | 504 } |
| 458 | 505 |
| 459 @reflectiveTest | 506 @reflectiveTest |
| 460 class WorkItemTest extends AbstractDriverTest { | 507 class WorkItemTest extends AbstractDriverTest { |
| 461 test_buildTask_complete() { | 508 test_buildTask_complete() { |
| 462 AnalysisTarget target = new TestSource(); | 509 AnalysisTarget target = new TestSource(); |
| 463 TaskDescriptor descriptor = new TaskDescriptor('task', | 510 TaskDescriptor descriptor = new TaskDescriptor('task', |
| 464 (context, target) => new TestAnalysisTask(context, target), | 511 (context, target) => new TestAnalysisTask(context, target), |
| 465 (target) => {}, [new ResultDescriptor('output', null)]); | 512 (target) => {}, [new ResultDescriptor('output', null)]); |
| 466 WorkItem item = new WorkItem(context, target, descriptor); | 513 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 467 AnalysisTask task = item.buildTask(); | 514 AnalysisTask task = item.buildTask(); |
| 468 expect(task, isNotNull); | 515 expect(task, isNotNull); |
| 469 } | 516 } |
| 470 | 517 |
| 471 test_buildTask_incomplete() { | 518 test_buildTask_incomplete() { |
| 472 AnalysisTarget target = new TestSource(); | 519 AnalysisTarget target = new TestSource(); |
| 473 ResultDescriptor inputResult = new ResultDescriptor('input', null); | 520 ResultDescriptor inputResult = new ResultDescriptor('input', null); |
| 474 List<ResultDescriptor> outputResults = | 521 List<ResultDescriptor> outputResults = |
| 475 <ResultDescriptor>[new ResultDescriptor('output', null)]; | 522 <ResultDescriptor>[new ResultDescriptor('output', null)]; |
| 476 TaskDescriptor descriptor = new TaskDescriptor('task', (context, target) => | 523 TaskDescriptor descriptor = new TaskDescriptor('task', (context, target) => |
| 477 new TestAnalysisTask(context, target, results: outputResults), | 524 new TestAnalysisTask(context, target, results: outputResults), |
| 478 (target) => {'one': inputResult.of(target)}, outputResults); | 525 (target) => {'one': inputResult.of(target)}, outputResults); |
| 479 WorkItem item = new WorkItem(context, target, descriptor); | 526 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 480 expect(() => item.buildTask(), throwsStateError); | 527 expect(() => item.buildTask(), throwsStateError); |
| 481 } | 528 } |
| 482 | 529 |
| 483 test_create() { | 530 test_create() { |
| 484 AnalysisTarget target = new TestSource(); | 531 AnalysisTarget target = new TestSource(); |
| 485 TaskDescriptor descriptor = new TaskDescriptor( | 532 TaskDescriptor descriptor = new TaskDescriptor( |
| 486 'task', null, (target) => {}, [new ResultDescriptor('result', null)]); | 533 'task', null, (target) => {}, [new ResultDescriptor('result', null)]); |
| 487 WorkItem item = new WorkItem(context, target, descriptor); | 534 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 488 expect(item, isNotNull); | 535 expect(item, isNotNull); |
| 489 expect(item.context, context); | 536 expect(item.context, context); |
| 490 expect(item.descriptor, descriptor); | 537 expect(item.descriptor, descriptor); |
| 491 expect(item.target, target); | 538 expect(item.target, target); |
| 492 } | 539 } |
| 493 | 540 |
| 494 test_gatherInputs_complete() { | 541 test_gatherInputs_complete() { |
| 495 AnalysisTarget target = new TestSource(); | 542 AnalysisTarget target = new TestSource(); |
| 496 TaskDescriptor descriptor = new TaskDescriptor('task', | 543 TaskDescriptor descriptor = new TaskDescriptor('task', |
| 497 (context, target) => new TestAnalysisTask(context, target), | 544 (context, target) => new TestAnalysisTask(context, target), |
| 498 (target) => {}, [new ResultDescriptor('output', null)]); | 545 (target) => {}, [new ResultDescriptor('output', null)]); |
| 499 WorkItem item = new WorkItem(context, target, descriptor); | 546 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 500 WorkItem result = item.gatherInputs(taskManager); | 547 WorkItem result = item.gatherInputs(taskManager, []); |
| 501 expect(result, isNull); | 548 expect(result, isNull); |
| 502 expect(item.exception, isNull); | 549 expect(item.exception, isNull); |
| 503 } | 550 } |
| 504 | 551 |
| 505 test_gatherInputs_incomplete() { | 552 test_gatherInputs_incomplete() { |
| 506 AnalysisTarget target = new TestSource(); | 553 AnalysisTarget target = new TestSource(); |
| 507 ResultDescriptor resultA = new ResultDescriptor('resultA', null); | 554 ResultDescriptor resultA = new ResultDescriptor('resultA', null); |
| 508 ResultDescriptor resultB = new ResultDescriptor('resultB', null); | 555 ResultDescriptor resultB = new ResultDescriptor('resultB', null); |
| 509 // prepare tasks | 556 // prepare tasks |
| 510 TaskDescriptor task1 = new TaskDescriptor('task', (context, target) => | 557 TaskDescriptor task1 = new TaskDescriptor('task', (context, target) => |
| 511 new TestAnalysisTask(context, target, results: [resultA]), | 558 new TestAnalysisTask(context, target, results: [resultA]), |
| 512 (target) => {}, [resultA]); | 559 (target) => {}, [resultA]); |
| 513 TaskDescriptor task2 = new TaskDescriptor('task', | 560 TaskDescriptor task2 = new TaskDescriptor('task', |
| 514 (context, target) => new TestAnalysisTask(context, target), | 561 (context, target) => new TestAnalysisTask(context, target), |
| 515 (target) => {'one': resultA.of(target)}, [resultB]); | 562 (target) => {'one': resultA.of(target)}, [resultB]); |
| 516 taskManager.addTaskDescriptor(task1); | 563 taskManager.addTaskDescriptor(task1); |
| 517 taskManager.addTaskDescriptor(task2); | 564 taskManager.addTaskDescriptor(task2); |
| 518 // gather inputs | 565 // gather inputs |
| 519 WorkItem item = new WorkItem(context, target, task2); | 566 WorkItem item = new WorkItem(context, target, task2, null); |
| 520 WorkItem inputItem = item.gatherInputs(taskManager); | 567 WorkItem inputItem = item.gatherInputs(taskManager, []); |
| 521 expect(inputItem, isNotNull); | 568 expect(inputItem, isNotNull); |
| 522 } | 569 } |
| 523 | 570 |
| 524 test_gatherInputs_invalid() { | 571 test_gatherInputs_invalid() { |
| 525 AnalysisTarget target = new TestSource(); | 572 AnalysisTarget target = new TestSource(); |
| 526 ResultDescriptor inputResult = new ResultDescriptor('input', null); | 573 ResultDescriptor inputResult = new ResultDescriptor('input', null); |
| 527 TaskDescriptor descriptor = new TaskDescriptor('task', | 574 TaskDescriptor descriptor = new TaskDescriptor('task', |
| 528 (context, target) => new TestAnalysisTask(context, target), | 575 (context, target) => new TestAnalysisTask(context, target), |
| 529 (target) => {'one': inputResult.of(target)}, | 576 (target) => {'one': inputResult.of(target)}, |
| 530 [new ResultDescriptor('output', null)]); | 577 [new ResultDescriptor('output', null)]); |
| 531 WorkItem item = new WorkItem(context, target, descriptor); | 578 WorkItem item = new WorkItem(context, target, descriptor, null); |
| 532 WorkItem result = item.gatherInputs(taskManager); | 579 WorkItem result = item.gatherInputs(taskManager, []); |
| 533 expect(result, isNull); | 580 expect(result, isNull); |
| 534 expect(item.exception, isNotNull); | 581 expect(item.exception, isNotNull); |
| 535 } | 582 } |
| 536 } | 583 } |
| 537 | 584 |
| 538 @reflectiveTest | 585 @reflectiveTest |
| 539 class WorkOrderTest extends EngineTestCase { | 586 class WorkOrderTest extends EngineTestCase { |
| 540 test_create() { | 587 test_create() { |
| 541 TaskManager manager = new TaskManager(); | 588 TaskManager manager = new TaskManager(); |
| 542 TaskDescriptor descriptor = new TaskDescriptor( | 589 TaskDescriptor descriptor = new TaskDescriptor( |
| 543 'task', null, (_) => {}, [new ResultDescriptor('result', null)]); | 590 'task', null, (_) => {}, [new ResultDescriptor('result', null)]); |
| 544 WorkOrder order = | 591 WorkOrder order = |
| 545 new WorkOrder(manager, new WorkItem(null, null, descriptor)); | 592 new WorkOrder(manager, new WorkItem(null, null, descriptor, null)); |
| 546 expect(order, isNotNull); | 593 expect(order, isNotNull); |
| 547 expect(order.currentItems, isNull); | 594 expect(order.currentItems, isNull); |
| 548 expect(order.current, isNull); | 595 expect(order.current, isNull); |
| 549 } | 596 } |
| 550 | 597 |
| 551 test_moveNext() { | 598 test_moveNext() { |
| 552 TaskManager manager = new TaskManager(); | 599 TaskManager manager = new TaskManager(); |
| 553 TaskDescriptor descriptor = new TaskDescriptor( | 600 TaskDescriptor descriptor = new TaskDescriptor( |
| 554 'task', null, (_) => {}, [new ResultDescriptor('result', null)]); | 601 'task', null, (_) => {}, [new ResultDescriptor('result', null)]); |
| 555 WorkItem workItem = new WorkItem(null, null, descriptor); | 602 WorkItem workItem = new WorkItem(null, null, descriptor, null); |
| 556 WorkOrder order = new WorkOrder(manager, workItem); | 603 WorkOrder order = new WorkOrder(manager, workItem); |
| 557 // "item" has no child items | 604 // "item" has no child items |
| 558 expect(order.moveNext(), isTrue); | 605 expect(order.moveNext(), isTrue); |
| 559 expect(order.current, workItem); | 606 expect(order.current, workItem); |
| 560 // done | 607 // done |
| 561 expect(order.moveNext(), isFalse); | 608 expect(order.moveNext(), isFalse); |
| 562 expect(order.current, isNull); | 609 expect(order.current, isNull); |
| 563 } | 610 } |
| 564 } | 611 } |
| 565 | 612 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 return dependency; | 660 return dependency; |
| 614 } | 661 } |
| 615 } | 662 } |
| 616 return null; | 663 return null; |
| 617 } | 664 } |
| 618 } | 665 } |
| 619 | 666 |
| 620 class _WorkManagerMock extends TypedMock implements WorkManager { | 667 class _WorkManagerMock extends TypedMock implements WorkManager { |
| 621 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 668 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 622 } | 669 } |
| OLD | NEW |