| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 * Classes and methods for executing tests. | 6 * Classes and methods for executing tests. |
| 7 * | 7 * |
| 8 * This module includes: | 8 * This module includes: |
| 9 * - Managing parallel execution of tests, including timeout checks. | 9 * - Managing parallel execution of tests, including timeout checks. |
| 10 * - Evaluating the output of each test as pass/fail/crash/timeout. | 10 * - Evaluating the output of each test as pass/fail/crash/timeout. |
| (...skipping 1909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1920 * closed. | 1920 * closed. |
| 1921 */ | 1921 */ |
| 1922 class TestCaseCompleter { | 1922 class TestCaseCompleter { |
| 1923 static final COMPLETED_STATES = [dgraph.NodeState.Failed, | 1923 static final COMPLETED_STATES = [dgraph.NodeState.Failed, |
| 1924 dgraph.NodeState.Successful]; | 1924 dgraph.NodeState.Successful]; |
| 1925 final dgraph.Graph graph; | 1925 final dgraph.Graph graph; |
| 1926 final TestCaseEnqueuer enqueuer; | 1926 final TestCaseEnqueuer enqueuer; |
| 1927 final CommandQueue commandQueue; | 1927 final CommandQueue commandQueue; |
| 1928 | 1928 |
| 1929 Map<Command, CommandOutput> _outputs = new Map<Command, CommandOutput>(); | 1929 Map<Command, CommandOutput> _outputs = new Map<Command, CommandOutput>(); |
| 1930 bool _closed = false; |
| 1930 StreamController<TestCase> _controller = new StreamController<TestCase>(); | 1931 StreamController<TestCase> _controller = new StreamController<TestCase>(); |
| 1931 | 1932 |
| 1932 TestCaseCompleter(this.graph, this.enqueuer, this.commandQueue) { | 1933 TestCaseCompleter(this.graph, this.enqueuer, this.commandQueue) { |
| 1933 var eventCondition = graph.events.where; | 1934 var eventCondition = graph.events.where; |
| 1934 | 1935 |
| 1935 // Store all the command outputs -- they will be delivered synchronously | 1936 // Store all the command outputs -- they will be delivered synchronously |
| 1936 // (i.e. before state changes in the graph) | 1937 // (i.e. before state changes in the graph) |
| 1937 commandQueue.completedCommands.listen((CommandOutput output) { | 1938 commandQueue.completedCommands.listen((CommandOutput output) { |
| 1938 _outputs[output.command] = output; | 1939 _outputs[output.command] = output; |
| 1939 }); | 1940 }); |
| 1940 | 1941 |
| 1941 // Listen for NodeState.Processing -> NodeState.{Successfull,Failed} | 1942 // Listen for NodeState.Processing -> NodeState.{Successfull,Failed} |
| 1942 // changes. | 1943 // changes. |
| 1943 eventCondition((event) => event is dgraph.StateChangedEvent) | 1944 eventCondition((event) => event is dgraph.StateChangedEvent) |
| 1944 .listen((dgraph.StateChangedEvent event) { | 1945 .listen((dgraph.StateChangedEvent event) { |
| 1945 if (event.from == dgraph.NodeState.Processing) { | 1946 if (event.from == dgraph.NodeState.Processing) { |
| 1946 assert(COMPLETED_STATES.contains(event.to)); | 1947 assert(COMPLETED_STATES.contains(event.to)); |
| 1947 _completeTestCasesIfPossible(event.node.userData); | 1948 _completeTestCasesIfPossible(event.node.userData); |
| 1948 | 1949 |
| 1949 if (graph.isSealed && enqueuer.remainingTestCases.isEmpty) { | 1950 if (!_closed && |
| 1951 graph.isSealed && |
| 1952 enqueuer.remainingTestCases.isEmpty) { |
| 1950 _controller.close(); | 1953 _controller.close(); |
| 1954 _closed = true; |
| 1951 } | 1955 } |
| 1952 } | 1956 } |
| 1953 }); | 1957 }); |
| 1958 |
| 1959 // Listen also for GraphSealedEvent's. If there is not a single node in the |
| 1960 // graph, we still want to finish after the graph was sealed. |
| 1961 eventCondition((event) => event is dgraph.GraphSealedEvent) |
| 1962 .listen((dgraph.GraphSealedEvent event) { |
| 1963 if (!_closed && enqueuer.remainingTestCases.isEmpty) { |
| 1964 _controller.close(); |
| 1965 _closed = true; |
| 1966 } |
| 1967 }); |
| 1954 } | 1968 } |
| 1955 | 1969 |
| 1956 Stream<TestCase> get finishedTestCases => _controller.stream; | 1970 Stream<TestCase> get finishedTestCases => _controller.stream; |
| 1957 | 1971 |
| 1958 void _completeTestCasesIfPossible(Command command) { | 1972 void _completeTestCasesIfPossible(Command command) { |
| 1959 assert(_outputs[command] != null); | 1973 assert(_outputs[command] != null); |
| 1960 | 1974 |
| 1961 var testCases = enqueuer.command2testCases[command]; | 1975 var testCases = enqueuer.command2testCases[command]; |
| 1962 | 1976 |
| 1963 // Update TestCases with command outputs | 1977 // Update TestCases with command outputs |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2084 } | 2098 } |
| 2085 } | 2099 } |
| 2086 | 2100 |
| 2087 void eventAllTestsDone() { | 2101 void eventAllTestsDone() { |
| 2088 for (var listener in _eventListener) { | 2102 for (var listener in _eventListener) { |
| 2089 listener.allDone(); | 2103 listener.allDone(); |
| 2090 } | 2104 } |
| 2091 _allDone(); | 2105 _allDone(); |
| 2092 } | 2106 } |
| 2093 } | 2107 } |
| OLD | NEW |