Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: lib/src/runner/live_suite_controller.dart

Issue 1887853002: Add a LiveSuite class. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/runner/live_suite.dart ('k') | lib/src/util/iterable_set.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'dart:async';
6
7 import 'package:async/async.dart' hide Result;
8 import 'package:collection/collection.dart';
9
10 import '../backend/state.dart';
11 import '../backend/live_test.dart';
12 import 'live_suite.dart';
13 import 'runner_suite.dart';
14
15 /// An implementation of [LiveSuite] that's controlled by a [LiveSuiteController ].
kevmoo 2016/04/14 01:11:24 long line?
nweiz 2016/04/14 19:21:53 Done.
16 class _LiveSuite extends LiveSuite {
17 final LiveSuiteController _controller;
18
19 RunnerSuite get suite => _controller._suite;
20
21 bool get isComplete => _controller._isComplete;
22
23 Future get onComplete => _controller._onCompleteGroup.future;
24
25 bool get isClosed => _controller._onCloseCompleter.isCompleted;
26
27 Future get onClose => _controller._onCloseCompleter.future;
28
29 Stream<LiveTest> get onTestStarted =>
30 _controller._onTestStartedController.stream;
31
32 Set<LiveTest> get passed => new UnmodifiableSetView(_controller._passed);
33
34 Set<LiveTest> get skipped => new UnmodifiableSetView(_controller._skipped);
35
36 Set<LiveTest> get failed => new UnmodifiableSetView(_controller._failed);
37
38 LiveTest get active => _controller._active;
39
40 _LiveSuite(this._controller);
41 }
42
43 /// A controller that drives a [LiveSuite].
44 ///
45 /// This is a utility class to make it easier for [Engine] to create the
46 /// [LiveSuite]s exposed by various APIs. The [LiveSuite] is accessible through
47 /// [LiveSuiteController.liveSuite]. When a live test is run, it should be
48 /// passed to [reportLiveTest], and once tests are finished being run for this
49 /// suite, [noMoreLiveTests] should be called. Once the suite should be torn
50 /// down, [close] should be called.
51 class LiveSuiteController {
52 /// The [LiveSuite] controlled by [this].
53 LiveSuite get liveSuite => _liveSuite;
54 LiveSuite _liveSuite;
55
56 /// The suite that's being run.
57 final RunnerSuite _suite;
58
59 /// The future group that backs [LiveSuite.onComplete].
60 ///
61 /// This contains all the futures from tests that are run in this suite.
62 final _onCompleteGroup = new FutureGroup();
63
64 /// Whether [_onCompleteGroup]'s future has fired.
65 var _isComplete = false;
66
67 /// The completer that backs [LiveSuite.onClose].
68 ///
69 /// This is completed when the live suite is closed.
70 final _onCloseCompleter = new Completer();
71
72 /// The controller for [LiveSuite.onTestStarted].
73 final _onTestStartedController =
74 new StreamController<LiveTest>.broadcast(sync: true);
75
76 /// The set that backs [LiveTest.passed].
77 final _passed = new Set<LiveTest>();
78
79 /// The set that backs [LiveTest.skipped].
80 final _skipped = new Set<LiveTest>();
81
82 /// The set that backs [LiveTest.failed].
83 final _failed = new Set<LiveTest>();
84
85 /// The test exposed through [LiveTest.active].
86 LiveTest _active;
87
88 /// Creates a controller for a live suite representing running the tests in
89 /// [suite].
90 ///
91 /// Once this is called, the controller assumes responsibility for closing the
92 /// suite. The caller should call [LiveSuiteController.close] rather than
93 /// calling [RunnerSuite.close] directly.
94 LiveSuiteController(this._suite) {
95 _liveSuite = new _LiveSuite(this);
96
97 _onCompleteGroup.future.then((_) {
98 _isComplete = true;
99 }, onError: (_) {});
100 }
101
102 /// Reports the status of [liveTest] through [liveSuite].
103 ///
104 /// The live test is assumed to be a member of this suite. If [countSuccess]
105 /// is `true` (the default), the test is put into [passed] if it succeeds.
106 /// Otherwise, it's removed from [liveTests] entirely.
107 ///
108 /// Throws a [StateError] if called after [noMoreLiveTests].
109 void reportLiveTest(LiveTest liveTest, {bool countSuccess: true}) {
110 if (_onTestStartedController.isClosed) {
111 throw new StateError("Can't call reportLiveTest() after noMoreTests().");
112 }
113
114 assert(liveTest.suite == _suite);
115 assert(_active == null);
116
117 _active = liveTest;
118
119 liveTest.onStateChange.listen((state) {
120 if (state.status != Status.complete) return;
121 _active = null;
122
123 if (state.result != Result.success) {
124 _passed.remove(liveTest);
125 _failed.add(liveTest);
126 } else if (liveTest.test.metadata.skip) {
127 _skipped.add(liveTest);
128 } else if (countSuccess) {
129 _passed.add(liveTest);
130 }
131 });
132
133 _onTestStartedController.add(liveTest);
134
135 _onCompleteGroup.add(liveTest.onComplete);
136 }
137
138 /// Indicates that all the live tests that are going to be provided for this
139 /// suite have already been provided.
140 void noMoreLiveTests() {
141 _onTestStartedController.close();
142 _onCompleteGroup.close();
143 }
144
145 /// Closes the underlying suite.
146 Future close() => _closeMemo.runOnce(() async {
147 try {
148 await _suite.close();
149 } finally {
150 _onCloseCompleter.complete();
151 }
152 });
153 final _closeMemo = new AsyncMemoizer();
154 }
OLDNEW
« no previous file with comments | « lib/src/runner/live_suite.dart ('k') | lib/src/util/iterable_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698